poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1691843 [20/30] - in /poi/branches/common_sl: ./ .settings/ legal/ osgi/ osgi/src/ src/examples/src/org/apache/poi/hpsf/examples/ src/examples/src/org/apache/poi/hssf/usermodel/examples/ src/examples/src/org/apache/poi/ss/examples/ src/exa...
Date Sun, 19 Jul 2015 19:00:38 GMT
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java Sun Jul 19 19:00:32 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;
@@ -47,252 +48,290 @@ import org.apache.poi.xwpf.extractor.XWP
  * Test that the extractor factory plays nicely
  */
 public class TestExtractorFactory extends TestCase {
+    private File txt;
 
-   private File txt;
+    private File xls;
+    private File xlsx;
+    private File xlsxStrict;
+    private File xltx;
+    private File xlsEmb;
+
+    private File doc;
+    private File doc6;
+    private File doc95;
+    private File docx;
+    private File dotx;
+    private File docEmb;
+    private File docEmbOOXML;
+
+    private File ppt;
+    private File pptx;
+
+    private File msg;
+    private File msgEmb;
+    private File msgEmbMsg;
+
+    private File vsd;
+    private File vsdx;
+
+    private File pub;
+
+    private File getFileAndCheck(POIDataSamples samples, String name) {
+        File file = samples.getFile(name);
+
+        assertNotNull("Did not get a file for " + name, file);
+        assertTrue("Did not get a type file for " + name, file.isFile());
+        assertTrue("File did not exist: " + name, file.exists());
+
+        return file;
+    }
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance();
+        xls = getFileAndCheck(ssTests, "SampleSS.xls");
+        xlsx = getFileAndCheck(ssTests, "SampleSS.xlsx");
+        xlsxStrict = getFileAndCheck(ssTests, "SampleSS.strict.xlsx");
+        xltx = getFileAndCheck(ssTests, "test.xltx");
+        xlsEmb = getFileAndCheck(ssTests, "excel_with_embeded.xls");
+
+        POIDataSamples wpTests = POIDataSamples.getDocumentInstance();
+        doc = getFileAndCheck(wpTests, "SampleDoc.doc");
+        doc6 = getFileAndCheck(wpTests, "Word6.doc");
+        doc95 = getFileAndCheck(wpTests, "Word95.doc");
+        docx = getFileAndCheck(wpTests, "SampleDoc.docx");
+        dotx = getFileAndCheck(wpTests, "test.dotx");
+        docEmb = getFileAndCheck(wpTests, "word_with_embeded.doc");
+        docEmbOOXML = getFileAndCheck(wpTests, "word_with_embeded_ooxml.doc");
+
+        POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
+        ppt = getFileAndCheck(slTests, "SampleShow.ppt");
+        pptx = getFileAndCheck(slTests, "SampleShow.pptx");
+        txt = getFileAndCheck(slTests, "SampleShow.txt");
+
+        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");
+
+        POIDataSamples olTests = POIDataSamples.getHSMFInstance();
+        msg = getFileAndCheck(olTests, "quick.msg");
+        msgEmb = getFileAndCheck(olTests, "attachment_test_msg.msg");
+        msgEmbMsg = getFileAndCheck(olTests, "attachment_msg_pdf.msg");
+    }
+
+    public void testFile() throws Exception {
+        // Excel
+        POITextExtractor xlsExtractor = ExtractorFactory.createExtractor(xls);
+        assertNotNull("Had empty extractor for " + xls, xlsExtractor);
+        assertTrue("Expected instanceof ExcelExtractor, but had: " + xlsExtractor.getClass(), 
+                xlsExtractor
+                instanceof ExcelExtractor
+        );
+        assertTrue(
+                xlsExtractor.getText().length() > 200
+        );
+        xlsExtractor.close();
+
+        POITextExtractor extractor = ExtractorFactory.createExtractor(xlsx);
+        assertTrue(
+                extractor
+                instanceof XSSFExcelExtractor
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(xlsx);
+        assertTrue(
+                extractor.getText().length() > 200
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(xltx);
+        assertTrue(
+                extractor
+                instanceof XSSFExcelExtractor
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(xltx);
+        assertTrue(
+                extractor.getText().contains("test")
+        );
+        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
+//                instanceof XSSFExcelExtractor
+//        );
+//        extractor.close();
+//
+//        extractor = ExtractorFactory.createExtractor(xlsxStrict);
+//        assertTrue(
+//                extractor.getText().contains("test")
+//        );
+//        extractor.close();
+
+
+        // Word
+        assertTrue(
+                ExtractorFactory.createExtractor(doc)
+                instanceof WordExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(doc).getText().length() > 120
+        );
+
+        assertTrue(
+                ExtractorFactory.createExtractor(doc6)
+                instanceof Word6Extractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(doc6).getText().length() > 20
+        );
+
+        assertTrue(
+                ExtractorFactory.createExtractor(doc95)
+                instanceof Word6Extractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(doc95).getText().length() > 120
+        );
+
+        extractor = ExtractorFactory.createExtractor(docx);
+        assertTrue(
+                extractor instanceof XWPFWordExtractor
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(docx);
+        assertTrue(
+                extractor.getText().length() > 120
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(dotx);
+        assertTrue(
+                extractor instanceof XWPFWordExtractor
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(dotx);
+        assertTrue(
+                extractor.getText().contains("Test")
+        );
+        extractor.close();
+
+        // PowerPoint
+        assertTrue(
+                ExtractorFactory.createExtractor(ppt)
+                instanceof PowerPointExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(ppt).getText().length() > 120
+        );
+
+        extractor = ExtractorFactory.createExtractor(pptx);
+        assertTrue(
+                extractor
+                instanceof XSLFPowerPointExtractor
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(pptx);
+        assertTrue(
+                extractor.getText().length() > 120
+        );
+        extractor.close();
+
+        // Visio - binary
+        assertTrue(
+                ExtractorFactory.createExtractor(vsd)
+                instanceof VisioTextExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(vsd).getText().length() > 50
+        );
+        // Visio - vsdx
+        try {
+            ExtractorFactory.createExtractor(vsdx);
+            fail();
+        } catch(IllegalArgumentException e) {
+            // Good
+        }
+
+        // Publisher
+        assertTrue(
+                ExtractorFactory.createExtractor(pub)
+                instanceof PublisherTextExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(pub).getText().length() > 50
+        );
+
+        // Outlook msg
+        assertTrue(
+                ExtractorFactory.createExtractor(msg)
+                instanceof OutlookTextExtactor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(msg).getText().length() > 50
+        );
+
+        // Text
+        try {
+            ExtractorFactory.createExtractor(txt);
+            fail();
+        } catch(IllegalArgumentException e) {
+            // Good
+        }
+    }
+
+    public void testInputStream() throws Exception {
+        // Excel
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(xls))
+                instanceof ExcelExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(xls)).getText().length() > 200
+        );
+
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(xlsx))
+                instanceof XSSFExcelExtractor
+        );
+        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(
+                ExtractorFactory.createExtractor(new FileInputStream(doc))
+                instanceof WordExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(doc)).getText().length() > 120
+        );
 
-   private File xls;
-   private File xlsx;
-   private File xltx;
-   private File xlsEmb;
-
-   private File doc;
-   private File doc6;
-   private File doc95;
-   private File docx;
-   private File dotx;
-   private File docEmb;
-   private File docEmbOOXML;
-
-   private File ppt;
-   private File pptx;
-
-   private File msg;
-   private File msgEmb;
-   private File msgEmbMsg;
-   
-   private File vsd;
-   
-   private File pub;
-
-   private File getFileAndCheck(POIDataSamples samples, String name) {
-       File file = samples.getFile(name);
-       
-       assertNotNull("Did not get a file for " + name, file);
-       assertTrue("Did not get a type file for " + name, file.isFile());
-       assertTrue("File did not exist: " + name, file.exists());
-       
-       return file;
-   }
-   @Override
-   protected void setUp() throws Exception {
-      super.setUp();
-
-      POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance();
-      xls = getFileAndCheck(ssTests, "SampleSS.xls");
-      xlsx = getFileAndCheck(ssTests, "SampleSS.xlsx");
-      xltx = getFileAndCheck(ssTests, "test.xltx");
-      xlsEmb = getFileAndCheck(ssTests, "excel_with_embeded.xls");
-
-      POIDataSamples wpTests = POIDataSamples.getDocumentInstance();
-      doc = getFileAndCheck(wpTests, "SampleDoc.doc");
-      doc6 = getFileAndCheck(wpTests, "Word6.doc");
-      doc95 = getFileAndCheck(wpTests, "Word95.doc");
-      docx = getFileAndCheck(wpTests, "SampleDoc.docx");
-      dotx = getFileAndCheck(wpTests, "test.dotx");
-      docEmb = getFileAndCheck(wpTests, "word_with_embeded.doc");
-      docEmbOOXML = getFileAndCheck(wpTests, "word_with_embeded_ooxml.doc");
-
-      POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
-      ppt = getFileAndCheck(slTests, "SampleShow.ppt");
-      pptx = getFileAndCheck(slTests, "SampleShow.pptx");
-      txt = getFileAndCheck(slTests, "SampleShow.txt");
-
-      POIDataSamples dgTests = POIDataSamples.getDiagramInstance();
-      vsd = getFileAndCheck(dgTests, "Test_Visio-Some_Random_Text.vsd");
-      
-      POIDataSamples pubTests = POIDataSamples.getPublisherInstance();
-      pub = getFileAndCheck(pubTests, "Simple.pub");
-      
-      POIDataSamples olTests = POIDataSamples.getHSMFInstance();
-      msg = getFileAndCheck(olTests, "quick.msg");
-      msgEmb = getFileAndCheck(olTests, "attachment_test_msg.msg");
-      msgEmbMsg = getFileAndCheck(olTests, "attachment_msg_pdf.msg");
-   }
-
-   public void testFile() throws Exception {
-      // Excel
-      POITextExtractor xlsExtractor = ExtractorFactory.createExtractor(xls);
-      assertNotNull("Had empty extractor for " + xls, xlsExtractor);
-      assertTrue("Expected instanceof ExcelExtractor, but had: " + xlsExtractor.getClass(), 
-            xlsExtractor
-            instanceof ExcelExtractor
-      );
-      assertTrue(
-            xlsExtractor.getText().length() > 200
-      );
-      xlsExtractor.close();
-
-      POITextExtractor extractor = ExtractorFactory.createExtractor(xlsx);
-      assertTrue(
-            extractor
-            instanceof XSSFExcelExtractor
-      );
-      extractor.close();
-
-      extractor = ExtractorFactory.createExtractor(xlsx);
-      assertTrue(
-            extractor.getText().length() > 200
-      );
-      extractor.close();
-
-      extractor = ExtractorFactory.createExtractor(xltx);
-      assertTrue(
-            extractor
-            instanceof XSSFExcelExtractor
-      );
-      extractor.close();
-
-      extractor = ExtractorFactory.createExtractor(xltx);
-      assertTrue(
-            extractor.getText().contains("test")
-      );
-      extractor.close();
-
-
-      // Word
-      assertTrue(
-            ExtractorFactory.createExtractor(doc)
-            instanceof WordExtractor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(doc).getText().length() > 120
-      );
-
-      assertTrue(
-            ExtractorFactory.createExtractor(doc6)
-            instanceof Word6Extractor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(doc6).getText().length() > 20
-      );
-      
-      assertTrue(
-            ExtractorFactory.createExtractor(doc95)
-            instanceof Word6Extractor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(doc95).getText().length() > 120
-      );
-          
-      extractor = ExtractorFactory.createExtractor(docx);
-      assertTrue(
-            extractor instanceof XWPFWordExtractor
-      );
-      extractor.close();
-      
-      extractor = ExtractorFactory.createExtractor(docx);
-      assertTrue(
-            extractor.getText().length() > 120
-      );
-      extractor.close();
-
-      extractor = ExtractorFactory.createExtractor(dotx);
-      assertTrue(
-            extractor instanceof XWPFWordExtractor
-      );
-      extractor.close();
-      
-      extractor = ExtractorFactory.createExtractor(dotx);
-      assertTrue(
-            extractor.getText().contains("Test")
-      );
-      extractor.close();
-
-      // PowerPoint
-      assertTrue(
-            ExtractorFactory.createExtractor(ppt)
-            instanceof PowerPointExtractor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(ppt).getText().length() > 120
-      );
-
-      extractor = ExtractorFactory.createExtractor(pptx);
-      assertTrue(
-            extractor
-            instanceof XSLFPowerPointExtractor
-      );
-      extractor.close();
-
-      extractor = ExtractorFactory.createExtractor(pptx);
-      assertTrue(
-            extractor.getText().length() > 120
-      );
-      extractor.close();
-
-      // Visio
-      assertTrue(
-            ExtractorFactory.createExtractor(vsd)
-            instanceof VisioTextExtractor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(vsd).getText().length() > 50
-      );
-      
-      // Publisher
-      assertTrue(
-            ExtractorFactory.createExtractor(pub)
-            instanceof PublisherTextExtractor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(pub).getText().length() > 50
-      );
-      
-      // Outlook msg
-      assertTrue(
-            ExtractorFactory.createExtractor(msg)
-            instanceof OutlookTextExtactor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(msg).getText().length() > 50
-      );
-
-      // Text
-      try {
-         ExtractorFactory.createExtractor(txt);
-         fail();
-      } catch(IllegalArgumentException e) {
-         // Good
-      }
-	}
-	
-	public void testInputStream() throws Exception {
-		// Excel
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(xls))
-				instanceof ExcelExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(xls)).getText().length() > 200
-		);
-		
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(xlsx))
-				instanceof XSSFExcelExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(xlsx)).getText().length() > 200
-		);
-		
-		// Word
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(doc))
-				instanceof WordExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(doc)).getText().length() > 120
-		);
-		
         assertTrue(
                 ExtractorFactory.createExtractor(new FileInputStream(doc6))
                 instanceof Word6Extractor
@@ -300,7 +339,7 @@ public class TestExtractorFactory extend
         assertTrue(
                 ExtractorFactory.createExtractor(new FileInputStream(doc6)).getText().length() > 20
         );
-        
+
         assertTrue(
                 ExtractorFactory.createExtractor(new FileInputStream(doc95))
                 instanceof Word6Extractor
@@ -308,92 +347,99 @@ public class TestExtractorFactory extend
         assertTrue(
                 ExtractorFactory.createExtractor(new FileInputStream(doc95)).getText().length() > 120
         );
-        
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(docx))
-				instanceof XWPFWordExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(docx)).getText().length() > 120
-		);
-		
-		// PowerPoint
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(ppt))
-				instanceof PowerPointExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(ppt)).getText().length() > 120
-		);
-		
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(pptx))
-				instanceof XSLFPowerPointExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(pptx)).getText().length() > 120
-		);
-		
-		// Visio
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(vsd))
-				instanceof VisioTextExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new FileInputStream(vsd)).getText().length() > 50
-		);
-		
-      // Publisher
-      assertTrue(
-            ExtractorFactory.createExtractor(new FileInputStream(pub))
-            instanceof PublisherTextExtractor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(new FileInputStream(pub)).getText().length() > 50
-      );
-      
-		// Outlook msg
-      assertTrue(
-            ExtractorFactory.createExtractor(new FileInputStream(msg))
-            instanceof OutlookTextExtactor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(new FileInputStream(msg)).getText().length() > 50
-      );
-		
-		// Text
-		try {
-			FileInputStream stream = new FileInputStream(txt);
-			try {
+
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(docx))
+                instanceof XWPFWordExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(docx)).getText().length() > 120
+        );
+
+        // PowerPoint
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(ppt))
+                instanceof PowerPointExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(ppt)).getText().length() > 120
+        );
+
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(pptx))
+                instanceof XSLFPowerPointExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(pptx)).getText().length() > 120
+        );
+
+        // Visio
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(vsd))
+                instanceof VisioTextExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(vsd)).getText().length() > 50
+        );
+        // Visio - vsdx
+        try {
+            ExtractorFactory.createExtractor(new FileInputStream(vsdx));
+            fail();
+        } catch(IllegalArgumentException e) {
+            // Good
+        }
+
+        // Publisher
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(pub))
+                instanceof PublisherTextExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(pub)).getText().length() > 50
+        );
+
+        // Outlook msg
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(msg))
+                instanceof OutlookTextExtactor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new FileInputStream(msg)).getText().length() > 50
+        );
+
+        // Text
+        try {
+            FileInputStream stream = new FileInputStream(txt);
+            try {
                 ExtractorFactory.createExtractor(stream);
-    			fail();
-			} finally {
-			    stream.close();
-			}
-		} catch(IllegalArgumentException e) {
-			// Good
-		}
-	}
-	
-	public void testPOIFS() throws Exception {
-		// Excel
-		assertTrue(
-				ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)))
-				instanceof ExcelExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls))).getText().length() > 200
-		);
-		
-		// Word
-		assertTrue(
-				ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc)))
-				instanceof WordExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc))).getText().length() > 120
-		);
-		
+                fail();
+            } finally {
+                stream.close();
+            }
+        } catch(IllegalArgumentException e) {
+            // Good
+        }
+    }
+
+    public void testPOIFS() throws Exception {
+        // Excel
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)))
+                instanceof ExcelExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls))).getText().length() > 200
+        );
+
+        // Word
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc)))
+                instanceof WordExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc))).getText().length() > 120
+        );
+
         assertTrue(
                 ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc6)))
                 instanceof Word6Extractor
