summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-12-22 09:16:53 +0000
committerPJ Fanning <fanningpj@apache.org>2021-12-22 09:16:53 +0000
commitcf1354dc6c6128d8fd024ee1f57359761cd5fd1f (patch)
tree01271a3ece4f3b266c24f45346f8d8dbdeb40290
parent74b08e5f5147ffeb11ace78ef47566cae0609df0 (diff)
downloadpoi-cf1354dc6c6128d8fd024ee1f57359761cd5fd1f.tar.gz
poi-cf1354dc6c6128d8fd024ee1f57359761cd5fd1f.zip
small refactor of ThemesTable
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896269 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java36
1 files changed, 30 insertions, 6 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java
index 28d5a0633e..72fe4e0107 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.model;
import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.ooxml.POIXMLDocumentPart;
@@ -62,7 +63,7 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes {
}
private IndexedColorMap colorMap;
- private final ThemeDocument theme;
+ private ThemeDocument theme;
/**
* Create a new, empty ThemesTable
@@ -81,15 +82,23 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes {
*/
public ThemesTable(PackagePart part) throws IOException {
super(part);
-
- try {
- theme = ThemeDocument.Factory.parse(part.getInputStream(), DEFAULT_XML_OPTIONS);
- } catch(XmlException e) {
- throw new IOException(e.getLocalizedMessage(), e);
+ try (InputStream stream = part.getInputStream()) {
+ readFrom(stream);
}
}
/**
+ * Construct a ThemesTable.
+ * @param stream input stream.
+ *
+ * @since POI 5.2.0
+ */
+ public ThemesTable(InputStream stream) throws IOException {
+ super();
+ readFrom(stream);
+ }
+
+ /**
* Construct a ThemesTable from an existing ThemeDocument.
* @param theme A ThemeDocument.
*/
@@ -98,6 +107,21 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes {
}
/**
+ * Read this themes table from an XML file.
+ *
+ * @param is The input stream containing the XML document.
+ * @throws IOException if an error occurs while reading.
+ * @since POI 5.2.0
+ */
+ public void readFrom(InputStream is) throws IOException {
+ try {
+ theme = ThemeDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
+ } catch(XmlException e) {
+ throw new IOException(e.getLocalizedMessage(), e);
+ }
+ }
+
+ /**
* called from {@link StylesTable} when setting theme, used to adjust colors if a custom indexed mapping is defined
*/
protected void setColorMap(IndexedColorMap colorMap) {