You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/02/13 19:43:08 UTC
svn commit: r1886493 - in /poi/trunk/src/ooxml:
java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
Author: fanningpj
Date: Sat Feb 13 19:43:07 2021
New Revision: 1886493
URL: http://svn.apache.org/viewvc?rev=1886493&view=rev
Log:
allo XSSFReader to be sublclassed with implementation that allows OOXMl Strict files
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java?rev=1886493&r1=1886492&r2=1886493&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java Sat Feb 13 19:43:07 2021
@@ -82,6 +82,16 @@ public class XSSFReader {
* Creates a new XSSFReader, for the given package
*/
public XSSFReader(OPCPackage pkg) throws IOException, OpenXML4JException {
+ this(pkg, false);
+ }
+
+ /**
+ * Creates a new XSSFReader, for the given package
+ *
+ * @param pkg an <code>OPCPackage</code> representing a spreasheet file
+ * @param allowStrictOoxmlFiles whether to try to handle Strict OOXML format files
+ */
+ public XSSFReader(OPCPackage pkg, boolean allowStrictOoxmlFiles) throws IOException, OpenXML4JException {
this.pkg = pkg;
PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
@@ -91,19 +101,23 @@ public class XSSFReader {
// this code is similar to POIXMLDocumentPart.getPartFromOPCPackage(), but I could not combine it
// easily due to different return values
if (coreDocRelationship == null) {
- if (this.pkg.getRelationshipsByType(
+ if (allowStrictOoxmlFiles) {
+ coreDocRelationship = this.pkg.getRelationshipsByType(
+ PackageRelationshipTypes.STRICT_CORE_DOCUMENT).getRelationship(0);
+ } else if (this.pkg.getRelationshipsByType(
PackageRelationshipTypes.STRICT_CORE_DOCUMENT).getRelationship(0) != null) {
throw new POIXMLException("Strict OOXML isn't currently supported, please see bug #57699");
}
- throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
+ if (coreDocRelationship == null) {
+ throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
+ }
}
// Get the part that holds the workbook
workbookPart = this.pkg.getPart(coreDocRelationship);
}
-
/**
* Opens up the Shared Strings Table, parses it, and
* returns a handy object for working with
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java?rev=1886493&r1=1886492&r2=1886493&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/eventusermodel/TestXSSFReader.java Sat Feb 13 19:43:07 2021
@@ -334,6 +334,28 @@ public final class TestXSSFReader {
}
}
+ @Test
+ void testStrictOoxmlNotAllowed() throws Exception {
+ assertThrows(POIXMLException.class, () -> {
+ try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) {
+ XSSFReader reader = new XSSFReader(pkg);
+ }
+ });
+ assertThrows(POIXMLException.class, () -> {
+ try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) {
+ XSSFReader reader = new XSSFReader(pkg, false);
+ }
+ });
+ }
+
+ @Test
+ void testStrictOoxmlAllowed() throws Exception {
+ try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("sample.strict.xlsx"))) {
+ XSSFReader reader = new XSSFReader(pkg, true);
+ assertNotNull(reader.pkg);
+ }
+ }
+
private static String hash(XSSFReader reader) throws IOException {
Iterable<InputStream> iter = () -> {
try {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org