@@ -401,7 +447,7 @@ public class TestExtractorFactory extend
         assertTrue(
                 ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc6))).getText().length() > 20
         );
-        
+
         assertTrue(
                 ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc95)))
                 instanceof Word6Extractor
@@ -409,297 +455,297 @@ public class TestExtractorFactory extend
         assertTrue(
                 ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(doc95))).getText().length() > 120
         );
-        
-		// PowerPoint
-		assertTrue(
-				ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(ppt)))
-				instanceof PowerPointExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(ppt))).getText().length() > 120
-		);
-		
-		// Visio
-		assertTrue(
-				ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(vsd)))
-				instanceof VisioTextExtractor
-		);
-		assertTrue(
-				ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(vsd))).getText().length() > 50
-		);
-      
-      // Publisher
-      assertTrue(
-            ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(pub)))
-            instanceof PublisherTextExtractor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(pub))).getText().length() > 50
-      );
-		
-      // Outlook msg
-      assertTrue(
-            ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(msg)))
-            instanceof OutlookTextExtactor
-      );
-      assertTrue(
-            ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(msg))).getText().length() > 50
-      );
-      
-		// Text
-		try {
-			ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(txt)));
-			fail();
-		} catch(IOException e) {
-			// Good
-		}
-	}
-	
-	public void testPackage() throws Exception {
-		// Excel
-		POIXMLTextExtractor extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
-        assertTrue(
-				extractor
-				instanceof XSSFExcelExtractor
-		);
+
+        // PowerPoint
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(ppt)))
+                instanceof PowerPointExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(ppt))).getText().length() > 120
+        );
+
+        // Visio
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(vsd)))
+                instanceof VisioTextExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(vsd))).getText().length() > 50
+        );
+
+        // Publisher
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(pub)))
+                instanceof PublisherTextExtractor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(pub))).getText().length() > 50
+        );
+
+        // Outlook msg
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(msg)))
+                instanceof OutlookTextExtactor
+        );
+        assertTrue(
+                ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(msg))).getText().length() > 50
+        );
+
+        // Text
+        try {
+            ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(txt)));
+            fail();
+        } catch(IOException e) {
+            // Good
+        }
+    }
+
+    public void testPackage() throws Exception {
+        // Excel
+        POIXMLTextExtractor extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
+        assertTrue(
+                extractor
+                instanceof XSSFExcelExtractor
+        );
         extractor.close();
-		extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString()));
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString()));
         assertTrue(extractor.getText().length() > 200);
         extractor.close();
