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
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1615781 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b6c30fae87
commit
b350d5c5ed
@ -35,6 +35,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationship;
|
|||||||
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.apache.xmlbeans.impl.common.SystemCache;
|
||||||
|
|
||||||
public abstract class POIXMLDocument extends POIXMLDocumentPart{
|
public abstract class POIXMLDocument extends POIXMLDocumentPart{
|
||||||
public static final String DOCUMENT_CREATOR = "Apache POI";
|
public static final String DOCUMENT_CREATOR = "Apache POI";
|
||||||
@ -56,6 +57,11 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
|
|||||||
protected POIXMLDocument(OPCPackage pkg) {
|
protected POIXMLDocument(OPCPackage pkg) {
|
||||||
super(pkg);
|
super(pkg);
|
||||||
this.pkg = 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,16 +20,20 @@ package org.apache.poi.xssf.model;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
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.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
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.CTRst;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,6 +38,7 @@ import java.util.List;
|
|||||||
import org.apache.poi.EncryptedDocumentException;
|
import org.apache.poi.EncryptedDocumentException;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
|
import org.apache.poi.POIXMLException;
|
||||||
import org.apache.poi.POIXMLProperties;
|
import org.apache.poi.POIXMLProperties;
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
@ -1859,14 +1860,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
assertEquals(null, props.getCoreProperties().getDescription());
|
assertEquals(null, props.getCoreProperties().getDescription());
|
||||||
|
|
||||||
// Now check the spreadsheet itself
|
// Now check the spreadsheet itself
|
||||||
// TODO Fix then enable
|
|
||||||
/*
|
|
||||||
try {
|
try {
|
||||||
new XSSFWorkbook(pkg);
|
new XSSFWorkbook(pkg);
|
||||||
fail("Should fail as too much expansion occurs");
|
fail("Should fail as too much expansion occurs");
|
||||||
} catch(POIXMLException e) {
|
} catch(POIXMLException e) {
|
||||||
// Expected
|
// Expected
|
||||||
} */
|
}
|
||||||
|
|
||||||
// Try with one with the entities in the Content Types
|
// Try with one with the entities in the Content Types
|
||||||
try {
|
try {
|
||||||
@ -1875,6 +1874,10 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check we can still parse valid files after all that
|
||||||
|
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
|
||||||
|
assertEquals(3, wb.getNumberOfSheets());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user