poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1666525 - in /poi/trunk/src/ooxml: java/org/apache/poi/ java/org/apache/poi/extractor/ testcases/org/apache/poi/extractor/ testcases/org/apache/poi/xssf/usermodel/
Date Fri, 13 Mar 2015 17:39:47 GMT
Author: nick
Date: Fri Mar 13 17:39:47 2015
New Revision: 1666525

URL: http://svn.apache.org/r1666525
Log:
Detect OOXML-strict, and give more helpful exceptions for them

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
    poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java?rev=1666525&r1=1666524&r2=1666525&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java Fri Mar 13 17:39:47 2015
@@ -94,6 +94,15 @@ public class POIXMLDocumentPart {
      */
     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;

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=1666525&r1=1666524&r2=1666525&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 Fri Mar 13 17:39:47
2015
@@ -47,6 +47,7 @@ import org.apache.poi.openxml4j.opc.OPCP
 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;
@@ -66,10 +67,9 @@ import org.apache.xmlbeans.XmlException;
  *  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? */
@@ -166,6 +166,10 @@ public class ExtractorFactory {
        
        // 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 =
                    pkg.getRelationshipsByType(VISIO_DOCUMENT_REL);
@@ -173,6 +177,7 @@ public class ExtractorFactory {
                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());

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=1666525&r1=1666524&r2=1666525&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 Fri Mar
13 17:39:47 2015
@@ -25,6 +25,7 @@ import junit.framework.TestCase;
 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;
@@ -162,6 +163,12 @@ public class TestExtractorFactory extend
         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
@@ -307,6 +314,14 @@ public class TestExtractorFactory extend
         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(

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1666525&r1=1666524&r2=1666525&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Fri Mar
13 17:39:47 2015
@@ -2293,13 +2293,19 @@ public final class TestXSSFBugs extends
     
     /**
      * 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
     }
 }



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


Mime
View raw message