From 31eb7f9b06f41e0fe9032ccb772c6e91655a4af5 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 27 Jan 2020 22:54:03 +0000 Subject: [PATCH] Fix some IDE warnings, Sonar fixes and some missing closing of resources in unit-tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1873231 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xddf/usermodel/chart/XDDFChart.java | 55 +++----- .../apache/poi/xssf/usermodel/XSSFFont.java | 8 +- .../apache/poi/openxml4j/opc/TestPackage.java | 120 +++++++++--------- .../poi/xslf/usermodel/TestPPTX2PNG.java | 4 +- .../xssf/model/TestSharedStringsTable.java | 13 +- .../poi/xssf/usermodel/TestXSSFBugs.java | 36 +++--- .../poi/xssf/usermodel/TestXSSFFont.java | 41 ++++-- .../poi/hemf/usermodel/HemfPicture.java | 7 +- .../hsmf/extractor/OutlookTextExtractor.java | 4 + .../hwpf/sprm/CharacterSprmCompressor.java | 2 +- 10 files changed, 148 insertions(+), 142 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java index 0b662e42f2..77dbbceeba 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java @@ -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); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java index 6deafc4bec..77ac1e2286 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java @@ -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()) diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java index 4caf68988f..fcc6171b4a 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java @@ -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("".getBytes("UTF-8")); + coreOut.write("".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("".getBytes("UTF-8")); + coreOut.write("".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 rs = pkg.getPartsByName(Pattern.compile("/word/.*?\\.xml")); HashMap 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("".getBytes("UTF-8")); + append.write("".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 diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java index 713b2f2b84..10757fbe02 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java @@ -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") diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java index 0963a27798..9f14006466 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java @@ -234,12 +234,13 @@ public final class TestSharedStringsTable { Path path = XSSFTestDataSamples.getSampleFile("48936-strings.txt").toPath(); - Stream lines = Files.lines(path, StandardCharsets.UTF_8); - List lst = lines - .map(String::trim) - .filter(((Predicate)String::isEmpty).negate()) - .collect(Collectors.toList()); - lines.close(); + final List lst; + try (Stream lines = Files.lines(path, StandardCharsets.UTF_8)) { + lst = lines + .map(String::trim) + .filter(((Predicate) String::isEmpty).negate()) + .collect(Collectors.toList()); + } for (String str : lst) { s.createRow(i++).createCell(0).setCellValue(str); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 65eaa7f173..bc97bfa2d5 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -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")); + } } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java index 7186034e4b..8547b29511 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java @@ -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); + } } diff --git a/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java b/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java index ed87177882..b9ae90f0af 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java +++ b/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfPicture.java @@ -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, GenericRecord { private final List 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, 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); diff --git a/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java b/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java index 37912523a4..0dff34f567 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java @@ -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 [ ...]"); + System.exit(1); + } for (String filename : args) { try (POIFSFileSystem poifs = new POIFSFileSystem(new File(filename)); OutlookTextExtractor extractor = new OutlookTextExtractor(poifs)) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java index 637c629070..7abe46e8ec 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmCompressor.java @@ -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()) -- 2.39.5