소스 검색

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
tags/REL_3_11_BETA2
Nick Burch 10 년 전
부모
커밋
22aec7b4e3

+ 6
- 0
src/ooxml/java/org/apache/poi/POIXMLDocument.java 파일 보기

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";
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);
} }


/** /**

+ 8
- 4
src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java 파일 보기

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;




/** /**

+ 6
- 3
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java 파일 보기

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;
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 {
} 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…
취소
저장