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();
// 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} */
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();
}
* 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);
}
}
==================================================================== */
package org.apache.poi.ss.format;
-import java.util.Locale;
import java.util.logging.Logger;
/**
/** The original specified format. */
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}.
*
import java.util.Formatter;
import java.util.Locale;
+import org.apache.poi.util.LocaleUtil;
+
/**
* A formatter for the default "General" cell format.
*
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();
}
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();
}
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();
}
\r
package org.apache.poi.util;\r
\r
+import java.nio.charset.Charset;\r
import java.util.Calendar;\r
import java.util.Locale;\r
import java.util.TimeZone;\r
* use UTC to perform calculations\r
*/\r
public static final TimeZone TIMEZONE_UTC = TimeZone.getTimeZone("UTC");\r
+ \r
+ /**\r
+ * Default encoding for unknown byte encodings of native files\r
+ * (at least it's better than to rely on a platform dependent encoding\r
+ * for legacy stuff ...)\r
+ */\r
+ public static final Charset CHARSET_1252 = Charset.forName("CP1252");\r
\r
private static final ThreadLocal<TimeZone> userTimeZone = new ThreadLocal<TimeZone>() {\r
@Override\r
import java.math.BigInteger;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.LocaleUtil;
import org.apache.xmlbeans.impl.xb.xmlschema.SpaceAttribute.Space;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
rPr.addNewSzCs().setVal(new BigInteger("24"));\r
CTSdtContentBlock content = block.addNewSdtContent();\r
CTP p = content.addNewP();\r
- p.setRsidR("00EF7E24".getBytes());\r
- p.setRsidRDefault("00EF7E24".getBytes());\r
+ p.setRsidR("00EF7E24".getBytes(LocaleUtil.CHARSET_1252));\r
+ p.setRsidRDefault("00EF7E24".getBytes(LocaleUtil.CHARSET_1252));\r
p.addNewPPr().addNewPStyle().setVal("TOCHeading");\r
p.addNewR().addNewT().setStringValue("Table of Contents");\r
}\r
public void addRow(int level, String title, int page, String bookmarkRef) {\r
CTSdtContentBlock contentBlock = this.block.getSdtContent();\r
CTP p = contentBlock.addNewP();\r
- p.setRsidR("00EF7E24".getBytes());\r
- p.setRsidRDefault("00EF7E24".getBytes());\r
+ p.setRsidR("00EF7E24".getBytes(LocaleUtil.CHARSET_1252));\r
+ p.setRsidRDefault("00EF7E24".getBytes(LocaleUtil.CHARSET_1252));\r
CTPPr pPr = p.addNewPPr();\r
pPr.addNewPStyle().setVal("TOC" + level);\r
CTTabs tabs = pPr.addNewTabs();\r
package org.apache.poi.hpbf.dev;
-import java.io.FileInputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.StringUtil;
/**
public HPBFDumper(NPOIFSFileSystem fs) {
this.fs = fs;
}
- public HPBFDumper(InputStream inp) throws IOException {
+
+ @SuppressWarnings("resource")
+ public HPBFDumper(InputStream inp) throws IOException {
this(new NPOIFSFileSystem(inp));
}
return ret.toString();
}
- public static void main(String[] args) throws Exception {
+ @SuppressWarnings("resource")
+ public static void main(String[] args) throws Exception {
if(args.length < 1) {
System.err.println("Use:");
System.err.println(" HPBFDumper <filename>");
System.exit(1);
}
- HPBFDumper dump = new HPBFDumper(
- new FileInputStream(args[0])
- );
+ HPBFDumper dump = new HPBFDumper(new NPOIFSFileSystem(new File(args[0])));
System.out.println("Dumping " + args[0]);
dump.dumpContents();
// then 4 bytes giving the length, then
// 18 00
System.out.println(
- new String(data, 0, 8) +
+ new String(data, 0, 8, LocaleUtil.CHARSET_1252) +
dumpBytes(data, 8, 0x20-8)
);
);
pos += 2;
}
- String text = new String(data, pos, 4);
+ String text = new String(data, pos, 4, LocaleUtil.CHARSET_1252);
int blen = 8;
if(sixNotEight)
blen = 6;
int offset = 0x20 + i*24;
if(data[offset] == 0x18 && data[offset+1] == 0x00) {
// Has data
- startType[i] = new String(data, offset+2, 4);
+ startType[i] = new String(data, offset+2, 4, LocaleUtil.CHARSET_1252);
optA[i] = LittleEndian.getUShort(data, offset+6);
optB[i] = LittleEndian.getUShort(data, offset+8);
optC[i] = LittleEndian.getUShort(data, offset+10);
- endType[i] = new String(data, offset+12, 4);
+ endType[i] = new String(data, offset+12, 4, LocaleUtil.CHARSET_1252);
from[i] = (int)LittleEndian.getUInt(data, offset+16);
len[i] = (int)LittleEndian.getUInt(data, offset+20);
} else {
package org.apache.poi.hssf.converter;
import java.io.File;
-import java.io.FileWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
{
Document doc = ExcelToHtmlConverter.process( new File( args[0] ) );
- FileWriter out = new FileWriter( args[1] );
DOMSource domSource = new DOMSource( doc );
- StreamResult streamResult = new StreamResult( out );
+ StreamResult streamResult = new StreamResult( new File(args[1]) );
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty( OutputKeys.INDENT, "no" );
serializer.setOutputProperty( OutputKeys.METHOD, "html" );
serializer.transform( domSource, streamResult );
- out.close();
}
catch ( Exception e )
{
XMLHelper.getDocumentBuilderFactory().newDocumentBuilder()
.newDocument() );
excelToHtmlConverter.processWorkbook( workbook );
- return excelToHtmlConverter.getDocument();
+ Document doc = excelToHtmlConverter.getDocument();
+ workbook.close();
+ return doc;
}
private String cssClassContainerCell = null;
final short cellStyleIndex = cellStyle.getIndex();
if ( cellStyleIndex != 0 )
{
+ @SuppressWarnings("resource")
HSSFWorkbook workbook = cell.getRow().getSheet().getWorkbook();
String mainCssClass = getStyleClassName( workbook, cellStyle );
+
if ( wrapInDivs )
{
tableCellElement.setAttribute( "class", mainCssClass + " "