Author: nick
Date: Mon Aug  4 20:42:41 2014
New Revision: 1615781

URL: http://svn.apache.org/r1615781
Log:
Before parsing an OOXML document, reset the xmlbeans sax parser to avoid the 
risk of getting one in an error state (due to XMLBEANS-512). Should be a 
minimal extra overhead pending a proper fix. Allows us to finish enabling the 
unit tests for #54764

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
    
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=1615781&r1=1615780&r2=1615781&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java Mon Aug  4 
20:42:41 2014
@@ -35,6 +35,7 @@ import org.apache.poi.openxml4j.opc.Pack
 import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.IOUtils;
+import org.apache.xmlbeans.impl.common.SystemCache;
 
 public abstract class POIXMLDocument extends POIXMLDocumentPart{
     public static final String DOCUMENT_CREATOR = "Apache POI";
@@ -56,6 +57,11 @@ public abstract class POIXMLDocument ext
     protected POIXMLDocument(OPCPackage pkg) {
         super(pkg);
         this.pkg = pkg;
+        
+        // Workaround for XMLBEANS-512 - ensure that when we parse
+        //  the file, we start with a fresh XML Parser each time,
+        //  and avoid the risk of getting a SaxHandler that's in error
+        SystemCache.get().setSaxLoader(null);
     }
 
     /**

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java?rev=1615781&r1=1615780&r2=1615781&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java 
Mon Aug  4 20:42:41 2014
@@ -20,16 +20,20 @@ package org.apache.poi.xssf.model;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
-import org.apache.poi.POIXMLDocumentPart;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
 
 
 /**

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1615781&r1=1615780&r2=1615781&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java 
(original)
+++ 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java 
Mon Aug  4 20:42:41 2014
@@ -38,6 +38,7 @@ import java.util.List;
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.POIXMLException;
 import org.apache.poi.POIXMLProperties;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -1859,14 +1860,12 @@ public final class TestXSSFBugs extends 
         assertEquals(null, props.getCoreProperties().getDescription());
         
         // Now check the spreadsheet itself
-        // TODO Fix then enable
-/*        
         try {
             new XSSFWorkbook(pkg);
             fail("Should fail as too much expansion occurs");
         } catch(POIXMLException e) {
             // Expected
-        } */
+        }
         
         // Try with one with the entities in the Content Types
         try {
@@ -1875,6 +1874,10 @@ public final class TestXSSFBugs extends 
         } catch(Exception e) {
             // Expected
         }
+        
+        // Check we can still parse valid files after all that
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
+        assertEquals(3, wb.getNumberOfSheets());
     }
     
     /**



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

Reply via email to