-		
-		// Word
-		extractor = ExtractorFactory.createExtractor(OPCPackage.open(docx.toString()));
-        assertTrue(
-				extractor
-				instanceof XWPFWordExtractor
-		);
-        extractor.close();
-        
-		extractor = ExtractorFactory.createExtractor(OPCPackage.open(docx.toString()));
-        assertTrue(
-				extractor.getText().length() > 120
-		);
-        extractor.close();
-		
-		// PowerPoint
-		extractor = ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString()));
-        assertTrue(
-				extractor
-				instanceof XSLFPowerPointExtractor
-		);
-        extractor.close();
-
-		extractor = ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString()));
-        assertTrue(
-				extractor.getText().length() > 120
-		);
-        extractor.close();
-		
-		// Text
-		try {
-			ExtractorFactory.createExtractor(OPCPackage.open(txt.toString()));
-			fail();
-		} catch(InvalidOperationException e) {
-			// Good
-		}
-	}
-	
-	public void testPreferEventBased() throws Exception {
-	   assertFalse(ExtractorFactory.getPreferEventExtractor());
-	   assertFalse(ExtractorFactory.getThreadPrefersEventExtractors());
-	   assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
-	   
-	   ExtractorFactory.setThreadPrefersEventExtractors(true);
-	   
-      assertTrue(ExtractorFactory.getPreferEventExtractor());
-      assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
-      assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
-      
-      ExtractorFactory.setAllThreadsPreferEventExtractors(false);
-      
-      assertFalse(ExtractorFactory.getPreferEventExtractor());
-      assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
-      assertEquals(Boolean.FALSE, ExtractorFactory.getAllThreadsPreferEventExtractors());
-      
-      ExtractorFactory.setAllThreadsPreferEventExtractors(null);
-      
-      assertTrue(ExtractorFactory.getPreferEventExtractor());
-      assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
-      assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
-      
-      
-      // Check we get the right extractors now
-      POITextExtractor extractor = ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)));
-      assertTrue(
-            extractor
-            instanceof EventBasedExcelExtractor
-      );
-      extractor.close();
-      extractor = ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)));
-      assertTrue(
-            extractor.getText().length() > 200
-      );
-      extractor.close();
-      
-      extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
-      assertTrue(extractor instanceof XSSFEventBasedExcelExtractor);
-      extractor.close();
-
-      extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
-      assertTrue(
-            extractor.getText().length() > 200
-      );
-      extractor.close();
-      
-      
-      // Put back to normal
-      ExtractorFactory.setThreadPrefersEventExtractors(false);
-      assertFalse(ExtractorFactory.getPreferEventExtractor());
-      assertFalse(ExtractorFactory.getThreadPrefersEventExtractors());
-      assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
-      
-      // And back
-      extractor = ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)));
-      assertTrue(
-            extractor
-            instanceof ExcelExtractor
-      );
-      extractor.close();
-      extractor = ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)));
-      assertTrue(
-            extractor.getText().length() > 200
-      );
-      extractor.close();
-      
-      extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
-      assertTrue(
-            extractor
-            instanceof XSSFExcelExtractor
-      );
-      extractor.close();
-      extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString()));
-      assertTrue(
-            extractor.getText().length() > 200
-      );
-      extractor.close();
-	}
-
-   /**
-    * Test embeded docs text extraction. For now, only
-    *  does poifs embeded, but will do ooxml ones 
-    *  at some point.
-    */
-   public void testEmbeded() throws Exception {
-      POIOLE2TextExtractor ext;
-      POITextExtractor[] embeds;
-
-      // No embedings
-      ext = (POIOLE2TextExtractor)
-      ExtractorFactory.createExtractor(xls);
-      embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
-      assertEquals(0, embeds.length);
-
-      // Excel
-      ext = (POIOLE2TextExtractor)
-      ExtractorFactory.createExtractor(xlsEmb);
-      embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
-
-      assertEquals(6, embeds.length);
-      int numWord = 0, numXls = 0, numPpt = 0, numMsg = 0, numWordX;
-      for(int i=0; i<embeds.length; i++) {
-         assertTrue(embeds[i].getText().length() > 20);
-
-         if(embeds[i] instanceof PowerPointExtractor) numPpt++;
-         else if(embeds[i] instanceof ExcelExtractor) numXls++;
-         else if(embeds[i] instanceof WordExtractor) numWord++;
-         else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
-      }
-      assertEquals(2, numPpt);
-      assertEquals(2, numXls);
-      assertEquals(2, numWord);
-      assertEquals(0, numMsg);
-
-      // Word
-      ext = (POIOLE2TextExtractor)
-      ExtractorFactory.createExtractor(docEmb);
-      embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
-
-      numWord = 0; numXls = 0; numPpt = 0; numMsg = 0;
-      assertEquals(4, embeds.length);
-      for(int i=0; i<embeds.length; i++) {
-         assertTrue(embeds[i].getText().length() > 20);
-         if(embeds[i] instanceof PowerPointExtractor) numPpt++;
-         else if(embeds[i] instanceof ExcelExtractor) numXls++;
-         else if(embeds[i] instanceof WordExtractor) numWord++;
-         else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
-      }
-      assertEquals(1, numPpt);
-      assertEquals(2, numXls);
-      assertEquals(1, numWord);
-      assertEquals(0, numMsg);
-      
-      // Word which contains an OOXML file
-      ext = (POIOLE2TextExtractor)
-      ExtractorFactory.createExtractor(docEmbOOXML);
-      embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
-
-      numWord = 0; numXls = 0; numPpt = 0; numMsg = 0; numWordX = 0;
-      assertEquals(3, embeds.length);
-      for(int i=0; i<embeds.length; i++) {
-         assertTrue(embeds[i].getText().length() > 20);
-         if(embeds[i] instanceof PowerPointExtractor) numPpt++;
-         else if(embeds[i] instanceof ExcelExtractor) numXls++;
-         else if(embeds[i] instanceof WordExtractor) numWord++;
-         else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
-         else if(embeds[i] instanceof XWPFWordExtractor) numWordX++;
-      }
-      assertEquals(1, numPpt);
-      assertEquals(1, numXls);
-      assertEquals(0, numWord);
-      assertEquals(1, numWordX);
-      assertEquals(0, numMsg);
-      
-      // Outlook
-      ext = (OutlookTextExtactor)
-      ExtractorFactory.createExtractor(msgEmb);
-      embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
-
-      numWord = 0; numXls = 0; numPpt = 0; numMsg = 0;
-      assertEquals(1, embeds.length);
-      for(int i=0; i<embeds.length; i++) {
-         assertTrue(embeds[i].getText().length() > 20);
-         if(embeds[i] instanceof PowerPointExtractor) numPpt++;
-         else if(embeds[i] instanceof ExcelExtractor) numXls++;
-         else if(embeds[i] instanceof WordExtractor) numWord++;
-         else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
-      }
-      assertEquals(0, numPpt);
-      assertEquals(0, numXls);
-      assertEquals(1, numWord);
-      assertEquals(0, numMsg);
-      
-      // Outlook with another outlook file in it
-      ext = (OutlookTextExtactor)
-      ExtractorFactory.createExtractor(msgEmbMsg);
-      embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
-
-      numWord = 0; numXls = 0; numPpt = 0; numMsg = 0;
-      assertEquals(1, embeds.length);
-      for(int i=0; i<embeds.length; i++) {
-         assertTrue(embeds[i].getText().length() > 20);
-         if(embeds[i] instanceof PowerPointExtractor) numPpt++;
-         else if(embeds[i] instanceof ExcelExtractor) numXls++;
-         else if(embeds[i] instanceof WordExtractor) numWord++;
-         else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
-      }
-      assertEquals(0, numPpt);
-      assertEquals(0, numXls);
-      assertEquals(0, numWord);
-      assertEquals(1, numMsg);
-      
-
-      // TODO - PowerPoint
-      // TODO - Publisher
-      // TODO - Visio
-   }
+
+        // Word
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(docx.toString()));
+        assertTrue(
+                extractor
+                instanceof XWPFWordExtractor
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(docx.toString()));
+        assertTrue(
+                extractor.getText().length() > 120
+        );
+        extractor.close();
+
+        // PowerPoint
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString()));
+        assertTrue(
+                extractor
+                instanceof XSLFPowerPointExtractor
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString()));
+        assertTrue(
+                extractor.getText().length() > 120
+        );
+        extractor.close();
+
+        // Text
+        try {
+            ExtractorFactory.createExtractor(OPCPackage.open(txt.toString()));
+            fail();
+        } catch(InvalidOperationException e) {
+            // Good
+        }
+    }
+
+    public void testPreferEventBased() throws Exception {
+        assertFalse(ExtractorFactory.getPreferEventExtractor());
+        assertFalse(ExtractorFactory.getThreadPrefersEventExtractors());
+        assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
+
+        ExtractorFactory.setThreadPrefersEventExtractors(true);
+
+        assertTrue(ExtractorFactory.getPreferEventExtractor());
+        assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
+        assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
+
+        ExtractorFactory.setAllThreadsPreferEventExtractors(false);
+
+        assertFalse(ExtractorFactory.getPreferEventExtractor());
+        assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
+        assertEquals(Boolean.FALSE, ExtractorFactory.getAllThreadsPreferEventExtractors());
+
+        ExtractorFactory.setAllThreadsPreferEventExtractors(null);
+
+        assertTrue(ExtractorFactory.getPreferEventExtractor());
+        assertTrue(ExtractorFactory.getThreadPrefersEventExtractors());
+        assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
+
+
+        // Check we get the right extractors now
+        POITextExtractor extractor = ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)));
+        assertTrue(
+                extractor
+                instanceof EventBasedExcelExtractor
+        );
+        extractor.close();
+        extractor = ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)));
+        assertTrue(
+                extractor.getText().length() > 200
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
+        assertTrue(extractor instanceof XSSFEventBasedExcelExtractor);
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
+        assertTrue(
+                extractor.getText().length() > 200
+        );
+        extractor.close();
+
+
+        // Put back to normal
+        ExtractorFactory.setThreadPrefersEventExtractors(false);
+        assertFalse(ExtractorFactory.getPreferEventExtractor());
+        assertFalse(ExtractorFactory.getThreadPrefersEventExtractors());
+        assertNull(ExtractorFactory.getAllThreadsPreferEventExtractors());
+
+        // And back
+        extractor = ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)));
+        assertTrue(
+                extractor
+                instanceof ExcelExtractor
+        );
+        extractor.close();
+        extractor = ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls)));
+        assertTrue(
+                extractor.getText().length() > 200
+        );
+        extractor.close();
+
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
+        assertTrue(
+                extractor
+                instanceof XSSFExcelExtractor
+        );
+        extractor.close();
+        extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString()));
+        assertTrue(
+                extractor.getText().length() > 200
+        );
+        extractor.close();
+    }
+
+    /**
+     * Test embeded docs text extraction. For now, only
+     *  does poifs embeded, but will do ooxml ones 
+     *  at some point.
+     */
+    public void testEmbeded() throws Exception {
+        POIOLE2TextExtractor ext;
+        POITextExtractor[] embeds;
+
+        // No embedings
+        ext = (POIOLE2TextExtractor)
+                ExtractorFactory.createExtractor(xls);
+        embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
+        assertEquals(0, embeds.length);
+
+        // Excel
+        ext = (POIOLE2TextExtractor)
+                ExtractorFactory.createExtractor(xlsEmb);
+        embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
+
+        assertEquals(6, embeds.length);
+        int numWord = 0, numXls = 0, numPpt = 0, numMsg = 0, numWordX;
+        for(int i=0; i<embeds.length; i++) {
+            assertTrue(embeds[i].getText().length() > 20);
+
+            if(embeds[i] instanceof PowerPointExtractor) numPpt++;
+            else if(embeds[i] instanceof ExcelExtractor) numXls++;
+            else if(embeds[i] instanceof WordExtractor) numWord++;
+            else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
+        }
+        assertEquals(2, numPpt);
+        assertEquals(2, numXls);
+        assertEquals(2, numWord);
+        assertEquals(0, numMsg);
+
+        // Word
+        ext = (POIOLE2TextExtractor)
+                ExtractorFactory.createExtractor(docEmb);
+        embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
+
+        numWord = 0; numXls = 0; numPpt = 0; numMsg = 0;
+        assertEquals(4, embeds.length);
+        for(int i=0; i<embeds.length; i++) {
+            assertTrue(embeds[i].getText().length() > 20);
+            if(embeds[i] instanceof PowerPointExtractor) numPpt++;
+            else if(embeds[i] instanceof ExcelExtractor) numXls++;
+            else if(embeds[i] instanceof WordExtractor) numWord++;
+            else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
+        }
+        assertEquals(1, numPpt);
+        assertEquals(2, numXls);
+        assertEquals(1, numWord);
+        assertEquals(0, numMsg);
+
+        // Word which contains an OOXML file
+        ext = (POIOLE2TextExtractor)
+                ExtractorFactory.createExtractor(docEmbOOXML);
+        embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
+
+        numWord = 0; numXls = 0; numPpt = 0; numMsg = 0; numWordX = 0;
+        assertEquals(3, embeds.length);
+        for(int i=0; i<embeds.length; i++) {
+            assertTrue(embeds[i].getText().length() > 20);
+            if(embeds[i] instanceof PowerPointExtractor) numPpt++;
+            else if(embeds[i] instanceof ExcelExtractor) numXls++;
+            else if(embeds[i] instanceof WordExtractor) numWord++;
+            else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
+            else if(embeds[i] instanceof XWPFWordExtractor) numWordX++;
+        }
+        assertEquals(1, numPpt);
+        assertEquals(1, numXls);
+        assertEquals(0, numWord);
+        assertEquals(1, numWordX);
+        assertEquals(0, numMsg);
+
+        // Outlook
+        ext = (OutlookTextExtactor)
+                ExtractorFactory.createExtractor(msgEmb);
+        embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
+
+        numWord = 0; numXls = 0; numPpt = 0; numMsg = 0;
+        assertEquals(1, embeds.length);
+        for(int i=0; i<embeds.length; i++) {
+            assertTrue(embeds[i].getText().length() > 20);
+            if(embeds[i] instanceof PowerPointExtractor) numPpt++;
+            else if(embeds[i] instanceof ExcelExtractor) numXls++;
+            else if(embeds[i] instanceof WordExtractor) numWord++;
+            else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
+        }
+        assertEquals(0, numPpt);
+        assertEquals(0, numXls);
+        assertEquals(1, numWord);
+        assertEquals(0, numMsg);
+
+        // Outlook with another outlook file in it
+        ext = (OutlookTextExtactor)
+                ExtractorFactory.createExtractor(msgEmbMsg);
+        embeds = ExtractorFactory.getEmbededDocsTextExtractors(ext);
+
+        numWord = 0; numXls = 0; numPpt = 0; numMsg = 0;
+        assertEquals(1, embeds.length);
+        for(int i=0; i<embeds.length; i++) {
+            assertTrue(embeds[i].getText().length() > 20);
+            if(embeds[i] instanceof PowerPointExtractor) numPpt++;
+            else if(embeds[i] instanceof ExcelExtractor) numXls++;
+            else if(embeds[i] instanceof WordExtractor) numWord++;
+            else if(embeds[i] instanceof OutlookTextExtactor) numMsg++;
+        }
+        assertEquals(0, numPpt);
+        assertEquals(0, numXls);
+        assertEquals(0, numWord);
+        assertEquals(1, numMsg);
+
+
+        // TODO - PowerPoint
+        // TODO - Publisher
+        // TODO - Visio
+    }
 }

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/AllOpenXML4JTests.java Sun Jul 19 19:00:32 2015
@@ -17,28 +17,24 @@
 
 package org.apache.poi.openxml4j.opc;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
 import org.apache.poi.openxml4j.opc.compliance.AllOpenXML4JComplianceTests;
 import org.apache.poi.openxml4j.opc.internal.AllOpenXML4JInternalTests;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
 
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+      TestContentType.class
+    , TestFileHelper.class
+    , TestListParts.class
+    , TestPackage.class
+    , TestPackageCoreProperties.class
+    , TestPackagePartName.class
+    , TestPackageThumbnail.class
+    , TestPackagingURIHelper.class
+    , TestRelationships.class
+    , AllOpenXML4JComplianceTests.class
+    , AllOpenXML4JInternalTests.class
+})
 public final class AllOpenXML4JTests {
-
-	public static Test suite() {
-
-		TestSuite suite = new TestSuite(AllOpenXML4JTests.class.getName());
-		suite.addTestSuite(TestContentType.class);
-		suite.addTestSuite(TestFileHelper.class);
-		suite.addTestSuite(TestListParts.class);
-		suite.addTestSuite(TestPackage.class);
-		suite.addTestSuite(TestPackageCoreProperties.class);
-		suite.addTestSuite(TestPackagePartName.class);
-		suite.addTestSuite(TestPackageThumbnail.class);
-		suite.addTestSuite(TestPackagingURIHelper.class);
-		suite.addTestSuite(TestRelationships.class);
-		suite.addTest(AllOpenXML4JComplianceTests.suite());
-		suite.addTest(AllOpenXML4JInternalTests.suite());
-		return suite;
-	}
 }

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java Sun Jul 19 19:00:32 2015
@@ -17,6 +17,14 @@
 
 package org.apache.poi.openxml4j.opc;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -25,35 +33,47 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.TreeMap;
 import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
 
