aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi/extractor
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2010-07-29 11:57:08 +0000
committerNick Burch <nick@apache.org>2010-07-29 11:57:08 +0000
commitfbff3e557bbee0882a9b6492cad0e87ace030477 (patch)
treed5ecdd6439226fed1c404fc167d92a8dddfebb78 /src/ooxml/java/org/apache/poi/extractor
parentf575bfa0139c11d95e250e8ae2327e858d79f16b (diff)
downloadpoi-fbff3e557bbee0882a9b6492cad0e87ace030477.tar.gz
poi-fbff3e557bbee0882a9b6492cad0e87ace030477.zip
Refactor to make it easier to tell which content types each POIXMLTextExtractor handles
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@980414 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/extractor')
-rw-r--r--src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java69
1 files changed, 34 insertions, 35 deletions
diff --git a/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java b/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
index 7ccb9f9297..4864714f49 100644
--- a/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
+++ b/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
@@ -52,6 +52,7 @@ import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xslf.XSLFSlideShow;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
+import org.apache.poi.xslf.usermodel.XSLFRelation;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
import org.apache.poi.xssf.usermodel.XSSFRelation;
@@ -155,42 +156,40 @@ public class ExtractorFactory {
}
public static POIXMLTextExtractor createExtractor(OPCPackage pkg) throws IOException, OpenXML4JException, XmlException {
- PackageRelationshipCollection core =
- pkg.getRelationshipsByType(CORE_DOCUMENT_REL);
- if(core.size() != 1) {
- throw new IllegalArgumentException("Invalid OOXML Package received - expected 1 core document, found " + core.size());
- }
-
- PackagePart corePart = pkg.getPart(core.getRelationship(0));
- if (corePart.getContentType().equals(XSSFRelation.WORKBOOK.getContentType()) ||
- corePart.getContentType().equals(XSSFRelation.MACRO_TEMPLATE_WORKBOOK.getContentType()) ||
- corePart.getContentType().equals(XSSFRelation.MACRO_ADDIN_WORKBOOK.getContentType()) ||
- corePart.getContentType().equals(XSSFRelation.TEMPLATE_WORKBOOK.getContentType()) ||
- corePart.getContentType().equals(XSSFRelation.MACROS_WORKBOOK.getContentType())) {
- if(getPreferEventExtractor()) {
- return new XSSFEventBasedExcelExtractor(pkg);
- } else {
- return new XSSFExcelExtractor(pkg);
- }
- }
-
- if(corePart.getContentType().equals(XWPFRelation.DOCUMENT.getContentType()) ||
- corePart.getContentType().equals(XWPFRelation.TEMPLATE.getContentType()) ||
- corePart.getContentType().equals(XWPFRelation.MACRO_DOCUMENT.getContentType()) ||
- corePart.getContentType().equals(XWPFRelation.MACRO_TEMPLATE_DOCUMENT.getContentType()) ) {
- return new XWPFWordExtractor(pkg);
- }
-
- if(corePart.getContentType().equals(XSLFSlideShow.MAIN_CONTENT_TYPE) ||
- corePart.getContentType().equals(XSLFSlideShow.MACRO_CONTENT_TYPE) ||
- corePart.getContentType().equals(XSLFSlideShow.MACRO_TEMPLATE_CONTENT_TYPE) ||
- corePart.getContentType().equals(XSLFSlideShow.PRESENTATIONML_CONTENT_TYPE) ||
- corePart.getContentType().equals(XSLFSlideShow.PRESENTATIONML_TEMPLATE_CONTENT_TYPE) ||
- corePart.getContentType().equals(XSLFSlideShow.PRESENTATION_MACRO_CONTENT_TYPE)) {
- return new XSLFPowerPointExtractor(pkg);
- }
+ PackageRelationshipCollection core =
+ pkg.getRelationshipsByType(CORE_DOCUMENT_REL);
+ if(core.size() != 1) {
+ throw new IllegalArgumentException("Invalid OOXML Package received - expected 1 core document, found " + core.size());
+ }
- throw new IllegalArgumentException("No supported documents found in the OOXML package (found "+corePart.getContentType()+")");
+ PackagePart corePart = pkg.getPart(core.getRelationship(0));
+
+ // Is it XSSF?
+ for(XSSFRelation rel : XSSFExcelExtractor.SUPPORTED_TYPES) {
+ if(corePart.getContentType().equals(rel.getContentType())) {
+ if(getPreferEventExtractor()) {
+ return new XSSFEventBasedExcelExtractor(pkg);
+ } else {
+ return new XSSFExcelExtractor(pkg);
+ }
+ }
+ }
+
+ // Is it XWPF?
+ for(XWPFRelation rel : XWPFWordExtractor.SUPPORTED_TYPES) {
+ if(corePart.getContentType().equals(rel.getContentType())) {
+ return new XWPFWordExtractor(pkg);
+ }
+ }
+
+ // Is it XSLF?
+ for(XSLFRelation rel : XSLFPowerPointExtractor.SUPPORTED_TYPES) {
+ if(corePart.getContentType().equals(rel.getContentType())) {
+ return new XSLFPowerPointExtractor(pkg);
+ }
+ }
+
+ throw new IllegalArgumentException("No supported documents found in the OOXML package (found "+corePart.getContentType()+")");
}
public static POIOLE2TextExtractor createExtractor(POIFSFileSystem fs) throws IOException {