diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java index d27bd37666..0ca6e685df 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java @@ -194,7 +194,7 @@ public class ReadOnlySharedStringsTable extends DefaultHandler implements Shared sheetParser.setContentHandler(this); sheetParser.parse(sheetSource); } catch(ParserConfigurationException e) { - throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage()); + throw new SAXException("SAX parser appears to be broken - " + e.getMessage()); } } } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java index 6b814589e4..992dc32113 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java @@ -22,6 +22,7 @@ package org.apache.poi.xssf.eventusermodel; import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; +import java.io.InputStream; import java.util.List; import java.util.regex.Pattern; @@ -48,16 +49,22 @@ public final class TestReadOnlySharedStringsTable { SharedStringsTable stbl = new SharedStringsTable(parts.get(0)); ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0)); + ReadOnlySharedStringsTable rtbl2; + try (InputStream stream = parts.get(0).getInputStream()){ + rtbl2 = new ReadOnlySharedStringsTable(stream); + } assertEquals(stbl.getCount(), rtbl.getCount()); assertEquals(stbl.getUniqueCount(), rtbl.getUniqueCount()); + assertEquals(stbl.getUniqueCount(), rtbl2.getUniqueCount()); assertEquals(stbl.getCount(), stbl.getUniqueCount()); assertEquals(rtbl.getCount(), rtbl.getUniqueCount()); + assertEquals(rtbl.getCount(), rtbl2.getUniqueCount()); for (int i = 0; i < stbl.getUniqueCount(); i++) { RichTextString i1 = stbl.getItemAt(i); - RichTextString i2 = rtbl.getItemAt(i); - assertEquals(i1.getString(), i2.getString()); + assertEquals(i1.getString(), rtbl.getItemAt(i).getString()); + assertEquals(i1.getString(), rtbl2.getItemAt(i).getString()); } } } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/model/TestThemesTable.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/model/TestThemesTable.java index b50d691185..225d3f3f67 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/model/TestThemesTable.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/model/TestThemesTable.java @@ -17,33 +17,26 @@ package org.apache.poi.xssf.model; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.util.LinkedHashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import org.apache.commons.codec.binary.Hex; +import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.model.ThemesTable.ThemeElement; -import org.apache.poi.xssf.usermodel.XSSFCell; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFColor; -import org.apache.poi.xssf.usermodel.XSSFFont; -import org.apache.poi.xssf.usermodel.XSSFRow; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xssf.usermodel.*; import org.junit.jupiter.api.Test; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; +import static org.junit.jupiter.api.Assertions.*; + class TestThemesTable { private static final String testFileComplex = "Themes2.xlsx"; // TODO .xls version available too, add HSSF support then check @@ -165,6 +158,16 @@ class TestThemesTable { void themedAndNonThemedColours() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(testFileComplex)) { XSSFSheet sheet = wb.getSheetAt(0); + ThemesTable themesTable = wb.getTheme(); + XSSFColor color1 = themesTable.getThemeColor(0); + assertNotNull(color1); + assertNotEquals(0, color1.getRGB().length); + List themeParts = wb.getPackage().getPartsByContentType(XSSFRelation.THEME.getContentType()); + assertEquals(1, themeParts.size()); + try (InputStream themeStream = themeParts.get(0).getInputStream()) { + ThemesTable themesTable2 = new ThemesTable(themeStream); + assertArrayEquals(color1.getRGB(), themesTable2.getThemeColor(0).getRGB()); + } String[] names = {"White", "Black", "Grey", "Dark Blue", "Blue", "Red", "Green"}; String[] explicitFHexes = {"FFFFFFFF", "FF000000", "FFC0C0C0", "FF002060",