mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
small refactor of ThemesTable
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896269 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
74b08e5f51
commit
cf1354dc6c
@ -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,14 +82,22 @@ 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.
|
||||
@ -97,6 +106,21 @@ public class ThemesTable extends POIXMLDocumentPart implements Themes {
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user