*/
public POIXMLDocumentPart(OPCPackage pkg) {
PackageRelationship coreRel = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
+ if (coreRel == null) {
+ coreRel = pkg.getRelationshipsByType(PackageRelationshipTypes.STRICT_CORE_DOCUMENT).getRelationship(0);
+ if (coreRel != null) {
+ throw new POIXMLException("Strict OOXML isn't currently supported, please see bug #57699");
+ }
+ }
+ if (coreRel == null) {
+ throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
+ }
this.packagePart = pkg.getPart(coreRel);
this.packageRel = coreRel;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry;
* document, and returns it.
*/
public class ExtractorFactory {
- public static final String CORE_DOCUMENT_REL =
- "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
- public static final String VISIO_DOCUMENT_REL =
- "http://schemas.microsoft.com/visio/2010/relationships/document";
+ public static final String CORE_DOCUMENT_REL = PackageRelationshipTypes.CORE_DOCUMENT;
+ protected static final String VISIO_DOCUMENT_REL = PackageRelationshipTypes.VISIO_CORE_DOCUMENT;
+ protected static final String STRICT_DOCUMENT_REL = PackageRelationshipTypes.STRICT_CORE_DOCUMENT;
/** Should this thread prefer event based over usermodel based extractors? */
pkg.getRelationshipsByType(CORE_DOCUMENT_REL);
// If nothing was found, try some of the other OOXML-based core types
+ if (core.size() == 0) {
+ // Could it be an OOXML-Strict one?
+ core = pkg.getRelationshipsByType(STRICT_DOCUMENT_REL);
+ }
if (core.size() == 0) {
// Could it be a visio one?
PackageRelationshipCollection visio =
throw new IllegalArgumentException("Text extraction not supported for Visio OOXML files");
}
}
+
// Should just be a single core document, complain if not
if (core.size() != 1) {
throw new IllegalArgumentException("Invalid OOXML Package received - expected 1 core document, found " + core.size());
import org.apache.poi.POIDataSamples;
import org.apache.poi.POIOLE2TextExtractor;
import org.apache.poi.POITextExtractor;
+import org.apache.poi.POIXMLException;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.hdgf.extractor.VisioTextExtractor;
import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
extractor.close();
// TODO Support OOXML-Strict, see bug #57699
+ try {
+ extractor = ExtractorFactory.createExtractor(xlsxStrict);
+ fail("OOXML-Strict isn't yet supported");
+ } catch (POIXMLException e) {
+ // Expected, for now
+ }
// extractor = ExtractorFactory.createExtractor(xlsxStrict);
// assertTrue(
// extractor
assertTrue(
ExtractorFactory.createExtractor(new FileInputStream(xlsx)).getText().length() > 200
);
+ // TODO Support OOXML-Strict, see bug #57699
+// assertTrue(
+// ExtractorFactory.createExtractor(new FileInputStream(xlsxStrict))
+// instanceof XSSFExcelExtractor
+// );
+// assertTrue(
+// ExtractorFactory.createExtractor(new FileInputStream(xlsxStrict)).getText().length() > 200
+// );
// Word
assertTrue(
/**
* OOXML-Strict files
+ * Not currently working - namespace mis-match from XMLBeans
*/
@Test
- @Ignore
+ @Ignore("XMLBeans namespace mis-match on ooxml-strict files")
public void test57699() throws Exception {
- Workbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.strict.xlsx");
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.strict.xlsx");
assertEquals(3, wb.getNumberOfSheets());
+ // TODO Check sheet contents
+ // TODO Check formula evaluation
- // TODO Check the rest
+ XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ assertEquals(3, wbBack.getNumberOfSheets());
+ // TODO Re-check sheet contents
+ // TODO Re-check formula evaluation
}
}