-import junit.framework.TestCase;
-
+import org.apache.poi.POIXMLException;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
 import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;
 import org.apache.poi.openxml4j.opc.internal.FileHelper;
 import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
+import org.apache.poi.openxml4j.opc.internal.ZipHelper;
+import org.apache.poi.openxml4j.util.ZipSecureFile;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.util.DocumentHelper;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.TempFile;
+import org.junit.Ignore;
+import org.junit.Test;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
-public final class TestPackage extends TestCase {
+public final class TestPackage {
     private static final POILogger logger = POILogFactory.getLogger(TestPackage.class);
 
 	/**
 	 * Test that just opening and closing the file doesn't alter the document.
 	 */
-	public void testOpenSave() throws Exception {
+    @Test
+	public void openSave() throws Exception {
 		String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
 		File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.docx");
 
@@ -75,7 +95,8 @@ public final class TestPackage extends T
 	 * Test that when we create a new Package, we give it
 	 *  the correct default content types
 	 */
-	public void testCreateGetsContentTypes() throws Exception {
+    @Test
+	public void createGetsContentTypes() throws Exception {
 		File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestCreatePackageTMP.docx");
 
 		// Zap the target file, in case of an earlier run
@@ -107,7 +128,8 @@ public final class TestPackage extends T
 	/**
 	 * Test package creation.
 	 */
-	public void testCreatePackageAddPart() throws Exception {
+    @Test
+	public void createPackageAddPart() throws Exception {
 		File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestCreatePackageTMP.docx");
 
 		File expectedFile = OpenXML4JTestDataSamples.getSampleFile("TestCreatePackageOUTPUT.docx");
@@ -153,7 +175,8 @@ public final class TestPackage extends T
 	 *  document and another part, save and re-load and
 	 *  have everything setup as expected
 	 */
-	public void testCreatePackageWithCoreDocument() throws Exception {
+    @Test
+	public void createPackageWithCoreDocument() throws Exception {
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 		OPCPackage pkg = OPCPackage.create(baos);
 
@@ -247,7 +270,8 @@ public final class TestPackage extends T
     /**
 	 * Test package opening.
 	 */
-	public void testOpenPackage() throws Exception {
+    @Test
+	public void openPackage() throws Exception {
 		File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestOpenPackageTMP.docx");
 
 		File inputFile = OpenXML4JTestDataSamples.getSampleFile("TestOpenPackageINPUT.docx");
@@ -306,7 +330,8 @@ public final class TestPackage extends T
 	 *  OutputStream, in addition to the normal writing
 	 *  to a file
 	 */
-	public void testSaveToOutputStream() throws Exception {
+    @Test
+	public void saveToOutputStream() throws Exception {
 		String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
 		File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageOpenSaveTMP.docx");
 
@@ -334,7 +359,8 @@ public final class TestPackage extends T
 	 *  simple InputStream, in addition to the normal
 	 *  reading from a file
 	 */
-	public void testOpenFromInputStream() throws Exception {
+    @Test
+	public void openFromInputStream() throws Exception {
 		String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
 
 		FileInputStream finp = new FileInputStream(originalFile);
@@ -353,7 +379,9 @@ public final class TestPackage extends T
     /**
      * TODO: fix and enable
      */
-    public void disabled_testRemovePartRecursive() throws Exception {
+    @Test
+    @Ignore
+    public void removePartRecursive() throws Exception {
 		String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
 		File targetFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveOUTPUT.docx");
 		File tempFile = OpenXML4JTestDataSamples.getOutputFile("TestPackageRemovePartRecursiveTMP.docx");
@@ -369,7 +397,8 @@ public final class TestPackage extends T
 		assertTrue(targetFile.delete());
 	}
 
-	public void testDeletePart() throws InvalidFormatException {
+    @Test
+	public void deletePart() throws InvalidFormatException {
 		TreeMap<PackagePartName, String> expectedValues;
 		TreeMap<PackagePartName, String> values;
 
@@ -426,7 +455,8 @@ public final class TestPackage extends T
 		p.revert();
 	}
 
-	public void testDeletePartRecursive() throws InvalidFormatException {
+    @Test
+	public void deletePartRecursive() throws InvalidFormatException {
 		TreeMap<PackagePartName, String> expectedValues;
 		TreeMap<PackagePartName, String> values;
 
@@ -468,7 +498,8 @@ public final class TestPackage extends T
 	 * Test that we can open a file by path, and then
 	 *  write changes to it.
 	 */
-	public void testOpenFileThenOverwrite() throws Exception {
+    @Test
+	public void openFileThenOverwrite() throws Exception {
         File tempFile = TempFile.createTempFile("poiTesting","tmp");
         File origFile = OpenXML4JTestDataSamples.getSampleFile("TestPackageCommon.docx");
         FileHelper.copyFile(origFile, tempFile);
@@ -505,7 +536,8 @@ public final class TestPackage extends T
      * Test that we can open a file by path, save it
      *  to another file, then delete both
      */
-    public void testOpenFileThenSaveDelete() throws Exception {
+    @Test
+    public void openFileThenSaveDelete() throws Exception {
         File tempFile = TempFile.createTempFile("poiTesting","tmp");
         File tempFile2 = TempFile.createTempFile("poiTesting","tmp");
         File origFile = OpenXML4JTestDataSamples.getSampleFile("TestPackageCommon.docx");
@@ -529,7 +561,8 @@ public final class TestPackage extends T
 		return (ContentTypeManager)f.get(pkg);
 	}
 
-    public void testGetPartsByName() throws Exception {
+    @Test
+    public void getPartsByName() throws Exception {
         String filepath =  OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
 
         OPCPackage pkg = OPCPackage.open(filepath, PackageAccess.READ_WRITE);
@@ -553,7 +586,8 @@ public final class TestPackage extends T
         }
     }
     
-    public void testGetPartSize() throws Exception {
+    @Test
+    public void getPartSize() throws Exception {
        String filepath =  OpenXML4JTestDataSamples.getSampleFileName("sample.docx");
        OPCPackage pkg = OPCPackage.open(filepath, PackageAccess.READ);
        try {
@@ -585,7 +619,8 @@ public final class TestPackage extends T
        }
     }
 
-    public void testReplaceContentType() throws Exception {
+    @Test
+    public void replaceContentType() throws Exception {
         InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
         OPCPackage p = OPCPackage.open(is);
 
@@ -603,4 +638,131 @@ public final class TestPackage extends T
         assertFalse(mgr.isContentTypeRegister("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"));
         assertTrue(mgr.isContentTypeRegister("application/vnd.ms-excel.sheet.macroEnabled.main+xml"));
     }
+
+    @Test(expected=IOException.class)
+    public void zipBombCreateAndHandle() throws Exception {
+        // #50090 / #56865
+        ZipFile zipFile = ZipHelper.openZipFile(OpenXML4JTestDataSamples.getSampleFile("sample.xlsx"));
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        ZipOutputStream append = new ZipOutputStream(bos);
+        // first, copy contents from existing war
+        Enumeration<? extends ZipEntry> entries = zipFile.entries();
+        while (entries.hasMoreElements()) {
+            ZipEntry e2 = entries.nextElement();
+            ZipEntry e = new ZipEntry(e2.getName());
+            e.setTime(e2.getTime());
+            e.setComment(e2.getComment());
+            e.setSize(e2.getSize());
+            
+            append.putNextEntry(e);
+            if (!e.isDirectory()) {
+                InputStream is = zipFile.getInputStream(e);
+                if (e.getName().equals("[Content_Types].xml")) {
+                    ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
+                    IOUtils.copy(is, bos2);
+                    long size = bos2.size()-"</Types>".length();
+                    append.write(bos2.toByteArray(), 0, (int)size);
+                    byte spam[] = new byte[0x7FFF];
+                    for (int i=0; i<spam.length; i++) spam[i] = ' ';
+                    while (size < 0x7FFF0000) {
+                        append.write(spam);
+                        size += spam.length;
+                    }
+                    append.write("</Types>".getBytes());
+                    size += 8;
+                    e.setSize(size);
+                } else {
+                    IOUtils.copy(is, append);
+                }
+            }
+            append.closeEntry();
+        }
+        
+        append.close();
+        zipFile.close();
+
+        byte buf[] = bos.toByteArray();
+        bos = null;
+        
+        Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(buf));
+        wb.getSheetAt(0);
+        wb.close();
+    }
+    
+    @Test
+    public void zipBombCheckSizes() throws Exception {
+        File file = OpenXML4JTestDataSamples.getSampleFile("sample.xlsx");
+
+        try {
+            double min_ratio = Double.MAX_VALUE;
+            long max_size = 0;
+            ZipFile zf = ZipHelper.openZipFile(file);
+            Enumeration<? extends ZipEntry> entries = zf.entries();
+            while (entries.hasMoreElements()) {
+                ZipEntry ze = entries.nextElement();
+                double ratio = (double)ze.getCompressedSize() / (double)ze.getSize();
+                min_ratio = Math.min(min_ratio, ratio);
+                max_size = Math.max(max_size, ze.getSize());
+            }
+            zf.close();
+    
+            // use values close to, but within the limits 
+            ZipSecureFile.setMinInflateRatio(min_ratio-0.002);
+            ZipSecureFile.setMaxEntrySize(max_size+1);
+            Workbook wb = WorkbookFactory.create(file, null, true);
+            wb.close();
+    
+            // check ratio out of bounds
+            ZipSecureFile.setMinInflateRatio(min_ratio+0.002);
+            try {
+                wb = WorkbookFactory.create(file, null, true);
+                wb.close();
+                // this is a bit strange, as there will be different exceptions thrown
+                // depending if this executed via "ant test" or within eclipse
+                // maybe a difference in JDK ...
+            } catch (InvalidFormatException e) {
+                checkForZipBombException(e);
+            } catch (POIXMLException e) {
+                checkForZipBombException(e);
+            }
+    
+            // check max entry size ouf of bounds
+            ZipSecureFile.setMinInflateRatio(min_ratio-0.002);
+            ZipSecureFile.setMaxEntrySize(max_size-1);
+            try {
+                wb = WorkbookFactory.create(file, null, true);
+                wb.close();
+            } catch (InvalidFormatException e) {
+                checkForZipBombException(e);
+            } catch (POIXMLException e) {
+                checkForZipBombException(e);
+            }
+        } finally {
+            // reset otherwise a lot of ooxml tests will fail
+            ZipSecureFile.setMinInflateRatio(0.01d);
+            ZipSecureFile.setMaxEntrySize(0xFFFFFFFFl);            
+        }
+    }
+
+    private void checkForZipBombException(Throwable e) {
+        if(e instanceof InvocationTargetException) {
+            InvocationTargetException t = (InvocationTargetException)e;
+            IOException t2 = (IOException)t.getTargetException();
+            if("Zip bomb detected! Exiting.".equals(t2.getMessage())) {
+                return;
+            }
+        }
+        
+        if ("Zip bomb detected! Exiting.".equals(e.getMessage())) {
+            return;
+        }
+        
+        // recursively check the causes for the message as it can be nested further down in the exception-tree
+        if(e.getCause() != null && e.getCause() != e) {
+            checkForZipBombException(e.getCause());
+            return;
+        }
+
+        throw new IllegalStateException("Expected to catch an Exception because of a detected Zip Bomb, but did not find the related error message in the exception", e);        
+    }
 }

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java Sun Jul 19 19:00:32 2015
@@ -17,6 +17,10 @@
 
 package org.apache.poi.openxml4j.opc.compliance;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
@@ -34,6 +38,8 @@ import org.apache.poi.openxml4j.opc.OPCP
 import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
 import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.TempFile;
 
 /**
  * Test core properties Open Packaging Convention compliance.
@@ -224,4 +230,90 @@ public final class TestOPCComplianceCore
 		String msg = extractInvalidFormatMessage("LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx");
 		assertEquals("The element 'modified' must have the 'xsi:type' attribute with the value 'dcterms:W3CDTF' !", msg);
 	}
+	
+    /**
+     * Document with no core properties - testing at the OPC level,
+     *  saving into a new stream
+     */
+    public void testNoCoreProperties_saveNew() throws Exception {
+        String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
+        OPCPackage pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
+
+        // Verify it has empty properties
+        assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+        assertNotNull(pkg.getPackageProperties());
+        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+        assertNull(pkg.getPackageProperties().getLanguageProperty().getValue());
+
+        // Save and re-load
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        pkg.save(baos);
+        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+        pkg = OPCPackage.open(bais);
+
+        // An Empty Properties part has been added in the save/load
+        assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+        assertNotNull(pkg.getPackageProperties());
+        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+        assertNull(pkg.getPackageProperties().getLanguageProperty().getValue());
+        
+        
+        // Open a new copy of it
+        pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
+        
+        // Save and re-load, without having touched the properties yet
+        baos = new ByteArrayOutputStream();
+        pkg.save(baos);
+        bais = new ByteArrayInputStream(baos.toByteArray());
+        pkg = OPCPackage.open(bais);
+        
+        // Check that this too added empty properties without error
+        assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+        assertNotNull(pkg.getPackageProperties());
+        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+        assertNull(pkg.getPackageProperties().getLanguageProperty().getValue());
+    }
+
+    /**
+     * Document with no core properties - testing at the OPC level,
+     *  from a temp-file, saving in-place
+     */
+    public void testNoCoreProperties_saveInPlace() throws Exception {
+        String sampleFileName = "OPCCompliance_NoCoreProperties.xlsx";
+
+        // Copy this into a temp file, so we can play with it
+        File tmp = TempFile.createTempFile("poi-test", ".opc");
+        FileOutputStream out = new FileOutputStream(tmp);
+        IOUtils.copy(
+                POIDataSamples.getOpenXML4JInstance().openResourceAsStream(sampleFileName),
+                out);
+        out.close();
+
+        // Open it from that temp file
+        OPCPackage pkg = OPCPackage.open(tmp);
+
+        // Empty properties
+        assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+        assertNotNull(pkg.getPackageProperties());
+        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+        assertNull(pkg.getPackageProperties().getLanguageProperty().getValue());
+
+        // Save and close
+        pkg.close();
+
+
+        // Re-open and check
+        pkg = OPCPackage.open(tmp);
+
+        // An Empty Properties part has been added in the save/load
+        assertEquals(1, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+        assertNotNull(pkg.getPackageProperties());
+        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+        assertNull(pkg.getPackageProperties().getLanguageProperty().getValue());
+
+        // Finish and tidy
+        pkg.revert();
+        tmp.delete();
+    }
 }

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java Sun Jul 19 19:00:32 2015
@@ -18,6 +18,8 @@ package org.apache.poi.poifs.crypt;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
@@ -32,6 +34,8 @@ import java.util.Iterator;
 import javax.crypto.Cipher;
 
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.openxml4j.opc.ContentTypes;
+import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.poifs.crypt.agile.AgileEncryptionHeader;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.DocumentNode;
@@ -107,7 +111,7 @@ public class TestEncryptor {
         long decPackLenExpected = decExpected.getLength();
         assertEquals(decPackLenExpected, payloadExpected.length);
 
-        is = nfs.getRoot().createDocumentInputStream("EncryptedPackage");
+        is = nfs.getRoot().createDocumentInputStream(Decryptor.DEFAULT_POIFS_ENTRY);
         is = new BoundedInputStream(is, is.available()-16); // ignore padding block
         byte encPackExpected[] = IOUtils.toByteArray(is);
         is.close();
@@ -159,7 +163,7 @@ public class TestEncryptor {
         
         long decPackLenActual = decActual.getLength();
         
-        is = nfs.getRoot().createDocumentInputStream("EncryptedPackage");
+        is = nfs.getRoot().createDocumentInputStream(Decryptor.DEFAULT_POIFS_ENTRY);
         is = new BoundedInputStream(is, is.available()-16); // ignore padding block
         byte encPackActual[] = IOUtils.toByteArray(is);
         is.close();
@@ -266,6 +270,55 @@ public class TestEncryptor {
         assertArrayEquals(payloadExpected, payloadActual);
     }
     
+    /**
+     * Ensure we can encrypt a package that is missing the Core
+     *  Properties, eg one from dodgy versions of Jasper Reports 
+     * See https://github.com/nestoru/xlsxenc/ and
+     * http://stackoverflow.com/questions/28593223
+     */
+    @Test
+    public void encryptPackageWithoutCoreProperties() throws Exception {
+        // Open our file without core properties
+        File inp = POIDataSamples.getOpenXML4JInstance().getFile("OPCCompliance_NoCoreProperties.xlsx");
+        OPCPackage pkg = OPCPackage.open(inp.getPath());
+        
+        // It doesn't have any core properties yet
+        assertEquals(0, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+        assertNotNull(pkg.getPackageProperties());
+        assertNotNull(pkg.getPackageProperties().getLanguageProperty());
+        assertNull(pkg.getPackageProperties().getLanguageProperty().getValue());
+        
+        // Encrypt it
+        EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
+        NPOIFSFileSystem fs = new NPOIFSFileSystem();
+        
+        Encryptor enc = info.getEncryptor();
+        enc.confirmPassword("password");
+        OutputStream os = enc.getDataStream(fs);
+        pkg.save(os);
+        pkg.revert();
+        
+        // Save the resulting OLE2 document, and re-open it
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        fs.writeFilesystem(baos);
+        
+        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        NPOIFSFileSystem inpFS = new NPOIFSFileSystem(bais);
+        
+        // Check we can decrypt it
+        info = new EncryptionInfo(inpFS);
+        Decryptor d = Decryptor.getInstance(info);
+        assertEquals(true, d.verifyPassword("password"));
+        
+        OPCPackage inpPkg = OPCPackage.open(d.getDataStream(inpFS));
+        
+        // Check it now has empty core properties
+        assertEquals(1, inpPkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size());
+        assertNotNull(inpPkg.getPackageProperties());
+        assertNotNull(inpPkg.getPackageProperties().getLanguageProperty());
+        assertNull(inpPkg.getPackageProperties().getLanguageProperty().getValue());
+    }
+    
     @Test
     @Ignore
     public void inPlaceRewrite() throws Exception {

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSignatureInfo.java Sun Jul 19 19:00:32 2015
@@ -316,7 +316,7 @@ public class TestSignatureInfo {
         signatureConfig.addSignatureFacet(new XAdESXLSignatureFacet());
         
         // check for internet, no error means it works
-        boolean mockTsp = (getAccessError("http://timestamp.comodoca.com/rfc3161", true, 10000) == null);
+        boolean mockTsp = (getAccessError("http://timestamp.comodoca.com/rfc3161", true, 10000) != null);
         
         // http://timestamping.edelweb.fr/service/tsp
         // http://tsa.belgium.be/connect
@@ -382,11 +382,13 @@ public class TestSignatureInfo {
             si.confirmSignature();
         } catch (RuntimeException e) {
             // only allow a ConnectException because of timeout, we see this in Jenkins from time to time...
-            assertNotNull("Only allowing ConnectException here, but had: " + e, e.getCause());
+            if(e.getCause() == null) {
+                throw e;
+            }
             if(!(e.getCause() instanceof ConnectException)) {
                 throw e;
             }
-            assertTrue("Only allowing ConnectException here, but had: " + e, e.getCause().getMessage().contains("timed out"));
+            assertTrue("Only allowing ConnectException with 'timed out' as message here, but had: " + e, e.getCause().getMessage().contains("timed out"));
         }
         
         // verify

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java Sun Jul 19 19:00:32 2015
@@ -17,101 +17,282 @@
 
 package org.apache.poi.ss;
 
+import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.InputStream;
 
+import org.apache.poi.EmptyFileException;
+import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 
 import junit.framework.TestCase;
 
 public final class TestWorkbookFactory extends TestCase {
-	private String xls;
-	private String xlsx;
-	private String txt;
-
-	protected void setUp() {
-		xls = "SampleSS.xls";
-		xlsx = "SampleSS.xlsx";
-		txt = "SampleSS.txt";
-	}
-
-	public void testCreateNative() throws Exception {
-		Workbook wb;
-
-		// POIFS -> hssf
-		wb = WorkbookFactory.create(
-				new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls))
-		);
-		assertNotNull(wb);
-		assertTrue(wb instanceof HSSFWorkbook);
-		wb.close();
-
-		// Package -> xssf
-		wb = WorkbookFactory.create(
-				OPCPackage.open(
+    private String xls;
+    private String xlsx;
+    private String[] xls_prot;
+    private String[] xlsx_prot;
+    private String txt;
+
+    protected void setUp() {
+        xls = "SampleSS.xls";
+        xlsx = "SampleSS.xlsx";
+        xls_prot = new String[] {"password.xls", "password"};
+        xlsx_prot = new String[]{"protected_passtika.xlsx", "tika"};
+        txt = "SampleSS.txt";
+    }
+
+    public void testCreateNative() throws Exception {
+        Workbook wb;
+
+        // POIFS -> hssf
+        wb = WorkbookFactory.create(
+                new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls))
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        // Package -> xssf
+        wb = WorkbookFactory.create(
+                OPCPackage.open(
                         HSSFTestDataSamples.openSampleFileStream(xlsx))
-		);
-		assertNotNull(wb);
-		assertTrue(wb instanceof XSSFWorkbook);
-		// TODO: this re-writes the sample-file?! wb.close();
-	}
-
-	/**
-	 * Creates the appropriate kind of Workbook, but
-	 *  checking the mime magic at the start of the
-	 *  InputStream, then creating what's required.
-	 */
-	public void testCreateGeneric() throws Exception {
-		Workbook wb;
-
-		// InputStream -> either
-		wb = WorkbookFactory.create(
-				HSSFTestDataSamples.openSampleFileStream(xls)
-		);
-		assertNotNull(wb);
-		assertTrue(wb instanceof HSSFWorkbook);
-		wb.close();
-
-		wb = WorkbookFactory.create(
-				HSSFTestDataSamples.openSampleFileStream(xlsx)
-		);
-		assertNotNull(wb);
-		assertTrue(wb instanceof XSSFWorkbook);
-		// TODO: this re-writes the sample-file?! wb.close();
-		
-		// File -> either
-      wb = WorkbookFactory.create(
-            HSSFTestDataSamples.getSampleFile(xls)
-      );
-      assertNotNull(wb);
-      assertTrue(wb instanceof HSSFWorkbook);
-      wb.close();
-
-      wb = WorkbookFactory.create(
-            HSSFTestDataSamples.getSampleFile(xlsx)
-      );
-      assertNotNull(wb);
-      assertTrue(wb instanceof XSSFWorkbook);
-      
-      // TODO: close() re-writes the sample-file?! Resort to revert() for now to close file handle...
-      ((XSSFWorkbook)wb).getPackage().revert();
-
-		// Invalid type -> exception
-		try {
-			InputStream stream = HSSFTestDataSamples.openSampleFileStream(txt);
-			try {
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+        // TODO: this re-writes the sample-file?! wb.close();
+    }
+
+    public void testCreateReadOnly() throws Exception {
+        Workbook wb;
+
+        // POIFS -> hssf
+        wb = WorkbookFactory.create(HSSFTestDataSamples.getSampleFile(xls), null, true);
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        // Package -> xssf
+        wb = WorkbookFactory.create(HSSFTestDataSamples.getSampleFile(xlsx), null, true);
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+        wb.close();
+    }
+
+    /**
+     * Creates the appropriate kind of Workbook, but
+     *  checking the mime magic at the start of the
+     *  InputStream, then creating what's required.
+     */
+    public void testCreateGeneric() throws Exception {
+        Workbook wb;
+
+        // InputStream -> either
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.openSampleFileStream(xls)
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.openSampleFileStream(xlsx)
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+        // TODO: this re-writes the sample-file?! wb.close();
+
+        // File -> either
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.getSampleFile(xls)
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.getSampleFile(xlsx)
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+
+        // TODO: close() re-writes the sample-file?! Resort to revert() for now to close file handle...
+        ((XSSFWorkbook)wb).getPackage().revert();
+
+        // Invalid type -> exception
+        try {
+            InputStream stream = HSSFTestDataSamples.openSampleFileStream(txt);
+            try {
                 wb = WorkbookFactory.create(stream);
-			} finally {
-			    stream.close();
-			}
-			fail();
-		} catch(IllegalArgumentException e) {
-			// Good
-		}
-	}
+            } finally {
+                stream.close();
+            }
+            fail();
+        } catch(IllegalArgumentException e) {
+            // Good
+        }
+    }
+
+    /**
+     * Check that the overloaded stream methods which take passwords work properly
+     */
+    public void testCreateWithPasswordFromStream() throws Exception {
+        Workbook wb;
+
+
+        // Unprotected, no password given, opens normally
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.openSampleFileStream(xls), null
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.openSampleFileStream(xlsx), null
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+
+
+        // Unprotected, wrong password, opens normally
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.openSampleFileStream(xls), "wrong"
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.openSampleFileStream(xlsx), "wrong"
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+
+
+        // Protected, correct password, opens fine
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.openSampleFileStream(xls_prot[0]), xls_prot[1]
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.openSampleFileStream(xlsx_prot[0]), xlsx_prot[1]
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+
+
+        // Protected, wrong password, throws Exception
+        try {
+            wb = WorkbookFactory.create(
+                    HSSFTestDataSamples.openSampleFileStream(xls_prot[0]), "wrong"
+            );
+            fail("Shouldn't be able to open with the wrong password");
+        } catch (EncryptedDocumentException e) {}
+
+        try {
+            wb = WorkbookFactory.create(
+                    HSSFTestDataSamples.openSampleFileStream(xlsx_prot[0]), "wrong"
+            );
+            fail("Shouldn't be able to open with the wrong password");
+        } catch (EncryptedDocumentException e) {}
+    }
+
+    /**
+     * Check that the overloaded file methods which take passwords work properly
+     */
+    public void testCreateWithPasswordFromFile() throws Exception {
+        Workbook wb;
+
+        // Unprotected, no password given, opens normally
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.getSampleFile(xls), null
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.getSampleFile(xlsx), null
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+
+
+        // Unprotected, wrong password, opens normally
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.getSampleFile(xls), "wrong"
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.getSampleFile(xlsx), "wrong"
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+
+
+        // Protected, correct password, opens fine
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.getSampleFile(xls_prot[0]), xls_prot[1]
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof HSSFWorkbook);
+        wb.close();
+
+        wb = WorkbookFactory.create(
+                HSSFTestDataSamples.getSampleFile(xlsx_prot[0]), xlsx_prot[1]
+        );
+        assertNotNull(wb);
+        assertTrue(wb instanceof XSSFWorkbook);
+
+
+        // Protected, wrong password, throws Exception
+        try {
+            wb = WorkbookFactory.create(
+                    HSSFTestDataSamples.getSampleFile(xls_prot[0]), "wrong"
+            );
+            fail("Shouldn't be able to open with the wrong password");
+        } catch (EncryptedDocumentException e) {}
+
+        try {
+            wb = WorkbookFactory.create(
+                    HSSFTestDataSamples.getSampleFile(xlsx_prot[0]), "wrong"
+            );
+            fail("Shouldn't be able to open with the wrong password");
+        } catch (EncryptedDocumentException e) {}
+    }
+    
+    /**
+     * Check that a helpful exception is given on an empty file / stream
+     */
+    public void testEmptyFile() throws Exception {
+        InputStream emptyStream = new ByteArrayInputStream(new byte[0]);
+        File emptyFile = TempFile.createTempFile("empty", ".poi");
+        
+        try {
+            WorkbookFactory.create(emptyStream);
+            fail("Shouldn't be able to create for an empty stream");
+        } catch (EmptyFileException e) {
+        }
+        
+        try {
+            WorkbookFactory.create(emptyFile);
+            fail("Shouldn't be able to create for an empty file");
+        } catch (EmptyFileException e) {
+        }
+        emptyFile.delete();
+    }
 }



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


Mime
View raw message