]> source.dussan.org Git - poi.git/commitdiff
Fix some IDE warnings, Sonar fixes and some missing closing of resources in unit...
authorDominik Stadler <centic@apache.org>
Mon, 27 Jan 2020 22:54:03 +0000 (22:54 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 27 Jan 2020 22:54:03 +0000 (22:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1873231 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java
src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java
src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java

index 0b662e42f21bd063b8c5d06eebad53ac90657417..77dbbceeba5b37433a429f643b689ccbdf7c2088 100644 (file)
@@ -588,14 +588,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
 
     public XDDFValueAxis createValueAxis(AxisPosition pos) {
         XDDFValueAxis valueAxis = new XDDFValueAxis(getCTPlotArea(), pos);
-        if (axes.size() == 1) {
-            XDDFChartAxis axis = axes.get(0);
-            axis.crossAxis(valueAxis);
-            valueAxis.crossAxis(axis);
-            axis.setCrosses(AxisCrosses.AUTO_ZERO);
-            valueAxis.setCrosses(AxisCrosses.AUTO_ZERO);
-        }
-        axes.add(valueAxis);
+        addAxis(valueAxis);
         return valueAxis;
     }
 
@@ -607,41 +600,31 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
      */
     public XDDFSeriesAxis createSeriesAxis(AxisPosition pos) {
         XDDFSeriesAxis seriesAxis = new XDDFSeriesAxis(getCTPlotArea(), pos);
-        if (axes.size() == 1) {
-            XDDFChartAxis axis = axes.get(0);
-            axis.crossAxis(seriesAxis);
-            seriesAxis.crossAxis(axis);
-            axis.setCrosses(AxisCrosses.AUTO_ZERO);
-            seriesAxis.setCrosses(AxisCrosses.AUTO_ZERO);
-        }
-        axes.add(seriesAxis);
+        addAxis(seriesAxis);
         return seriesAxis;
     }
 
     public XDDFCategoryAxis createCategoryAxis(AxisPosition pos) {
         XDDFCategoryAxis categoryAxis = new XDDFCategoryAxis(getCTPlotArea(), pos);
-        if (axes.size() == 1) {
-            XDDFChartAxis axis = axes.get(0);
-            axis.crossAxis(categoryAxis);
-            categoryAxis.crossAxis(axis);
-            axis.setCrosses(AxisCrosses.AUTO_ZERO);
-            categoryAxis.setCrosses(AxisCrosses.AUTO_ZERO);
-        }
-        axes.add(categoryAxis);
+        addAxis(categoryAxis);
         return categoryAxis;
     }
 
     public XDDFDateAxis createDateAxis(AxisPosition pos) {
         XDDFDateAxis dateAxis = new XDDFDateAxis(getCTPlotArea(), pos);
+        addAxis(dateAxis);
+        return dateAxis;
+    }
+
+    private void addAxis(XDDFChartAxis newAxis) {
         if (axes.size() == 1) {
             XDDFChartAxis axis = axes.get(0);
-            axis.crossAxis(dateAxis);
-            dateAxis.crossAxis(axis);
+            axis.crossAxis(newAxis);
+            newAxis.crossAxis(axis);
             axis.setCrosses(AxisCrosses.AUTO_ZERO);
-            dateAxis.setCrosses(AxisCrosses.AUTO_ZERO);
+            newAxis.setCrosses(AxisCrosses.AUTO_ZERO);
         }
-        axes.add(dateAxis);
-        return dateAxis;
+        axes.add(newAxis);
     }
 
     /**
@@ -774,7 +757,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
     public PackageRelationship createRelationshipInChart(POIXMLRelation chartRelation, POIXMLFactory chartFactory,
         int chartIndex) {
         documentPart = createRelationship(chartRelation, chartFactory, chartIndex, true).getDocumentPart();
-        return this.addRelation(null, chartRelation, documentPart).getRelationship();
+        return addRelation(null, chartRelation, documentPart).getRelationship();
     }
 
     /**
@@ -793,7 +776,7 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
     private PackagePart createWorksheetPart(POIXMLRelation chartRelation, POIXMLRelation chartWorkbookRelation,
         POIXMLFactory chartFactory) throws InvalidFormatException {
         PackageRelationship xlsx = createRelationshipInChart(chartWorkbookRelation, chartFactory, chartIndex);
-        this.setExternalId(xlsx.getId());
+        setExternalId(xlsx.getId());
         return getTargetPart(xlsx);
     }
 
@@ -859,14 +842,14 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
     protected void fillSheet(XSSFSheet sheet, XDDFDataSource<?> categoryData, XDDFNumericalDataSource<?> valuesData) {
         int numOfPoints = categoryData.getPointCount();
         for (int i = 0; i < numOfPoints; i++) {
-            XSSFRow row = this.getRow(sheet, i + 1); // first row is for title
+            XSSFRow row = getRow(sheet, i + 1); // first row is for title
             Object category = categoryData.getPointAt(i);
             if (category != null) {
-                this.getCell(row, categoryData.getColIndex()).setCellValue(category.toString());
+                getCell(row, categoryData.getColIndex()).setCellValue(category.toString());
             }
             Number value = valuesData.getPointAt(i);
             if (value != null) {
-                this.getCell(row, valuesData.getColIndex()).setCellValue(value.doubleValue());
+                getCell(row, valuesData.getColIndex()).setCellValue(value.doubleValue());
             }
         }
     }
@@ -956,8 +939,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart implements TextContai
      */
     public CellReference setSheetTitle(String title, int column) {
         XSSFSheet sheet = getSheet();
-        XSSFRow row = this.getRow(sheet, 0);
-        XSSFCell cell = this.getCell(row, column);
+        XSSFRow row = getRow(sheet, 0);
+        XSSFCell cell = getCell(row, column);
         cell.setCellValue(title);
 
         return new CellReference(sheet.getSheetName(), 0, column, true, true);
index 6deafc4bec0e76c3997dcc0643f1c7b6bef7e88a..77ac1e228697717e1208658ba585d5bc958bf5e1 100644 (file)
@@ -99,7 +99,7 @@ public class XSSFFont implements Font {
         setFontName(DEFAULT_FONT_NAME);
         setFontHeight((double)DEFAULT_FONT_SIZE);
     }
-    
+
     /**
      * get the underlying CTFont font
      */
@@ -209,7 +209,7 @@ public class XSSFFont implements Font {
     public short getFontHeightInPoints() {
         return (short)getFontHeightRaw();
     }
-    
+
     /**
      * Return the raw font height, in points, but also
      *  including fractions.
@@ -540,7 +540,7 @@ public class XSSFFont implements Font {
 
 
     /**
-     * Perform a registration of ourselves 
+     * Perform a registration of ourselves
      *  to the style table
      */
     public long registerTo(StylesTable styles) {
@@ -649,7 +649,7 @@ public class XSSFFont implements Font {
                         && Objects.equals(this.getBold(), cf.getBold())
                         && Objects.equals(this.getStrikeout(), cf.getStrikeout())
                         && Objects.equals(this.getCharSet(), cf.getCharSet())
-                        && Objects.equals(this.getBold(), cf.getBold())
+                        && Objects.equals(this.getItalic(), cf.getItalic())
                         && Objects.equals(this.getColor(), cf.getColor())
                         && Objects.equals(this.getFamily(), cf.getFamily())
                         && Objects.equals(this.getFontHeight(), cf.getFontHeight())
index 4caf68988ff61cfecf51bace2d6011ef7491a0ac..fcc6171b4a04af220e66a96bc1618c92ef2caea7 100644 (file)
@@ -79,6 +79,7 @@ import java.io.OutputStream;
 import java.io.PushbackInputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -86,7 +87,6 @@ import java.util.List;
 import java.util.TreeMap;
 import java.util.function.BiConsumer;
 import java.util.regex.Pattern;
-import java.util.zip.ZipException;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -113,7 +113,7 @@ public final class TestPackage {
         OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE);
                try {
                p.save(targetFile.getAbsoluteFile());
-    
+
                // Compare the original and newly saved document
                assertTrue(targetFile.exists());
                ZipFileAssert.assertEquals(new File(originalFile), targetFile);
@@ -160,7 +160,7 @@ public final class TestPackage {
                                                PackagingURIHelper.createPartName("/foo.txt")
                                )
                );
-               
+
                pkg.revert();
        }
 
@@ -229,7 +229,7 @@ public final class TestPackage {
         PackagePart corePart = pkg.createPart(corePartName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
         // Put in some dummy content
         OutputStream coreOut = corePart.getOutputStream();
-        coreOut.write("<dummy-xml />".getBytes("UTF-8"));
+        coreOut.write("<dummy-xml />".getBytes(StandardCharsets.UTF_8));
         coreOut.close();
 
                // And another bit
@@ -243,7 +243,7 @@ public final class TestPackage {
 
         // Dummy content again
         coreOut = corePart.getOutputStream();
-        coreOut.write("<dummy-xml2 />".getBytes("UTF-8"));
+        coreOut.write("<dummy-xml2 />".getBytes(StandardCharsets.UTF_8));
         coreOut.close();
 
         //add a relationship with internal target: "#Sheet1!A1"
@@ -280,13 +280,13 @@ public final class TestPackage {
             assertEquals("/xl/workbook.xml", coreRel.getTargetURI().toString());
             corePart = pkg.getPart(coreRel);
             assertNotNull(corePart);
-    
+
             PackageRelationshipCollection rels = corePart.getRelationshipsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink");
             assertEquals(1, rels.size());
             rel = rels.getRelationship(0);
                        assertNotNull(rel);
             assertEquals("Sheet1!A1", rel.getTargetURI().getRawFragment());
-    
+
             assertMSCompatibility(pkg);
         } finally {
             pkg.close();
@@ -384,7 +384,7 @@ public final class TestPackage {
                        try (FileOutputStream fout = new FileOutputStream(targetFile)) {
                                p.save(fout);
                        }
-    
+
                // Compare the original and newly saved document
                assertTrue(targetFile.exists());
                ZipFileAssert.assertEquals(new File(originalFile), targetFile);
@@ -404,28 +404,29 @@ public final class TestPackage {
        public void openFromInputStream() throws IOException, InvalidFormatException {
                String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
 
-               FileInputStream finp = new FileInputStream(originalFile);
+               try (FileInputStream finp = new FileInputStream(originalFile)) {
+                       @SuppressWarnings("resource")
+                       OPCPackage p = OPCPackage.open(finp);
 
-               @SuppressWarnings("resource")
-        OPCPackage p = OPCPackage.open(finp);
-
-               assertNotNull(p);
-               assertNotNull(p.getRelationships());
-               assertEquals(12, p.getParts().size());
+                       try {
+                               assertNotNull(p);
+                               assertNotNull(p.getRelationships());
+                               assertEquals(12, p.getParts().size());
 
-               // Check it has the usual bits
-               assertTrue(p.hasRelationships());
-               assertTrue(p.containPart(PackagingURIHelper.createPartName("/_rels/.rels")));
-               
-               p.revert();
-               finp.close();
+                               // Check it has the usual bits
+                               assertTrue(p.hasRelationships());
+                               assertTrue(p.containPart(PackagingURIHelper.createPartName("/_rels/.rels")));
+                       } finally {
+                               p.revert();
+                       }
+               }
        }
 
     /**
      * TODO: fix and enable
      */
     @Test
-    @Ignore
+       @Ignore
     public void removePartRecursive() throws IOException, InvalidFormatException, URISyntaxException {
                String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
                File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx");
@@ -433,16 +434,18 @@ public final class TestPackage {
 
                @SuppressWarnings("resource")
         OPCPackage p = OPCPackage.open(originalFile, PackageAccess.READ_WRITE);
-               p.removePartRecursive(PackagingURIHelper.createPartName(new URI(
-                               "/word/document.xml")));
-               p.save(tempFile.getAbsoluteFile());
+               try {
+                       p.removePartRecursive(PackagingURIHelper.createPartName(new URI(
+                                       "/word/document.xml")));
+                       p.save(tempFile.getAbsoluteFile());
 
-               // Compare the original and newly saved document
-               assertTrue(targetFile.exists());
-               ZipFileAssert.assertEquals(targetFile, tempFile);
-               assertTrue(targetFile.delete());
-               
-               p.revert();
+                       // Compare the original and newly saved document
+                       assertTrue(targetFile.exists());
+                       ZipFileAssert.assertEquals(targetFile, tempFile);
+                       assertTrue(targetFile.delete());
+               } finally {
+                       p.revert();
+               }
        }
 
     @Test
@@ -543,7 +546,7 @@ public final class TestPackage {
                // Don't save modifications
                p.revert();
        }
-       
+
        /**
         * Test that we can open a file by path, and then
         *  write changes to it.
@@ -553,18 +556,18 @@ public final class TestPackage {
         File tempFile = TempFile.createTempFile("poiTesting","tmp");
         File origFile = OpenXML4JTestDataSamples.getSampleFile("TestPackageCommon.docx");
         FileHelper.copyFile(origFile, tempFile);
-        
+
         // Open the temp file
         OPCPackage p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE);
         // Close it
         p.close();
         // Delete it
         assertTrue(tempFile.delete());
-        
+
         // Reset
         FileHelper.copyFile(origFile, tempFile);
         p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE);
-        
+
         // Save it to the same file - not allowed
         try {
             p.save(tempFile);
@@ -576,14 +579,15 @@ public final class TestPackage {
         p.close();
         // Delete it
         assertTrue(tempFile.delete());
-        
-        
+
+
         // Open it read only, then close and delete - allowed
         FileHelper.copyFile(origFile, tempFile);
         p = OPCPackage.open(tempFile.toString(), PackageAccess.READ);
         p.close();
         assertTrue(tempFile.delete());
        }
+
     /**
      * Test that we can open a file by path, save it
      *  to another file, then delete both
@@ -594,14 +598,13 @@ public final class TestPackage {
         File tempFile2 = TempFile.createTempFile("poiTesting","tmp");
         File origFile = OpenXML4JTestDataSamples.getSampleFile("TestPackageCommon.docx");
         FileHelper.copyFile(origFile, tempFile);
-        
+
         // Open the temp file
-        OPCPackage p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE);
+               try (OPCPackage p = OPCPackage.open(tempFile.toString(), PackageAccess.READ_WRITE)) {
+                       // Save it to a different file
+                       p.save(tempFile2);
+               }
 
-        // Save it to a different file
-        p.save(tempFile2);
-        p.close();
-        
         // Delete both the files
         assertTrue(tempFile.delete());
         assertTrue(tempFile2.delete());
@@ -620,10 +623,10 @@ public final class TestPackage {
         try {
             List<PackagePart> rs =  pkg.getPartsByName(Pattern.compile("/word/.*?\\.xml"));
             HashMap<String, PackagePart>  selected = new HashMap<>();
-    
+
             for(PackagePart p : rs)
                 selected.put(p.getPartName().getName(), p);
-    
+
             assertEquals(6, selected.size());
             assertTrue(selected.containsKey("/word/document.xml"));
             assertTrue(selected.containsKey("/word/fontTable.xml"));
@@ -636,7 +639,7 @@ public final class TestPackage {
             pkg.revert();
         }
     }
-    
+
     @Test
     public void getPartSize() throws IOException, InvalidFormatException {
        String filepath =  OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
@@ -690,7 +693,7 @@ public final class TestPackage {
         p.revert();
         is.close();
     }
-    
+
     /**
      * Verify we give helpful exceptions (or as best we can) when
      *  supplied with non-OOXML file types (eg OLE2, ODF)
@@ -699,7 +702,7 @@ public final class TestPackage {
     public void NonOOXMLFileTypes() throws Exception {
         // Spreadsheet has a good mix of alternate file types
         POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
-        
+
         // OLE2 - Stream
         try {
                        try (InputStream stream = files.openResourceAsStream("SampleSS.xls")) {
@@ -718,7 +721,7 @@ public final class TestPackage {
             assertTrue(e.getMessage().contains("The supplied data appears to be in the OLE2 Format"));
             assertTrue(e.getMessage().contains("You are calling the part of POI that deals with OOXML"));
         }
-        
+
         // Raw XML - Stream
         try {
                        try (InputStream stream = files.openResourceAsStream("SampleSS.xml")) {
@@ -737,7 +740,7 @@ public final class TestPackage {
             assertTrue(e.getMessage().contains("The supplied data appears to be a raw XML file"));
             assertTrue(e.getMessage().contains("Formats such as Office 2003 XML"));
         }
-        
+
         // ODF / ODS - Stream
         try {
                        try (InputStream stream = files.openResourceAsStream("SampleSS.ods")) {
@@ -756,7 +759,7 @@ public final class TestPackage {
             assertTrue(e.toString().contains("The supplied data appears to be in ODF"));
             assertTrue(e.toString().contains("Formats like these (eg ODS"));
         }
-        
+
         // Plain Text - Stream
         try {
                        try (InputStream stream = files.openResourceAsStream("SampleSS.txt")) {
@@ -814,7 +817,7 @@ public final class TestPackage {
                                                                append.write(spam);
                                                                size += spam.length;
                                                        }
-                                                       append.write("</Types>".getBytes("UTF-8"));
+                                                       append.write("</Types>".getBytes(StandardCharsets.UTF_8));
                                                        size += 8;
                                                        eOut.setSize(size);
                                                } else {
@@ -969,7 +972,7 @@ public final class TestPackage {
             ZipSecureFile.setMaxTextSize(before);
         }
     }
-    
+
     // bug 60128
     @Test(expected=NotOfficeXmlFileException.class)
     public void testCorruptFile() throws InvalidFormatException {
@@ -989,7 +992,7 @@ public final class TestPackage {
                 new PushbackInputStream(new FileInputStream(hssf), 2),
                 new BufferedInputStream(new FileInputStream(hssf), 2),
         };
-        
+
         try {
             for (InputStream is : isList) {
                 WorkbookFactory.create(is).close();
@@ -1099,9 +1102,10 @@ public final class TestPackage {
        public void testBug62592SequentialCallsToGetParts() throws Exception {
                //make absolutely certain that sequential calls don't throw InvalidFormatExceptions
                String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
-               OPCPackage p2 = OPCPackage.open(originalFile, PackageAccess.READ);
-               p2.getParts();
-               p2.getParts();
+               try (OPCPackage p2 = OPCPackage.open(originalFile, PackageAccess.READ)) {
+                       p2.getParts();
+                       p2.getParts();
+               }
        }
 
        @Test
@@ -1189,6 +1193,7 @@ public final class TestPackage {
                }
        }
 
+       @SuppressWarnings("UnstableApiUsage")
        @Test
        public void testBug63029() throws Exception {
                File testFile = OpenXML4JTestDataSamples.getSampleFile("sample.docx");
@@ -1212,6 +1217,7 @@ public final class TestPackage {
                        ex = e;
                }
                // verify there was an exception while closing the file
+               assertNotNull("Fail to save: an error occurs while saving the package : Bugzilla 63029", ex);
                assertEquals("Fail to save: an error occurs while saving the package : Bugzilla 63029", ex.getMessage());
 
                // assert that md5 after closing is the same, i.e. the source is left intact
index 713b2f2b84329130876bee9f6cb398910a962fd3..10757fbe021d72e82dfdf2edb82b30fbba7b3c5a 100644 (file)
@@ -49,8 +49,6 @@ public class TestPPTX2PNG {
         "backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt, keyframes.pptx," +
         "customGeo.pptx, customGeo.ppt, wrench.emf, santa.wmf";
 
-
-
     @BeforeClass
     public static void checkHslf() {
         try {
@@ -61,7 +59,7 @@ public class TestPPTX2PNG {
     }
 
     // use filename instead of File object to omit full pathname in test name
-    @Parameter(value = 0)
+    @Parameter
     public String pptFile;
 
     @SuppressWarnings("ConstantConditions")
index 0963a27798d3419f22e02ed72dbad336447a99a2..9f140064664c6ede7b4b95c6b5557a05771c0a0b 100644 (file)
@@ -234,12 +234,13 @@ public final class TestSharedStringsTable {
 
         Path path = XSSFTestDataSamples.getSampleFile("48936-strings.txt").toPath();
 
-        Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8);
-        List<String> lst = lines
-            .map(String::trim)
-            .filter(((Predicate<String>)String::isEmpty).negate())
-            .collect(Collectors.toList());
-        lines.close();
+        final List<String> lst;
+        try (Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8)) {
+            lst = lines
+                    .map(String::trim)
+                    .filter(((Predicate<String>) String::isEmpty).negate())
+                    .collect(Collectors.toList());
+        }
 
         for (String str : lst) {
             s.createRow(i++).createCell(0).setCellValue(str);
index 65eaa7f1735434f236908e9448059cced3c5df5f..bc97bfa2d56b9d22796b5d806e0561a02067ce15 100644 (file)
@@ -1919,29 +1919,31 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
     @Test
     public void test54764WithSAXHelper() throws Exception {
         File testFile = XSSFTestDataSamples.getSampleFile("54764.xlsx");
-        ZipFile zip = new ZipFile(testFile);
-        ZipArchiveEntry ze = zip.getEntry("xl/sharedStrings.xml");
-        XMLReader reader = XMLHelper.newXMLReader();
-        try {
-            reader.parse(new InputSource(zip.getInputStream(ze)));
-            fail("should have thrown SAXParseException");
-        } catch (SAXParseException e) {
-            assertNotNull(e.getMessage());
-            assertTrue(e.getMessage().contains("more than \"1\" entity"));
+        try (ZipFile zip = new ZipFile(testFile)) {
+            ZipArchiveEntry ze = zip.getEntry("xl/sharedStrings.xml");
+            XMLReader reader = XMLHelper.newXMLReader();
+            try {
+                reader.parse(new InputSource(zip.getInputStream(ze)));
+                fail("should have thrown SAXParseException");
+            } catch (SAXParseException e) {
+                assertNotNull(e.getMessage());
+                assertTrue(e.getMessage().contains("more than \"1\" entity"));
+            }
         }
     }
 
     @Test
     public void test54764WithDocumentHelper() throws Exception {
         File testFile = XSSFTestDataSamples.getSampleFile("54764.xlsx");
-        ZipFile zip = new ZipFile(testFile);
-        ZipArchiveEntry ze = zip.getEntry("xl/sharedStrings.xml");
-        try {
-            DocumentHelper.readDocument(zip.getInputStream(ze));
-            fail("should have thrown SAXParseException");
-        } catch (SAXParseException e) {
-            assertNotNull(e.getMessage());
-            assertNotEquals(isOldXercesActive(), e.getMessage().contains("DOCTYPE is disallowed when the feature"));
+        try (ZipFile zip = new ZipFile(testFile)) {
+            ZipArchiveEntry ze = zip.getEntry("xl/sharedStrings.xml");
+            try {
+                DocumentHelper.readDocument(zip.getInputStream(ze));
+                fail("should have thrown SAXParseException");
+            } catch (SAXParseException e) {
+                assertNotNull(e.getMessage());
+                assertNotEquals(isOldXercesActive(), e.getMessage().contains("DOCTYPE is disallowed when the feature"));
+            }
         }
     }
 
index 7186034e4b457e45a3ebd936e7bc241716d3cdf8..8547b295113ce7afa01c0ab6b300697978919cdb 100644 (file)
@@ -103,7 +103,7 @@ public final class TestXSSFFont extends BaseTestFont{
         assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
         xssfFont.setCharSet((byte)(FontCharset.ARABIC.getValue()));
         assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
-        
+
         // This one isn't allowed
         assertNull(FontCharset.valueOf(9999));
         try {
@@ -112,20 +112,20 @@ public final class TestXSSFFont extends BaseTestFont{
         } catch(POIXMLException e) {
                // expected here
                }
-      
-               
+
+
                // Now try with a few sample files
-               
+
                // Normal charset
         XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
-        assertEquals(0, 
+        assertEquals(0,
               wb1.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
         );
         wb1.close();
-               
+
                // GB2312 charset
         XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx");
-        assertEquals(134, 
+        assertEquals(134,
               wb2.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
         );
         wb2.close();
@@ -253,13 +253,13 @@ public final class TestXSSFFont extends BaseTestFont{
                assertEquals(ctFont.getColorArray(0).getRgb()[3],xssfFont.getXSSFColor().getRGB()[3]);
 
                xssfFont.setColor((short)23);
-               
+
                byte[] bytes = Integer.toHexString(0xF1F1F1).getBytes(LocaleUtil.CHARSET_1252);
         color.setRgb(bytes);
                XSSFColor newColor=XSSFColor.from(color, null);
                xssfFont.setColor(newColor);
                assertEquals(ctFont.getColorArray(0).getRgb()[2],newColor.getRGB()[2]);
-               
+
                assertArrayEquals(bytes, xssfFont.getXSSFColor().getRGB());
                assertEquals(0, xssfFont.getColor());
        }
@@ -325,16 +325,16 @@ public final class TestXSSFFont extends BaseTestFont{
         // cannot check on result because on some machines we get back false here!
         SheetUtil.canComputeColumnWidth(wb.getFontAt(0));
 
-        wb.close();        
+        wb.close();
     }
 
     // store test from TestSheetUtil here as it uses XSSF
        @Test
-       public void testCanComputeWidthInvalidFont() throws IOException {
+       public void testCanComputeWidthInvalidFont() {
         Font font = new XSSFFont(CTFont.Factory.newInstance());
         font.setFontName("some non existing font name");
-        
-        // Even with invalid fonts we still get back useful data most of the time... 
+
+        // Even with invalid fonts we still get back useful data most of the time...
         SheetUtil.canComputeColumnWidth(font);
     }
 
@@ -439,4 +439,19 @@ public final class TestXSSFFont extends BaseTestFont{
 
                wb.close();
        }
+
+       @Test
+       public void testEquals() {
+               XSSFFont font = new XSSFFont();
+               XSSFFont equ = new XSSFFont();
+               XSSFFont notequ = new XSSFFont();
+               notequ.setItalic(true);
+
+               assertEquals(equ, font);
+               assertNotEquals(font, notequ);
+
+               notequ.setItalic(false);
+               notequ.setThemeColor((short)123);
+               assertNotEquals(font, notequ);
+       }
 }
index ed87177882d9f501c6cc80c0dd33c20cce7428f1..b9ae90f0afa60cb71e6bc4683ca40a1e5cf5559d 100644 (file)
@@ -25,7 +25,6 @@ import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Dimension2D;
 import java.awt.geom.Rectangle2D;
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -57,11 +56,11 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
     private final List<HemfRecord> records = new ArrayList<>();
     private boolean isParsed = false;
 
-    public HemfPicture(InputStream is) throws IOException {
+    public HemfPicture(InputStream is) {
         this(new LittleEndianInputStream(is));
     }
 
-    public HemfPicture(LittleEndianInputStream is) throws IOException {
+    public HemfPicture(LittleEndianInputStream is) {
         stream = is;
     }
 
@@ -175,13 +174,11 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
             prop.setViewportOrg(emfBounds.getX(), emfBounds.getY());
             prop.setViewportExt(emfBounds.getWidth(), emfBounds.getHeight());
 
-            int idx = 0;
             for (HemfRecord r : getRecords()) {
                 try {
                     g.draw(r);
                 } catch (RuntimeException ignored) {
                 }
-                idx++;
             }
         } finally {
             ctx.setTransform(at);
index 37912523a4df95028241c79fe49057b1770bab04..0dff34f567f8868a50772d911f7cb319e908ddfa 100644 (file)
@@ -59,6 +59,10 @@ public class OutlookTextExtractor extends POIOLE2TextExtractor {
     }
 
     public static void main(String[] args) throws Exception {
+        if(args.length == 0) {
+            System.err.println("Usage: OutlookTextExtractor <file> [<file> ...]");
+            System.exit(1);
+        }
         for (String filename : args) {
             try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename));
                  OutlookTextExtractor extractor = new OutlookTextExtractor(poifs)) {
index 637c629070606f2574eb77b4a8a144d93e547c1c..7abe46e8ecf47f1a735d14e9d133eb5ec3567ed3 100644 (file)
@@ -94,7 +94,7 @@ public final class CharacterSprmCompressor
 
        size += SprmUtils.addSprm((short)0x6a09, 0, varParam, sprmList);
     }
-    if (newCHP.isFOle2() != newCHP.isFOle2())
+    if (newCHP.isFOle2() != oldCHP.isFOle2())
     {
       int value = 0;
       if (newCHP.isFOle2())