summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-12-22 04:00:44 +0000
committerPJ Fanning <fanningpj@apache.org>2021-12-22 04:00:44 +0000
commit74b08e5f5147ffeb11ace78ef47566cae0609df0 (patch)
tree6194d078db14f248786ab0fdfc5371222088038d
parentfe4a3b7596cae53b3cd69885c58ccce20b491b4e (diff)
downloadpoi-74b08e5f5147ffeb11ace78ef47566cae0609df0.tar.gz
poi-74b08e5f5147ffeb11ace78ef47566cae0609df0.zip
small refactor of XSSFReader
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896260 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
index bc1bad8abf..fa834e1c76 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
@@ -74,6 +74,7 @@ public class XSSFReader {
protected OPCPackage pkg;
protected PackagePart workbookPart;
+ protected boolean useReadOnlySharedStringsTable;
/**
* Creates a new XSSFReader, for the given package
@@ -116,13 +117,39 @@ public class XSSFReader {
}
/**
+ * Controls whether {@link #getSharedStringsTable()} uses {@link SharedStringsTable}
+ * or {@link ReadOnlySharedStringsTable}.
+ * @param useReadOnlySharedStringsTable
+ * @since POI 5.2.0
+ */
+ public void setUseReadOnlySharedStringsTable(boolean useReadOnlySharedStringsTable) {
+ this.useReadOnlySharedStringsTable = useReadOnlySharedStringsTable;
+ }
+
+ /**
+ * @return whether {@link #getSharedStringsTable()} uses {@link SharedStringsTable}
+ * or {@link ReadOnlySharedStringsTable}.
+ * @since POI 5.2.0
+ */
+ public boolean useReadOnlySharedStringsTable(boolean useReadOnlySharedStringsTable) {
+ return useReadOnlySharedStringsTable;
+ }
+
+ /**
* Opens up the Shared Strings Table, parses it, and
* returns a handy object for working with
* shared strings.
+ * @see #setUseReadOnlySharedStringsTable(boolean)
*/
public SharedStrings getSharedStringsTable() throws IOException, InvalidFormatException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());
- return parts.size() == 0 ? null : new SharedStringsTable(parts.get(0));
+ try {
+ return parts.size() == 0 ? null :
+ useReadOnlySharedStringsTable ? new ReadOnlySharedStringsTable(parts.get(0)) :
+ new SharedStringsTable(parts.get(0));
+ } catch (SAXException se) {
+ throw new InvalidFormatException("Failed to parse SharedStringsTable", se);
+ }
}
/**