diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2015-09-07 22:34:21 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2015-09-07 22:34:21 +0000 |
commit | e84b4d041c63936ab584bc3ca075e24035591f88 (patch) | |
tree | 28497ad2b15fd3a5f2d9fc89ec0ef88f18a952a6 /src/java/org/apache/poi | |
parent | a3d2eb57ff4ac10ae215b9b7404260103eb6f538 (diff) | |
download | poi-e84b4d041c63936ab584bc3ca075e24035591f88.tar.gz poi-e84b4d041c63936ab584bc3ca075e24035591f88.zip |
forbidden apis fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701710 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
5 files changed, 27 insertions, 20 deletions
diff --git a/src/java/org/apache/poi/ss/format/CellDateFormatter.java b/src/java/org/apache/poi/ss/format/CellDateFormatter.java index dcf702c329..4027d02765 100644 --- a/src/java/org/apache/poi/ss/format/CellDateFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellDateFormatter.java @@ -38,13 +38,12 @@ public class CellDateFormatter extends CellFormatter { private final DateFormat dateFmt; private String sFmt; - private static final long EXCEL_EPOCH_TIME; - private static final Date EXCEL_EPOCH_DATE; + private final long EXCEL_EPOCH_TIME; + private final Date EXCEL_EPOCH_DATE; - private static final CellFormatter SIMPLE_DATE = new CellDateFormatter( - "mm/d/y"); + private static /* final */ CellDateFormatter SIMPLE_DATE = null; - static { + { Calendar c = LocaleUtil.getLocaleCalendar(1904, 0, 1, 0, 0, 0); EXCEL_EPOCH_DATE = c.getTime(); EXCEL_EPOCH_TIME = c.getTimeInMillis(); @@ -153,7 +152,7 @@ public class CellDateFormatter extends CellFormatter { // tweak the format pattern to pass tests on JDK 1.7, // See https://issues.apache.org/bugzilla/show_bug.cgi?id=53369 String ptrn = descBuf.toString().replaceAll("((y)(?!y))(?<!yy)", "yy"); - dateFmt = new SimpleDateFormat(ptrn, LOCALE); + dateFmt = new SimpleDateFormat(ptrn, LocaleUtil.getUserLocale()); } /** {@inheritDoc} */ @@ -185,7 +184,7 @@ public class CellDateFormatter extends CellFormatter { Formatter formatter = new Formatter(toAppendTo, Locale.ROOT); try { long msecs = dateObj.getTime() % 1000; - formatter.format(LOCALE, sFmt, msecs / 1000.0); + formatter.format(LocaleUtil.getUserLocale(), sFmt, msecs / 1000.0); } finally { formatter.close(); } @@ -219,6 +218,11 @@ public class CellDateFormatter extends CellFormatter { * For a date, this is <tt>"mm/d/y"</tt>. */ public void simpleValue(StringBuffer toAppendTo, Object value) { + synchronized (CellDateFormatter.class) { + if (SIMPLE_DATE == null || !SIMPLE_DATE.EXCEL_EPOCH_DATE.equals(EXCEL_EPOCH_DATE)) { + SIMPLE_DATE = new CellDateFormatter("mm/d/y"); + } + } SIMPLE_DATE.formatValue(toAppendTo, value); } } diff --git a/src/java/org/apache/poi/ss/format/CellFormatter.java b/src/java/org/apache/poi/ss/format/CellFormatter.java index 23cfbe541c..e529a90f16 100644 --- a/src/java/org/apache/poi/ss/format/CellFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellFormatter.java @@ -16,7 +16,6 @@ ==================================================================== */ package org.apache.poi.ss.format; -import java.util.Locale; import java.util.logging.Logger; /** @@ -29,12 +28,6 @@ public abstract class CellFormatter { protected final String format; /** - * This is the locale used to get a consistent format result from which to - * work. - */ - public static final Locale LOCALE = Locale.US; - - /** * Creates a new formatter object, storing the format in {@link #format}. * * @param format The format. diff --git a/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java b/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java index cdee8cf01b..b890e02176 100644 --- a/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java @@ -19,6 +19,8 @@ package org.apache.poi.ss.format; import java.util.Formatter; import java.util.Locale; +import org.apache.poi.util.LocaleUtil; + /** * A formatter for the default "General" cell format. * @@ -57,9 +59,9 @@ public class CellGeneralFormatter extends CellFormatter { stripZeros = false; } - Formatter formatter = new Formatter(toAppendTo, LOCALE); + Formatter formatter = new Formatter(toAppendTo, LocaleUtil.getUserLocale()); try { - formatter.format(LOCALE, fmt, value); + formatter.format(LocaleUtil.getUserLocale(), fmt, value); } finally { formatter.close(); } diff --git a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java index 3addf46fe5..f38f78006f 100644 --- a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java @@ -597,9 +597,9 @@ public class CellNumberFormatter extends CellFormatter { writeFraction(value, null, fractional, output, mods); } else { StringBuffer result = new StringBuffer(); - Formatter f = new Formatter(result, LOCALE); + Formatter f = new Formatter(result, LocaleUtil.getUserLocale()); try { - f.format(LOCALE, printfFmt, value); + f.format(LocaleUtil.getUserLocale(), printfFmt, value); } finally { f.close(); } @@ -873,9 +873,9 @@ public class CellNumberFormatter extends CellFormatter { List<Special> numSpecials, Set<StringMod> mods) { StringBuffer sb = new StringBuffer(); - Formatter formatter = new Formatter(sb, LOCALE); + Formatter formatter = new Formatter(sb, LocaleUtil.getUserLocale()); try { - formatter.format(LOCALE, fmt, num); + formatter.format(LocaleUtil.getUserLocale(), fmt, num); } finally { formatter.close(); } diff --git a/src/java/org/apache/poi/util/LocaleUtil.java b/src/java/org/apache/poi/util/LocaleUtil.java index 4edd65d18d..d402be58c3 100644 --- a/src/java/org/apache/poi/util/LocaleUtil.java +++ b/src/java/org/apache/poi/util/LocaleUtil.java @@ -18,6 +18,7 @@ package org.apache.poi.util;
+import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
@@ -39,6 +40,13 @@ public class LocaleUtil { * use UTC to perform calculations
*/
public static final TimeZone TIMEZONE_UTC = TimeZone.getTimeZone("UTC");
+
+ /**
+ * Default encoding for unknown byte encodings of native files
+ * (at least it's better than to rely on a platform dependent encoding
+ * for legacy stuff ...)
+ */
+ public static final Charset CHARSET_1252 = Charset.forName("CP1252");
private static final ThreadLocal<TimeZone> userTimeZone = new ThreadLocal<TimeZone>() {
@Override
|