Author: fanningpj
Date: Wed Dec 22 09:16:53 2021
New Revision: 1896269

URL: http://svn.apache.org/viewvc?rev=1896269&view=rev
Log:
small refactor of ThemesTable

Modified:
    poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java?rev=1896269&r1=1896268&r2=1896269&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java 
(original)
+++ 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/ThemesTable.java 
Wed Dec 22 09:16:53 2021
@@ -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 POIXMLD
    }
 
     private IndexedColorMap colorMap;
-    private final ThemeDocument theme;
+    private ThemeDocument theme;
 
     /**
      * Create a new, empty ThemesTable
@@ -81,15 +82,23 @@ public class ThemesTable extends POIXMLD
      */
     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 POIXMLD
     }
 
     /**
+     * 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) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to