From b15b18bae7c1a767340d61187223341334256739 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sun, 10 Jan 2016 02:20:35 +0000 Subject: [PATCH] replace Throwable.printStackTrace() with POILogger calls - Todo: other printStrackTrace(...) calls git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1723899 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/dev/BiffViewer.java | 10 +---- .../org/apache/poi/hssf/dev/EFBiffViewer.java | 15 ++----- .../apache/poi/hssf/dev/FormulaViewer.java | 36 +++++++---------- .../org/apache/poi/hssf/dev/RecordLister.java | 15 ++----- .../poi/hssf/extractor/ExcelExtractor.java | 39 +++++++++---------- .../apache/poi/hssf/usermodel/HSSFShape.java | 23 ++++++++--- .../poifs/filesystem/NPOIFSFileSystem.java | 7 ++-- .../poifs/filesystem/OPOIFSFileSystem.java | 2 +- .../poi/ss/format/CellNumberFormatter.java | 6 ++- .../poi/ss/formula/WorkbookEvaluator.java | 2 +- .../apache/poi/ss/formula/functions/Rate.java | 6 ++- .../poi/xssf/extractor/XSSFExportToXml.java | 5 ++- .../xwpf/model/XWPFHeaderFooterPolicy.java | 7 +++- .../poi/xwpf/usermodel/XWPFDocument.java | 6 ++- .../devtools/forbidden-signatures-prod.txt | 5 ++- .../textproperties/TextPropCollection.java | 8 +++- .../poi/hslf/record/MasterTextPropAtom.java | 3 +- .../apache/poi/hslf/record/TextRulerAtom.java | 4 -- .../poi/hslf/record/TxMasterStyleAtom.java | 4 +- .../hssf/converter/ExcelToHtmlConverter.java | 38 +++++++++--------- .../src/org/apache/poi/hwpf/QuickTest.java | 12 ++---- .../apache/poi/hwpf/model/CHPBinTable.java | 11 +----- .../apache/poi/hwpf/model/PAPBinTable.java | 25 ++---------- .../org/apache/poi/hwpf/sprm/SprmBuffer.java | 15 ++++--- 24 files changed, 139 insertions(+), 165 deletions(-) diff --git a/src/java/org/apache/poi/hssf/dev/BiffViewer.java b/src/java/org/apache/poi/hssf/dev/BiffViewer.java index 2752169344..553c7a351c 100644 --- a/src/java/org/apache/poi/hssf/dev/BiffViewer.java +++ b/src/java/org/apache/poi/hssf/dev/BiffViewer.java @@ -390,15 +390,9 @@ public final class BiffViewer { * * */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, CommandParseException { // args = new String[] { "--out", "", }; - CommandArgs cmdArgs; - try { - cmdArgs = CommandArgs.parse(args); - } catch (CommandParseException e) { - e.printStackTrace(); - return; - } + CommandArgs cmdArgs = CommandArgs.parse(args); PrintWriter pw; if (cmdArgs.shouldOutputToFile()) { diff --git a/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java b/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java index be8fe537a2..b136e4ca8a 100644 --- a/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java +++ b/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java @@ -72,21 +72,14 @@ public class EFBiffViewer this.file = file; } - public static void main(String [] args) + public static void main(String [] args) throws IOException { if ((args.length == 1) && !args[ 0 ].equals("--help")) { - try - { - EFBiffViewer viewer = new EFBiffViewer(); + EFBiffViewer viewer = new EFBiffViewer(); - viewer.setFile(args[ 0 ]); - viewer.run(); - } - catch (IOException e) - { - e.printStackTrace(); - } + viewer.setFile(args[ 0 ]); + viewer.run(); } else { diff --git a/src/java/org/apache/poi/hssf/dev/FormulaViewer.java b/src/java/org/apache/poi/hssf/dev/FormulaViewer.java index eaa3fff0b5..5ea0331ad7 100644 --- a/src/java/org/apache/poi/hssf/dev/FormulaViewer.java +++ b/src/java/org/apache/poi/hssf/dev/FormulaViewer.java @@ -18,6 +18,7 @@ package org.apache.poi.hssf.dev; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.List; @@ -52,13 +53,14 @@ public class FormulaViewer /** * Method run + * @throws IOException * * * @exception Exception * */ - public void run() throws Exception { + public void run() throws IOException { NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true); InputStream is = BiffViewer.getPOIFSInputStream(fs); List records = RecordFactory.createRecords(is); @@ -206,10 +208,12 @@ public class FormulaViewer * pass me a filename and I'll try and parse the formulas from it * * @param args pass one argument with the filename or --help + * @throws IOException + * @throws Exception * */ - public static void main(String args[]) + public static void main(String args[]) throws IOException { if ((args == null) || (args.length >2 ) || args[ 0 ].equals("--help")) @@ -218,31 +222,17 @@ public class FormulaViewer "FormulaViewer .8 proof that the devil lies in the details (or just in BIFF8 files in general)"); System.out.println("usage: Give me a big fat file name"); } else if (args[0].equals("--listFunctions")) { // undocumented attribute to research functions!~ - try { - FormulaViewer viewer = new FormulaViewer(); - viewer.setFile(args[1]); - viewer.setList(true); - viewer.run(); - } - catch (Exception e) { - System.out.println("Whoops!"); - e.printStackTrace(); - } + FormulaViewer viewer = new FormulaViewer(); + viewer.setFile(args[1]); + viewer.setList(true); + viewer.run(); } else { - try - { - FormulaViewer viewer = new FormulaViewer(); + FormulaViewer viewer = new FormulaViewer(); - viewer.setFile(args[ 0 ]); - viewer.run(); - } - catch (Exception e) - { - System.out.println("Whoops!"); - e.printStackTrace(); - } + viewer.setFile(args[ 0 ]); + viewer.run(); } } } diff --git a/src/java/org/apache/poi/hssf/dev/RecordLister.java b/src/java/org/apache/poi/hssf/dev/RecordLister.java index 2f61ea3765..8cb71e5da4 100644 --- a/src/java/org/apache/poi/hssf/dev/RecordLister.java +++ b/src/java/org/apache/poi/hssf/dev/RecordLister.java @@ -180,21 +180,14 @@ public class RecordLister this.file = file; } - public static void main(String [] args) + public static void main(String [] args) throws IOException { if ((args.length == 1) && !args[ 0 ].equals("--help")) { - try - { - RecordLister viewer = new RecordLister(); + RecordLister viewer = new RecordLister(); - viewer.setFile(args[ 0 ]); - viewer.run(); - } - catch (IOException e) - { - e.printStackTrace(); - } + viewer.setFile(args[ 0 ]); + viewer.run(); } else { diff --git a/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java b/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java index b270182a0f..27df0c8f17 100644 --- a/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java +++ b/src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java @@ -207,8 +207,9 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p /** * Command line extractor. + * @throws IOException */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { CommandArgs cmdArgs; try { @@ -225,27 +226,23 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p return; } - try { - InputStream is; - if(cmdArgs.getInputFile() == null) { - is = System.in; - } else { - is = new FileInputStream(cmdArgs.getInputFile()); - } - HSSFWorkbook wb = new HSSFWorkbook(is); - - ExcelExtractor extractor = new ExcelExtractor(wb); - extractor.setIncludeSheetNames(cmdArgs.shouldShowSheetNames()); - extractor.setFormulasNotResults(!cmdArgs.shouldEvaluateFormulas()); - extractor.setIncludeCellComments(cmdArgs.shouldShowCellComments()); - extractor.setIncludeBlankCells(cmdArgs.shouldShowBlankCells()); - extractor.setIncludeHeadersFooters(cmdArgs.shouldIncludeHeadersFooters()); - System.out.println(extractor.getText()); - extractor.close(); - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); + InputStream is; + if(cmdArgs.getInputFile() == null) { + is = System.in; + } else { + is = new FileInputStream(cmdArgs.getInputFile()); } + HSSFWorkbook wb = new HSSFWorkbook(is); + is.close(); + + ExcelExtractor extractor = new ExcelExtractor(wb); + extractor.setIncludeSheetNames(cmdArgs.shouldShowSheetNames()); + extractor.setFormulasNotResults(!cmdArgs.shouldEvaluateFormulas()); + extractor.setIncludeCellComments(cmdArgs.shouldShowCellComments()); + extractor.setIncludeBlankCells(cmdArgs.shouldShowBlankCells()); + extractor.setIncludeHeadersFooters(cmdArgs.shouldIncludeHeadersFooters()); + System.out.println(extractor.getText()); + extractor.close(); } /** * Should sheet names be included? Default is true diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java b/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java index 4775122f82..dbdd741548 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java @@ -17,13 +17,24 @@ package org.apache.poi.hssf.usermodel; -import org.apache.poi.ddf.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.apache.poi.ddf.EscherBoolProperty; +import org.apache.poi.ddf.EscherChildAnchorRecord; +import org.apache.poi.ddf.EscherClientAnchorRecord; +import org.apache.poi.ddf.EscherContainerRecord; +import org.apache.poi.ddf.EscherOptRecord; +import org.apache.poi.ddf.EscherProperties; +import org.apache.poi.ddf.EscherProperty; +import org.apache.poi.ddf.EscherRGBProperty; +import org.apache.poi.ddf.EscherSimpleProperty; +import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.hssf.record.CommonObjectDataSubRecord; import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.util.LittleEndian; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * An abstract shape. @@ -34,6 +45,8 @@ import java.io.IOException; * setFlipVertical() or setFlipHorizontally(). */ public abstract class HSSFShape { + private static final POILogger LOG = POILogFactory.getLogger(HSSFShape.class); + public static final int LINEWIDTH_ONE_PT = 12700; public static final int LINEWIDTH_DEFAULT = 9525; public static final int LINESTYLE__COLOR_DEFAULT = 0x08000040; @@ -362,7 +375,7 @@ public abstract class HSSFShape { LittleEndian.putInt(property.getPropertyValue(), bos); return LittleEndian.getShort(bos.toByteArray(), 2); } catch (IOException e) { - e.printStackTrace(); + LOG.log(POILogger.ERROR, "can't determine rotation degree", e); return 0; } } diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java index 5fa7fb3aae..71d39546d0 100644 --- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java @@ -57,6 +57,8 @@ import org.apache.poi.util.CloseIgnoringInputStream; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LongField; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** *

This is the main class of the POIFS system; it manages the entire @@ -67,8 +69,7 @@ import org.apache.poi.util.LongField; public class NPOIFSFileSystem extends BlockStore implements POIFSViewable, Closeable { -// private static final POILogger _logger = -// POILogFactory.getLogger(NPOIFSFileSystem.class); + private static final POILogger LOG = POILogFactory.getLogger(NPOIFSFileSystem.class); /** * Convenience method for clients that want to avoid the auto-close behaviour of the constructor. @@ -346,7 +347,7 @@ public class NPOIFSFileSystem extends BlockStore } // else not success? Try block did not complete normally // just print stack trace and leave original ex to be thrown - e.printStackTrace(); + LOG.log(POILogger.ERROR, "can't close input stream", e); } } diff --git a/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java index 19abc48abe..b0afaa3338 100644 --- a/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/OPOIFSFileSystem.java @@ -194,7 +194,7 @@ public class OPOIFSFileSystem } // else not success? Try block did not complete normally // just print stack trace and leave original ex to be thrown - e.printStackTrace(); + _logger.log(POILogger.ERROR, "can't close input stream", e); } } diff --git a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java index f38f78006f..b291cfd9a9 100644 --- a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java @@ -32,6 +32,8 @@ import java.util.regex.Matcher; import org.apache.poi.ss.format.CellFormatPart.PartHandler; import org.apache.poi.util.LocaleUtil; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * This class implements printing out a value using a number format. @@ -39,6 +41,8 @@ import org.apache.poi.util.LocaleUtil; * @author Ken Arnold, Industrious Media LLC */ public class CellNumberFormatter extends CellFormatter { + private static final POILogger LOG = POILogFactory.getLogger(CellNumberFormatter.class); + private final String desc; private String printfFmt; private double scale; @@ -843,7 +847,7 @@ public class CellNumberFormatter extends CellFormatter { writeSingleInteger(denominatorFmt, d, output, denominatorSpecials, mods); } catch (RuntimeException ignored) { - ignored.printStackTrace(); + LOG.log(POILogger.ERROR, "error while fraction evaluation", ignored); } } diff --git a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java index 03dd9772fe..f4b30c4f0e 100644 --- a/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java @@ -332,7 +332,7 @@ public final class WorkbookEvaluator { return new NotImplementedException(msg, inner); } catch (Exception e) { // avoid bombing out during exception handling - e.printStackTrace(); + LOG.log(POILogger.ERROR, "Can't add exception info", e); return inner; // preserve original exception } } diff --git a/src/java/org/apache/poi/ss/formula/functions/Rate.java b/src/java/org/apache/poi/ss/formula/functions/Rate.java index bc53585134..2a28b95f37 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Rate.java +++ b/src/java/org/apache/poi/ss/formula/functions/Rate.java @@ -22,11 +22,15 @@ import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.ValueEval; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * Implements the Excel Rate function */ public class Rate implements Function { + private static final POILogger LOG = POILogFactory.getLogger(Rate.class); + public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { if (args.length < 3) { //First 3 parameters are mandatory return ErrorEval.VALUE_INVALID; @@ -61,7 +65,7 @@ public class Rate implements Function { checkValue(rate); } catch (EvaluationException e) { - e.printStackTrace() ; + LOG.log(POILogger.ERROR, "Can't evaluate rate function", e); return e.getErrorEval(); } diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index f6ad11f1eb..734a9f4546 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -46,6 +46,8 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.util.DocumentHelper; import org.apache.poi.util.LocaleUtil; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFMap; import org.apache.poi.xssf.usermodel.XSSFRow; @@ -80,6 +82,7 @@ import org.xml.sax.SAXException; * */ public class XSSFExportToXml implements Comparator{ + private static final POILogger LOG = POILogFactory.getLogger(XSSFExportToXml.class); private XSSFMap map; @@ -265,7 +268,7 @@ public class XSSFExportToXml implements Comparator{ //if no exceptions where raised, the document is valid return true; } catch(IOException e) { - e.printStackTrace(); + LOG.log(POILogger.ERROR, "document is not valid", e); } return false; diff --git a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java index 28ba945792..d6f3e51599 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java +++ b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java @@ -24,6 +24,8 @@ import java.util.Iterator; import java.util.List; import org.apache.poi.POIXMLDocumentPart; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFFactory; import org.apache.poi.xwpf.usermodel.XWPFFooter; @@ -66,6 +68,8 @@ import com.microsoft.schemas.vml.STTrueFalse; * the right headers and footers for the document. */ public class XWPFHeaderFooterPolicy { + private static final POILogger LOG = POILogFactory.getLogger(XWPFHeaderFooterPolicy.class); + public static final Enum DEFAULT = STHdrFtr.DEFAULT; public static final Enum EVEN = STHdrFtr.EVEN; public static final Enum FIRST = STHdrFtr.FIRST; @@ -376,8 +380,7 @@ public class XWPFHeaderFooterPolicy { pars[0] = getWatermarkParagraph(text, 3); createHeader(EVEN, pars); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOG.log(POILogger.ERROR, "error while creating watermark", e); } } diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index cdbada28ea..3fecf9de48 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -52,6 +52,8 @@ import org.apache.poi.poifs.crypt.HashAlgorithm; import org.apache.poi.util.IOUtils; import org.apache.poi.util.IdentifierManager; import org.apache.poi.util.Internal; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.util.PackageHelper; import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; import org.apache.xmlbeans.XmlCursor; @@ -88,6 +90,8 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument; * at some point in your use.

*/ public class XWPFDocument extends POIXMLDocument implements Document, IBody { + private static final POILogger LOG = POILogFactory.getLogger(XWPFDocument.class); + protected List footers = new ArrayList(); protected List headers = new ArrayList(); protected List comments = new ArrayList(); @@ -899,7 +903,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { int level = Integer.parseInt(parStyle.substring("Heading".length())); toc.addRow(level, par.getText(), 1, "112723803"); } catch (NumberFormatException e) { - e.printStackTrace(); + LOG.log(POILogger.ERROR, "can't format number in TOC heading", e); } } } diff --git a/src/resources/devtools/forbidden-signatures-prod.txt b/src/resources/devtools/forbidden-signatures-prod.txt index 3dd98b2fbe..bc63b5b3c7 100644 --- a/src/resources/devtools/forbidden-signatures-prod.txt +++ b/src/resources/devtools/forbidden-signatures-prod.txt @@ -25,5 +25,6 @@ #java.lang.Runtime#exit(int) #java.lang.Runtime#halt(int) -@defaultMessage Please do not try to stop the world -java.lang.System#gc() + +java.lang.System#gc() @ Please do not try to stop the world +java.lang.Throwable#printStackTrace() @ Please use POILogger for exceptions diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java index cf45cc790f..b6ffeec9bd 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/TextPropCollection.java @@ -29,6 +29,8 @@ import org.apache.poi.hslf.exceptions.HSLFException; import org.apache.poi.hslf.record.StyleTextPropAtom; import org.apache.poi.util.HexDump; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; /** * For a given run of characters, holds the properties (which could @@ -37,6 +39,8 @@ import org.apache.poi.util.LittleEndian; * properties, and the indent level if required. */ public class TextPropCollection { + private static final POILogger LOG = POILogFactory.getLogger(TextPropCollection.class); + /** All the different kinds of paragraph properties we might handle */ private static final TextProp[] paragraphTextPropTypes = { // TextProp order is according to 2.9.20 TextPFException, @@ -376,8 +380,8 @@ public class TextPropCollection { writeOut(baos); byte[] b = baos.toByteArray(); out.append(HexDump.dump(b, 0, 0)); - } catch (Exception e ) { - e.printStackTrace(); + } catch (IOException e ) { + LOG.log(POILogger.ERROR, "can't dump TextPropCollection", e); } return out.toString(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java index dd942133ee..d38b390af0 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java @@ -77,8 +77,7 @@ public final class MasterTextPropAtom extends RecordAtom { try { read(); } catch (Exception e){ - logger.log(POILogger.ERROR, "Failed to parse MasterTextPropAtom: " + e.getMessage()); - e.printStackTrace(); + logger.log(POILogger.ERROR, "Failed to parse MasterTextPropAtom", e); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java index f81061dc0a..9b40a9893c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java @@ -25,11 +25,8 @@ import org.apache.poi.util.POILogger; /** * Ruler of a text as it differs from the style's ruler settings. - * - * @author Yegor Kozlov */ public final class TextRulerAtom extends RecordAtom { - /** * Record header. */ @@ -79,7 +76,6 @@ public final class TextRulerAtom extends RecordAtom { read(); } catch (Exception e){ logger.log(POILogger.ERROR, "Failed to parse TextRulerAtom: " + e.getMessage()); - e.printStackTrace(); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java index e63137d9c5..b4b8e80046 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -48,6 +48,8 @@ import org.apache.poi.util.POILogger; * @author Yegor Kozlov */ public final class TxMasterStyleAtom extends RecordAtom { + private static final POILogger LOG = POILogFactory.getLogger(TxMasterStyleAtom.class); + /** * Maximum number of indentation levels allowed in PowerPoint documents */ @@ -71,7 +73,7 @@ public final class TxMasterStyleAtom extends RecordAtom { try { init(); } catch (Exception e){ - POILogFactory.getLogger(TxMasterStyleAtom.class).log(POILogger.WARN, "Exception when reading available styles", e); + LOG.log(POILogger.WARN, "Exception when reading available styles", e); } } diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java index b16a961fbf..c61f05d9a2 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java @@ -17,13 +17,16 @@ package org.apache.poi.hssf.converter; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -68,8 +71,11 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter *

* Where infile is an input .xls file ( Word 97-2007) which will be rendered * as HTML into outfile + * @throws TransformerException + * @throws Exception */ public static void main( String[] args ) + throws IOException, ParserConfigurationException, TransformerException { if ( args.length < 2 ) { @@ -80,25 +86,19 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter System.out.println( "Converting " + args[0] ); System.out.println( "Saving output to " + args[1] ); - try - { - Document doc = ExcelToHtmlConverter.process( new File( args[0] ) ); - DOMSource domSource = new DOMSource( doc ); - StreamResult streamResult = new StreamResult( new File(args[1]) ); + Document doc = ExcelToHtmlConverter.process( new File( args[0] ) ); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer serializer = tf.newTransformer(); - // TODO set encoding from a command argument - serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" ); - serializer.setOutputProperty( OutputKeys.INDENT, "no" ); - serializer.setOutputProperty( OutputKeys.METHOD, "html" ); - serializer.transform( domSource, streamResult ); - } - catch ( Exception e ) - { - e.printStackTrace(); - } + DOMSource domSource = new DOMSource( doc ); + StreamResult streamResult = new StreamResult( new File(args[1]) ); + + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer serializer = tf.newTransformer(); + // TODO set encoding from a command argument + serializer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" ); + serializer.setOutputProperty( OutputKeys.INDENT, "no" ); + serializer.setOutputProperty( OutputKeys.METHOD, "html" ); + serializer.transform( domSource, streamResult ); } /** @@ -107,8 +107,10 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter * @param xlsFile * file to process * @return DOM representation of result HTML + * @throws IOException + * @throws ParserConfigurationException */ - public static Document process( File xlsFile ) throws Exception + public static Document process( File xlsFile ) throws IOException, ParserConfigurationException { final HSSFWorkbook workbook = ExcelToHtmlUtils.loadXls( xlsFile ); ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter( diff --git a/src/scratchpad/src/org/apache/poi/hwpf/QuickTest.java b/src/scratchpad/src/org/apache/poi/hwpf/QuickTest.java index 09e1b9342b..ec97cb4c10 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/QuickTest.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/QuickTest.java @@ -18,6 +18,8 @@ package org.apache.poi.hwpf; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import org.apache.poi.hwpf.usermodel.CharacterRun; import org.apache.poi.hwpf.usermodel.Paragraph; @@ -30,10 +32,8 @@ public final class QuickTest { } - public static void main(String[] args) + public static void main(String[] args) throws IOException { - try - { HWPFDocument doc = new HWPFDocument (new FileInputStream (args[0])); Range r = doc.getRange(); @@ -81,12 +81,6 @@ public final class QuickTest // System.out.println(); // } // } - - } - catch (Exception t) - { - t.printStackTrace(); - } } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java index 18747c4367..7a3f19121b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java @@ -156,16 +156,7 @@ public class CHPBinTable if ( hasChp ) { - SprmBuffer newSprmBuffer; - try - { - newSprmBuffer = (SprmBuffer) sprmBuffer.clone(); - } - catch ( CloneNotSupportedException e ) - { - // shall not happen - throw new Error( e ); - } + SprmBuffer newSprmBuffer = sprmBuffer.clone(); CHPX chpx = new CHPX( textPiece.getStart(), textPiece.getEnd(), newSprmBuffer ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java index cae8089c48..a139ee0f4f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java @@ -277,18 +277,9 @@ public class PAPBinTable if ( papx.getGrpprl() == null || papx.getGrpprl().length == 0 ) continue; - if ( sprmBuffer == null ) - try - { - sprmBuffer = (SprmBuffer) papx.getSprmBuf().clone(); - } - catch ( CloneNotSupportedException e ) - { - // can't happen - throw new Error( e ); - } - else - { + if ( sprmBuffer == null ) { + sprmBuffer = papx.getSprmBuf().clone(); + } else { sprmBuffer.append( papx.getGrpprl(), 2 ); } } @@ -325,15 +316,7 @@ public class PAPBinTable PAPX currentPap = _paragraphs.get(listIndex); if (currentPap != null && currentPap.getStart() < cpStart) { - SprmBuffer clonedBuf = null; - try - { - clonedBuf = (SprmBuffer)currentPap.getSprmBuf().clone(); - } - catch (CloneNotSupportedException exc) - { - exc.printStackTrace(); - } + SprmBuffer clonedBuf = currentPap.getSprmBuf().clone(); // Copy the properties of the one before to afterwards // Will go: diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java index 73120db367..24ef823c49 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java @@ -128,13 +128,16 @@ public final class SprmBuffer implements Cloneable System.arraycopy( grpprl, offset, _buf, _offset, grpprl.length - offset ); _offset += grpprl.length - offset; } - public Object clone() - throws CloneNotSupportedException + public SprmBuffer clone() { - SprmBuffer retVal = (SprmBuffer)super.clone(); - retVal._buf = new byte[_buf.length]; - System.arraycopy(_buf, 0, retVal._buf, 0, _buf.length); - return retVal; + try { + SprmBuffer retVal = (SprmBuffer)super.clone(); + retVal._buf = new byte[_buf.length]; + System.arraycopy(_buf, 0, retVal._buf, 0, _buf.length); + return retVal; + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } } private void ensureCapacity( int addition ) {