From 133c0d7c0bd756f5a2fe0f40ef7b4f4c2790cd69 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 16 Nov 2012 12:21:49 +0000 Subject: [PATCH] Bug 52628 - Replace System.err info messages with a POILogger git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1410318 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + src/java/org/apache/poi/POIDocument.java | 2 +- .../apache/poi/hpsf/HPSFRuntimeException.java | 72 +++++++++---------- .../org/apache/poi/hpsf/VariantSupport.java | 11 +-- .../FormatTrackingHSSFListener.java | 7 +- .../record/EmbeddedObjectRefSubRecord.java | 5 +- .../apache/poi/hssf/record/FeatRecord.java | 5 +- .../poi/hssf/record/HyperlinkRecord.java | 4 +- .../poi/hssf/record/SSTDeserializer.java | 6 +- .../poi/hssf/record/common/UnicodeString.java | 2 +- .../usermodel/HSSFEvaluationWorkbook.java | 6 +- .../poi/hssf/usermodel/HSSFPicture.java | 6 +- .../poi/hssf/usermodel/HSSFPolygon.java | 8 ++- .../poi/poifs/filesystem/EntryUtils.java | 2 +- .../ss/formula/constant/ErrorConstant.java | 5 +- .../poi/ss/util/DateFormatConverter.java | 6 +- .../apache/poi/hdgf/chunks/ChunkFactory.java | 6 +- .../apache/poi/hdgf/streams/ChunkStream.java | 8 ++- .../poi/hmef/attribute/MAPIDateAttribute.java | 5 +- .../hmef/attribute/MAPIStringAttribute.java | 5 +- .../poi/hmef/attribute/TNEFDateAttribute.java | 5 +- .../hmef/attribute/TNEFStringAttribute.java | 5 +- .../src/org/apache/poi/hslf/model/Sheet.java | 6 +- .../poi/hslf/record/CurrentUserAtom.java | 8 ++- .../org/apache/poi/hslf/record/Record.java | 4 +- .../poi/hsmf/datatypes/AttachmentChunks.java | 5 +- .../datatypes/MessageSubmissionChunk.java | 5 +- .../poi/hsmf/datatypes/RecipientChunks.java | 7 +- .../poi/hsmf/parsers/POIFSChunkParser.java | 6 +- .../poi/hwpf/converter/AbstractWordUtils.java | 2 +- 30 files changed, 146 insertions(+), 79 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 1e13ea806..f4ae431ee 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52628 - Replace System.err info messages with a POILogger 54137 - improved performance of DataFormatter with Fractions 54099 - Ensure that CTHMerge and CTTcBorders go to poi-ooxml-schemas jar 54111 - Fixed extracting text from table cells in HSLF diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java index 169e9241b..8f177fec9 100644 --- a/src/java/org/apache/poi/POIDocument.java +++ b/src/java/org/apache/poi/POIDocument.java @@ -221,7 +221,7 @@ public abstract class POIDocument { logger.log(POILogger.INFO, "Wrote property set " + name + " of size " + data.length); } catch(org.apache.poi.hpsf.WritingNotSupportedException wnse) { - System.err.println("Couldn't write property set with name " + name + " as not supported by HPSF yet"); + logger.log( POILogger.ERROR, "Couldn't write property set with name " + name + " as not supported by HPSF yet"); } } diff --git a/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java b/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java index 79825ebf8..203498f13 100644 --- a/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java +++ b/src/java/org/apache/poi/hpsf/HPSFRuntimeException.java @@ -17,8 +17,6 @@ package org.apache.poi.hpsf; -import java.io.PrintStream; -import java.io.PrintWriter; /** *

This exception is the superclass of all other unchecked @@ -30,8 +28,8 @@ import java.io.PrintWriter; */ public class HPSFRuntimeException extends RuntimeException { - - /**

The underlying reason for this exception - may be + private static final long serialVersionUID = -7804271670232727159L; + /**

The underlying reason for this exception - may be * null.

*/ private Throwable reason; @@ -105,44 +103,44 @@ public class HPSFRuntimeException extends RuntimeException - /** - * @see Throwable#printStackTrace() - */ - public void printStackTrace() - { - printStackTrace(System.err); - } +// /** +// * @see Throwable#printStackTrace() +// */ +// public void printStackTrace() +// { +// printStackTrace(System.err); +// } - /** - * @see Throwable#printStackTrace(java.io.PrintStream) - */ - public void printStackTrace(final PrintStream p) - { - final Throwable reason = getReason(); - super.printStackTrace(p); - if (reason != null) - { - p.println("Caused by:"); - reason.printStackTrace(p); - } - } +// /** +// * @see Throwable#printStackTrace(java.io.PrintStream) +// */ +// public void printStackTrace(final PrintStream p) +// { +// final Throwable reason = getReason(); +// super.printStackTrace(p); +// if (reason != null) +// { +// p.println("Caused by:"); +// reason.printStackTrace(p); +// } +// } - /** - * @see Throwable#printStackTrace(java.io.PrintWriter) - */ - public void printStackTrace(final PrintWriter p) - { - final Throwable reason = getReason(); - super.printStackTrace(p); - if (reason != null) - { - p.println("Caused by:"); - reason.printStackTrace(p); - } - } +// /** +// * @see Throwable#printStackTrace(java.io.PrintWriter) +// */ +// public void printStackTrace(final PrintWriter p) +// { +// final Throwable reason = getReason(); +// super.printStackTrace(p); +// if (reason != null) +// { +// p.println("Caused by:"); +// reason.printStackTrace(p); +// } +// } } diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index 8b13fc0e3..f24c2a918 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -24,6 +24,9 @@ import java.util.Date; import java.util.LinkedList; import java.util.List; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; + /** *

Supports reading and writing of variant data.

* @@ -45,7 +48,7 @@ import java.util.List; */ public class VariantSupport extends Variant { - + private static POILogger logger = POILogFactory.getLogger(VariantSupport.class); private static boolean logUnsupportedTypes = false; /** @@ -78,7 +81,7 @@ public class VariantSupport extends Variant *

Keeps a list of the variant types an "unsupported" message has already * been issued for.

*/ - protected static List unsupportedMessage; + protected static List unsupportedMessage; /** *

Writes a warning to System.err that a variant type is @@ -93,11 +96,11 @@ public class VariantSupport extends Variant if (isLogUnsupportedTypes()) { if (unsupportedMessage == null) - unsupportedMessage = new LinkedList(); + unsupportedMessage = new LinkedList(); Long vt = Long.valueOf(ex.getVariantType()); if (!unsupportedMessage.contains(vt)) { - System.err.println(ex.getMessage()); + logger.log( POILogger.ERROR, ex.getMessage()); unsupportedMessage.add(vt); } } diff --git a/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java b/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java index 60c11d352..1ca3db366 100644 --- a/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java +++ b/src/java/org/apache/poi/hssf/eventusermodel/FormatTrackingHSSFListener.java @@ -31,6 +31,8 @@ import org.apache.poi.hssf.record.NumberRecord; import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFDataFormatter; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * A proxy HSSFListener that keeps track of the document formatting records, and @@ -38,6 +40,7 @@ import org.apache.poi.hssf.usermodel.HSSFDataFormatter; * ids. */ public class FormatTrackingHSSFListener implements HSSFListener { + private static POILogger logger = POILogFactory.getLogger(FormatTrackingHSSFListener.class); private final HSSFListener _childListener; private final HSSFDataFormatter _formatter; private final NumberFormat _defaultFormat; @@ -137,7 +140,7 @@ public class FormatTrackingHSSFListener implements HSSFListener { if (formatIndex >= HSSFDataFormat.getNumberOfBuiltinBuiltinFormats()) { FormatRecord tfr = _customFormatRecords.get(Integer.valueOf(formatIndex)); if (tfr == null) { - System.err.println("Requested format at index " + formatIndex + logger.log( POILogger.ERROR, "Requested format at index " + formatIndex + ", but it wasn't found"); } else { format = tfr.getFormatString(); @@ -167,7 +170,7 @@ public class FormatTrackingHSSFListener implements HSSFListener { public int getFormatIndex(CellValueRecordInterface cell) { ExtendedFormatRecord xfr = _xfRecords.get(cell.getXFIndex()); if (xfr == null) { - System.err.println("Cell " + cell.getRow() + "," + cell.getColumn() + logger.log( POILogger.ERROR, "Cell " + cell.getRow() + "," + cell.getColumn() + " uses XF with index " + cell.getXFIndex() + ", but we don't have that"); return -1; } diff --git a/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java index 6e74173d4..77e9fd86d 100644 --- a/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java +++ b/src/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java @@ -29,6 +29,8 @@ import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -39,6 +41,7 @@ import org.apache.poi.util.StringUtil; * @author Daniel Noll */ public final class EmbeddedObjectRefSubRecord extends SubRecord { + private static POILogger logger = POILogFactory.getLogger(EmbeddedObjectRefSubRecord.class); public static final short sid = 0x0009; private static final byte[] EMPTY_BYTE_ARRAY = { }; @@ -137,7 +140,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { int nUnexpectedPadding = remaining - dataLenAfterFormula; if (nUnexpectedPadding > 0) { - System.err.println("Discarding " + nUnexpectedPadding + " unexpected padding bytes "); + logger.log( POILogger.ERROR, "Discarding " + nUnexpectedPadding + " unexpected padding bytes "); readRawData(in, nUnexpectedPadding); remaining-=nUnexpectedPadding; } diff --git a/src/java/org/apache/poi/hssf/record/FeatRecord.java b/src/java/org/apache/poi/hssf/record/FeatRecord.java index 267eced88..572d6959d 100644 --- a/src/java/org/apache/poi/hssf/record/FeatRecord.java +++ b/src/java/org/apache/poi/hssf/record/FeatRecord.java @@ -24,6 +24,8 @@ import org.apache.poi.hssf.record.common.FtrHeader; import org.apache.poi.hssf.record.common.SharedFeature; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * Title: Feat (Feature) Record @@ -32,6 +34,7 @@ import org.apache.poi.util.LittleEndianOutput; * up with a {@link FeatHdrRecord}. */ public final class FeatRecord extends StandardRecord { + private static POILogger logger = POILogFactory.getLogger(FeatRecord.class); public final static short sid = 0x0868; private FtrHeader futureHeader; @@ -90,7 +93,7 @@ public final class FeatRecord extends StandardRecord { sharedFeature = new FeatSmartTag(in); break; default: - System.err.println("Unknown Shared Feature " + isf_sharedFeatureType + " found!"); + logger.log( POILogger.ERROR, "Unknown Shared Feature " + isf_sharedFeatureType + " found!"); } } diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java index 3d6b237cf..f13d7f0eb 100644 --- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java +++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java @@ -41,7 +41,7 @@ import org.apache.poi.util.StringUtil; */ public final class HyperlinkRecord extends StandardRecord { public final static short sid = 0x01B8; - private POILogger logger = POILogFactory.getLogger(getClass()); + private static POILogger logger = POILogFactory.getLogger(HyperlinkRecord.class); static final class GUID { /* @@ -641,7 +641,7 @@ public final class HyperlinkRecord extends StandardRecord { if (false) { // Quite a few examples in the unit tests which don't have the exact expected tail for (int i = 0; i < expectedTail.length; i++) { if (expectedTail[i] != result[i]) { - System.err.println("Mismatch in tail byte [" + i + "]" + logger.log( POILogger.ERROR, "Mismatch in tail byte [" + i + "]" + "expected " + (expectedTail[i] & 0xFF) + " but got " + (result[i] & 0xFF)); } } diff --git a/src/java/org/apache/poi/hssf/record/SSTDeserializer.java b/src/java/org/apache/poi/hssf/record/SSTDeserializer.java index 280bc26c9..181616185 100644 --- a/src/java/org/apache/poi/hssf/record/SSTDeserializer.java +++ b/src/java/org/apache/poi/hssf/record/SSTDeserializer.java @@ -21,6 +21,8 @@ package org.apache.poi.hssf.record; import org.apache.poi.hssf.record.common.UnicodeString; import org.apache.poi.util.IntMapper; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * Handles the task of deserializing a SST string. The two main entry points are @@ -30,7 +32,7 @@ import org.apache.poi.util.IntMapper; */ class SSTDeserializer { - + private static POILogger logger = POILogFactory.getLogger(SSTDeserializer.class); private IntMapper strings; public SSTDeserializer( IntMapper strings ) @@ -49,7 +51,7 @@ class SSTDeserializer // Extract exactly the count of strings from the SST record. UnicodeString str; if(in.available() == 0 && ! in.hasNextRecord()) { - System.err.println("Ran out of data before creating all the strings! String at index " + i + ""); + logger.log( POILogger.ERROR, "Ran out of data before creating all the strings! String at index " + i + ""); str = new UnicodeString(""); } else { str = new UnicodeString(in); diff --git a/src/java/org/apache/poi/hssf/record/common/UnicodeString.java b/src/java/org/apache/poi/hssf/record/common/UnicodeString.java index 3ee5e4e66..9e9ca0392 100644 --- a/src/java/org/apache/poi/hssf/record/common/UnicodeString.java +++ b/src/java/org/apache/poi/hssf/record/common/UnicodeString.java @@ -179,7 +179,7 @@ public class UnicodeString implements Comparable { // TODO - make int extraDataLength = runData - (numRuns*6); if(extraDataLength < 0) { - System.err.println("Warning - ExtRst overran by " + (0-extraDataLength) + " bytes"); + _logger.log( POILogger.WARN, "Warning - ExtRst overran by " + (0-extraDataLength) + " bytes"); extraDataLength = 0; } extraData = new byte[extraDataLength]; diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java index 0d130452b..7e350e88f 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java @@ -34,6 +34,8 @@ import org.apache.poi.ss.formula.FormulaParsingWorkbook; import org.apache.poi.ss.formula.FormulaRenderingWorkbook; import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.formula.udf.UDFFinder; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * Internal POI use only @@ -41,7 +43,7 @@ import org.apache.poi.ss.formula.udf.UDFFinder; * @author Josh Micich */ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, EvaluationWorkbook, FormulaParsingWorkbook { - + private static POILogger logger = POILogFactory.getLogger(HSSFEvaluationWorkbook.class); private final HSSFWorkbook _uBook; private final InternalWorkbook _iBook; @@ -139,7 +141,7 @@ public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E // Note - as of Bugzilla 48036 (svn r828244, r828247) POI is capable of evaluating // IntesectionPtg. However it is still not capable of parsing it. // So FormulaEvalTestData.xls now contains a few formulas that produce errors here. - System.err.println(e.getMessage()); + logger.log( POILogger.ERROR, e.getMessage()); } } FormulaRecordAggregate fra = (FormulaRecordAggregate) cell.getCellValueRecord(); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java index 1f20d9f0f..56b2f699e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java @@ -27,6 +27,8 @@ import org.apache.poi.hssf.record.EscherAggregate; import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.ss.usermodel.Picture; import org.apache.poi.ss.util.ImageUtils; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.hssf.model.InternalWorkbook; /** @@ -36,6 +38,8 @@ import org.apache.poi.hssf.model.InternalWorkbook; * @author Yegor Kozlov (yegor at apache.org) */ public class HSSFPicture extends HSSFSimpleShape implements Picture { + private static POILogger logger = POILogFactory.getLogger(HSSFPicture.class); + public static final int PICTURE_TYPE_EMF = HSSFWorkbook.PICTURE_TYPE_EMF; // Windows Enhanced Metafile public static final int PICTURE_TYPE_WMF = HSSFWorkbook.PICTURE_TYPE_WMF; // Windows Metafile public static final int PICTURE_TYPE_PICT = HSSFWorkbook.PICTURE_TYPE_PICT; // Macintosh PICT @@ -283,7 +287,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, true, data.getBytes("UTF-16LE")); setPropertyValue(prop); } catch (UnsupportedEncodingException e) { - System.out.println("Unsupported encoding: UTF-16LE"); + logger.log( POILogger.ERROR, "Unsupported encoding: UTF-16LE"); } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java index 98936f90c..07209ae3e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPolygon.java @@ -20,12 +20,14 @@ package org.apache.poi.hssf.usermodel; import org.apache.poi.ddf.*; import org.apache.poi.hssf.record.*; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * @author Glen Stampoultzis (glens at superlinksoftware.com) */ public class HSSFPolygon extends HSSFSimpleShape { - + private static POILogger logger = POILogFactory.getLogger(HSSFPolygon.class); public final static short OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 0x1E; public HSSFPolygon(EscherContainerRecord spContainer, ObjRecord objRecord, TextObjectRecord _textObjectRecord) { @@ -157,11 +159,11 @@ public class HSSFPolygon extends HSSFSimpleShape { */ public void setPoints(int[] xPoints, int[] yPoints) { if (xPoints.length != yPoints.length){ - System.out.println("xPoint.length must be equal to yPoints.length"); + logger.log( POILogger.ERROR, "xPoint.length must be equal to yPoints.length"); return; } if (xPoints.length == 0){ - System.out.println("HSSFPolygon must have at least one point"); + logger.log( POILogger.ERROR, "HSSFPolygon must have at least one point"); } EscherArrayProperty verticesProp = new EscherArrayProperty(EscherProperties.GEOMETRY__VERTICES, false, new byte[0] ); verticesProp.setNumberOfElementsInArray(xPoints.length+1); diff --git a/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java b/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java index 3233dfa26..60f2b8d38 100644 --- a/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java +++ b/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java @@ -36,7 +36,7 @@ public class EntryUtils public static void copyNodeRecursively( Entry entry, DirectoryEntry target ) throws IOException { - // System.err.println("copyNodeRecursively called with "+entry.getName()+ + // logger.log( POILogger.ERROR, "copyNodeRecursively called with "+entry.getName()+ // ","+target.getName()); DirectoryEntry newTarget = null; if ( entry.isDirectoryEntry() ) diff --git a/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java b/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java index 5a58db927..b3c7ee720 100644 --- a/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java +++ b/src/java/org/apache/poi/ss/formula/constant/ErrorConstant.java @@ -18,6 +18,8 @@ package org.apache.poi.ss.formula.constant; import org.apache.poi.ss.usermodel.ErrorConstants; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * Represents a constant error code value as encoded in a constant values array.

* @@ -27,6 +29,7 @@ import org.apache.poi.ss.usermodel.ErrorConstants; * @author Josh Micich */ public class ErrorConstant { + private static POILogger logger = POILogFactory.getLogger(ErrorConstant.class); // convenient access to name space private static final ErrorConstants EC = null; @@ -64,7 +67,7 @@ public class ErrorConstant { case ErrorConstants.ERROR_NUM: return NUM; case ErrorConstants.ERROR_NA: return NA; } - System.err.println("Warning - unexpected error code (" + errorCode + ")"); + logger.log( POILogger.WARN, "Warning - unexpected error code (" + errorCode + ")"); return new ErrorConstant(errorCode); } public String toString() { diff --git a/src/java/org/apache/poi/ss/util/DateFormatConverter.java b/src/java/org/apache/poi/ss/util/DateFormatConverter.java index b11f7a58d..316d1ed7b 100644 --- a/src/java/org/apache/poi/ss/util/DateFormatConverter.java +++ b/src/java/org/apache/poi/ss/util/DateFormatConverter.java @@ -24,6 +24,9 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; + /** * Convert java DateFormat patterns into Excel custom number formats. * For example, to format a date in excel using the "dd MMMM, yyyy" pattern and Japanese @@ -45,6 +48,7 @@ import java.util.Map; * */ public class DateFormatConverter { + private static POILogger logger = POILogFactory.getLogger(DateFormatConverter.class); public static class DateFormatTokenizer { String format; @@ -329,7 +333,7 @@ public class DateFormatConverter { result = localePrefixes.get( localeString.substring( 0, 2 ) ); if( result == null ) { Locale parentLocale = new Locale(localeString.substring( 0, 2 )); - System.out.println( "Unable to find prefix for " + locale + "(" + locale.getDisplayName() + ") or " + logger.log( POILogger.ERROR, "Unable to find prefix for " + locale + "(" + locale.getDisplayName() + ") or " + localeString.substring( 0, 2 ) + "(" + parentLocale.getDisplayName() + ")" ); return ""; } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java index 55cb5a7f1..1a7c3c6da 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java @@ -51,7 +51,7 @@ public final class ChunkFactory { "/org/apache/poi/hdgf/chunks_parse_cmds.tbl"; /** For logging problems we spot with the file */ - private POILogger logger = POILogFactory.getLogger(ChunkFactory.class); + private static POILogger logger = POILogFactory.getLogger(ChunkFactory.class); public ChunkFactory(int version) throws IOException { this.version = version; @@ -153,7 +153,7 @@ public final class ChunkFactory { data, endOfDataPos); endOfDataPos += 8; } else { - System.err.println("Header claims a length to " + endOfDataPos + " there's then no space for the trailer in the data (" + data.length + ")"); + logger.log(POILogger.ERROR, "Header claims a length to " + endOfDataPos + " there's then no space for the trailer in the data (" + data.length + ")"); } } if(header.hasSeparator()) { @@ -161,7 +161,7 @@ public final class ChunkFactory { separator = new ChunkSeparator( data, endOfDataPos); } else { - System.err.println("Header claims a length to " + endOfDataPos + " there's then no space for the separator in the data (" + data.length + ")"); + logger.log(POILogger.ERROR, "Header claims a length to " + endOfDataPos + " there's then no space for the separator in the data (" + data.length + ")"); } } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java index 595633480..9f15e40b9 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java @@ -23,8 +23,12 @@ import org.apache.poi.hdgf.chunks.Chunk; import org.apache.poi.hdgf.chunks.ChunkFactory; import org.apache.poi.hdgf.chunks.ChunkHeader; import org.apache.poi.hdgf.pointers.Pointer; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; public final class ChunkStream extends Stream { + private static POILogger logger = POILogFactory.getLogger(ChunkStream.class); + private ChunkFactory chunkFactory; /** All the Chunks we contain */ private Chunk[] chunks; @@ -62,14 +66,14 @@ public final class ChunkStream extends Stream { pos += chunk.getOnDiskSize(); } else { - System.err.println("Needed " + headerSize + " bytes to create the next chunk header, but only found " + (contents.length-pos) + " bytes, ignoring rest of data"); + logger.log(POILogger.WARN, "Needed " + headerSize + " bytes to create the next chunk header, but only found " + (contents.length-pos) + " bytes, ignoring rest of data"); pos = contents.length; } } } catch (Exception e) { - System.err.println("Failed to create chunk at " + pos + ", ignoring rest of data." + e); + logger.log(POILogger.ERROR, "Failed to create chunk at " + pos + ", ignoring rest of data." + e); } chunks = chunksA.toArray(new Chunk[chunksA.size()]); diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIDateAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIDateAttribute.java index bf786366d..243359639 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIDateAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIDateAttribute.java @@ -24,12 +24,15 @@ import org.apache.poi.hmef.HMEFMessage; import org.apache.poi.hpsf.Util; import org.apache.poi.hsmf.datatypes.MAPIProperty; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * A pure-MAPI attribute holding a Date, which applies * to a {@link HMEFMessage} or one of its {@link Attachment}s. */ public final class MAPIDateAttribute extends MAPIAttribute { + private static POILogger logger = POILogFactory.getLogger(MAPIDateAttribute.class); private Date data; /** @@ -64,7 +67,7 @@ public final class MAPIDateAttribute extends MAPIAttribute { return ((MAPIDateAttribute)attr).getDate(); } - System.err.println("Warning, non date property found: " + attr.toString()); + logger.log(POILogger.WARN, "Warning, non date property found: " + attr.toString()); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIStringAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIStringAttribute.java index b48651c09..72992086b 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIStringAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIStringAttribute.java @@ -23,6 +23,8 @@ import org.apache.poi.hmef.Attachment; import org.apache.poi.hmef.HMEFMessage; import org.apache.poi.hsmf.datatypes.MAPIProperty; import org.apache.poi.hsmf.datatypes.Types; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -30,6 +32,7 @@ import org.apache.poi.util.StringUtil; * to a {@link HMEFMessage} or one of its {@link Attachment}s. */ public final class MAPIStringAttribute extends MAPIAttribute { + private static POILogger logger = POILogFactory.getLogger(MAPIStringAttribute.class); private static final String CODEPAGE = "CP1252"; private final String data; @@ -78,7 +81,7 @@ public final class MAPIStringAttribute extends MAPIAttribute { return ((MAPIRtfAttribute)attr).getDataString(); } - System.err.println("Warning, non string property found: " + attr.toString()); + logger.log(POILogger.WARN, "Warning, non string property found: " + attr.toString()); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFDateAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFDateAttribute.java index 70793899f..890845229 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFDateAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFDateAttribute.java @@ -27,12 +27,15 @@ import org.apache.poi.hmef.Attachment; import org.apache.poi.hmef.HMEFMessage; import org.apache.poi.hpsf.Util; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * A Date attribute which applies to a {@link HMEFMessage} * or one of its {@link Attachment}s. */ public final class TNEFDateAttribute extends TNEFAttribute { + private static POILogger logger = POILogFactory.getLogger(TNEFDateAttribute.class); private Date data; /** @@ -85,7 +88,7 @@ public final class TNEFDateAttribute extends TNEFAttribute { return ((TNEFDateAttribute)attr).getDate(); } - System.err.println("Warning, non date property found: " + attr.toString()); + logger.log(POILogger.WARN, "Warning, non date property found: " + attr.toString()); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFStringAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFStringAttribute.java index 983d3f9a2..34e1ef369 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFStringAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/TNEFStringAttribute.java @@ -22,6 +22,8 @@ import java.io.InputStream; import org.apache.poi.hmef.Attachment; import org.apache.poi.hmef.HMEFMessage; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -29,6 +31,7 @@ import org.apache.poi.util.StringUtil; * or one of its {@link Attachment}s. */ public final class TNEFStringAttribute extends TNEFAttribute { + private static POILogger logger = POILogFactory.getLogger(TNEFStringAttribute.class); private String data; /** @@ -75,7 +78,7 @@ public final class TNEFStringAttribute extends TNEFAttribute { return ((TNEFStringAttribute)attr).getString(); } - System.err.println("Warning, non string property found: " + attr.toString()); + logger.log(POILogger.WARN, "Warning, non string property found: " + attr.toString()); return null; } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java b/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java index 217a60f85..6fef2cc8e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Sheet.java @@ -20,6 +20,8 @@ package org.apache.poi.hslf.model; import org.apache.poi.ddf.*; import org.apache.poi.hslf.record.*; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import java.util.ArrayList; import java.util.Iterator; @@ -35,6 +37,8 @@ import java.awt.*; */ public abstract class Sheet { + private static POILogger logger = POILogFactory.getLogger(Sheet.class); + /** * The SlideShow we belong to */ @@ -194,7 +198,7 @@ public abstract class Sheet { } else if (records[i + 1].getRecordType() == 4010l) { // TextSpecInfoAtom - Safe to ignore } else { - System.err.println("Found a TextHeaderAtom not followed by a TextBytesAtom or TextCharsAtom: Followed by " + records[i + 1].getRecordType()); + logger.log(POILogger.ERROR, "Found a TextHeaderAtom not followed by a TextBytesAtom or TextCharsAtom: Followed by " + records[i + 1].getRecordType()); } if (trun != null) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java index 1c7ad9f7f..0335cece3 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java @@ -23,6 +23,8 @@ package org.apache.poi.hslf.record; import java.io.*; import org.apache.poi.poifs.filesystem.*; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException; import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException; @@ -39,6 +41,8 @@ import org.apache.poi.hslf.exceptions.OldPowerPointFormatException; public class CurrentUserAtom { + private static POILogger logger = POILogFactory.getLogger(CurrentUserAtom.class); + /** Standard Atom header */ public static final byte[] atomHeader = new byte[] { 0, 0, -10, 15 }; /** The PowerPoint magic number for a non-encrypted file */ @@ -128,7 +132,7 @@ public class CurrentUserAtom if(_contents.length >= 4) { // PPT95 has 4 byte size, then data int size = LittleEndian.getInt(_contents); - System.err.println(size); + //System.err.println(size); if(size + 4 == _contents.length) { throw new OldPowerPointFormatException("Based on the Current User stream, you seem to have supplied a PowerPoint95 file, which isn't supported"); } @@ -173,7 +177,7 @@ public class CurrentUserAtom long usernameLen = LittleEndian.getUShort(_contents,20); if(usernameLen > 512) { // Handle the case of it being garbage - System.err.println("Warning - invalid username length " + usernameLen + " found, treating as if there was no username set"); + logger.log(POILogger.WARN, "Warning - invalid username length " + usernameLen + " found, treating as if there was no username set"); usernameLen = 0; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java index 09126999e..5530e2454 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java @@ -38,7 +38,7 @@ import org.apache.poi.util.POILogger; public abstract class Record { // For logging - protected POILogger logger = POILogFactory.getLogger(this.getClass()); + protected static POILogger logger = POILogFactory.getLogger(Record.class); /** * Is this record type an Atom record (only has data), @@ -155,7 +155,7 @@ public abstract class Record // Handle case of a corrupt last record, whose claimed length // would take us passed the end of the file if(start + len > b.length) { - System.err.println("Warning: Skipping record of type " + type + " at position " + start + " which claims to be longer than the file! (" + len + " vs " + (b.length-start) + ")"); + logger.log(POILogger.WARN, "Warning: Skipping record of type " + type + " at position " + start + " which claims to be longer than the file! (" + len + " vs " + (b.length-start) + ")"); return null; } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java index 55f8a5f25..aa17b7f7b 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java @@ -37,11 +37,14 @@ import java.util.Comparator; import java.util.List; import org.apache.poi.hsmf.MAPIMessage; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * Collection of convenence chunks for standard parts of the MSG file attachment. */ public class AttachmentChunks implements ChunkGroup { + private static POILogger logger = POILogFactory.getLogger(AttachmentChunks.class); public static final String PREFIX = "__attach_version1.0_#"; public ByteChunk attachData; @@ -131,7 +134,7 @@ public class AttachmentChunks implements ChunkGroup { } else if(chunk instanceof DirectoryChunk) { attachmentDirectory = (DirectoryChunk)chunk; } else { - System.err.println("Unexpected data chunk of type " + chunk); + logger.log(POILogger.ERROR, "Unexpected data chunk of type " + chunk); } } else if(chunk.getChunkId() == ATTACH_DISPOSITION.id) { diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java index 397717c7f..0c59b02eb 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java @@ -26,6 +26,8 @@ import java.util.regex.Pattern; import org.apache.poi.hsmf.datatypes.Types.MAPIType; import org.apache.poi.util.IOUtils; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * A Chunk that holds the details given back by the @@ -36,6 +38,7 @@ import org.apache.poi.util.IOUtils; */ public class MessageSubmissionChunk extends Chunk { + private static POILogger logger = POILogFactory.getLogger(MessageSubmissionChunk.class); private String rawId; private Calendar date; @@ -87,7 +90,7 @@ public class MessageSubmissionChunk extends Chunk { date.set(Calendar.SECOND, Integer.parseInt(m.group(6))); date.set(Calendar.MILLISECOND, 0); } else { - System.err.println("Warning - unable to make sense of date " + dateS); + logger.log(POILogger.WARN, "Warning - unable to make sense of date " + dateS); } } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java index dd3c47057..a3f57248a 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java @@ -21,6 +21,9 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; + /** * Collection of convenience chunks for the @@ -30,6 +33,8 @@ import java.util.List; * several of these. */ public final class RecipientChunks implements ChunkGroup { + private static POILogger logger = POILogFactory.getLogger(RecipientChunks.class); + public static final String PREFIX = "__recip_version1.0_#"; public static final MAPIProperty RECIPIENT_NAME = MAPIProperty.DISPLAY_NAME; @@ -82,7 +87,7 @@ public final class RecipientChunks implements ChunkGroup { try { recipientNumber = Integer.parseInt(number, 16); } catch(NumberFormatException e) { - System.err.println("Invalid recipient number in name " + name); + logger.log(POILogger.ERROR, "Invalid recipient number in name " + name); } } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java index 6800b0ac7..434d0cbd6 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java @@ -41,6 +41,8 @@ import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.DocumentNode; import org.apache.poi.poifs.filesystem.Entry; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * Processes a POIFS of a .msg file into groups of Chunks, such as @@ -48,6 +50,8 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; * data and so on. */ public final class POIFSChunkParser { + private static POILogger logger = POILogFactory.getLogger(POIFSChunkParser.class); + public static ChunkGroup[] parse(POIFSFileSystem fs) throws IOException { return parse(fs.getRoot()); } @@ -200,7 +204,7 @@ public final class POIFSChunkParser { chunk.readValue(inp); grouping.record(chunk); } catch(IOException e) { - System.err.println("Error reading from part " + entry.getName() + " - " + e.toString()); + logger.log(POILogger.ERROR, "Error reading from part " + entry.getName() + " - " + e.toString()); } } else { grouping.record(chunk); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java index 89ac7e563..6efb6ad22 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java @@ -453,7 +453,7 @@ public class AbstractWordUtils { if ( format != 0 ) - System.err.println( "NYI: toListItemNumberLabel(): " + format ); + logger.log( POILogger.INFO, "NYI: toListItemNumberLabel(): " + format ); return String.valueOf( number ); }