poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1665929 - in /poi/trunk: src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java test-data/diagram/test.vsdx
Date Wed, 11 Mar 2015 16:17:42 GMT
Author: nick
Date: Wed Mar 11 16:17:41 2015
New Revision: 1665929

URL: http://svn.apache.org/r1665929
Log:
Give a more helpful exception if a Visio VSDX ooxml file is passed to ExtractorFactory

Added:
    poi/trunk/test-data/diagram/test.vsdx   (with props)
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java?rev=1665929&r1=1665928&r2=1665929&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java Wed Mar 11 16:17:41
2015
@@ -68,6 +68,8 @@ import org.apache.xmlbeans.XmlException;
 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";
 
 
 	/** Should this thread prefer event based over usermodel based extractors? */
@@ -158,12 +160,25 @@ public class ExtractorFactory {
 	}
 
 	public static POIXMLTextExtractor createExtractor(OPCPackage pkg) throws IOException, OpenXML4JException,
XmlException {
+	   // Check for the normal Office core document
        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());
+       
+       // If nothing was found, try some of the other OOXML-based core types
+       if (core.size() == 0) {
+           // Could it be a visio one?
+           PackageRelationshipCollection visio =
+                   pkg.getRelationshipsByType(VISIO_DOCUMENT_REL);
+           if (visio.size() == 1) {
+               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());
        }
 
+       // Grab the core document part, and try to identify from that
        PackagePart corePart = pkg.getPart(core.getRelationship(0));
 
        // Is it XSSF?

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java?rev=1665929&r1=1665928&r2=1665929&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java Wed Mar
11 16:17:41 2015
@@ -71,6 +71,7 @@ public class TestExtractorFactory extend
    private File msgEmbMsg;
    
    private File vsd;
+   private File vsdx;
    
    private File pub;
 
@@ -109,6 +110,7 @@ public class TestExtractorFactory extend
 
       POIDataSamples dgTests = POIDataSamples.getDiagramInstance();
       vsd = getFileAndCheck(dgTests, "Test_Visio-Some_Random_Text.vsd");
+      vsdx = getFileAndCheck(dgTests, "test.vsdx");
       
       POIDataSamples pubTests = POIDataSamples.getPublisherInstance();
       pub = getFileAndCheck(pubTests, "Simple.pub");
@@ -230,7 +232,7 @@ public class TestExtractorFactory extend
       );
       extractor.close();
 
-      // Visio
+      // Visio - binary
       assertTrue(
             ExtractorFactory.createExtractor(vsd)
             instanceof VisioTextExtractor
@@ -238,6 +240,13 @@ public class TestExtractorFactory extend
       assertTrue(
             ExtractorFactory.createExtractor(vsd).getText().length() > 50
       );
+      // Visio - vsdx
+      try {
+          ExtractorFactory.createExtractor(vsdx);
+          fail();
+      } catch(IllegalArgumentException e) {
+          // Good
+      }
       
       // Publisher
       assertTrue(
@@ -342,6 +351,13 @@ public class TestExtractorFactory extend
 		assertTrue(
 				ExtractorFactory.createExtractor(new FileInputStream(vsd)).getText().length() > 50
 		);
+	      // Visio - vsdx
+	      try {
+	          ExtractorFactory.createExtractor(new FileInputStream(vsdx));
+	          fail();
+	      } catch(IllegalArgumentException e) {
+	          // Good
+	      }
 		
       // Publisher
       assertTrue(

Added: poi/trunk/test-data/diagram/test.vsdx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/diagram/test.vsdx?rev=1665929&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/diagram/test.vsdx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message