poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1177409 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/ss/usermodel/ ooxml/testcases/org/apache/poi/ss/ testcases/org/apache/poi/hssf/ testcases/org/apache/poi/hssf/usermodel/
Date Thu, 29 Sep 2011 19:39:52 GMT
Author: nick
Date: Thu Sep 29 19:39:51 2011
New Revision: 1177409

URL: http://svn.apache.org/viewvc?rev=1177409&view=rev
Log:
Allow the passing of a File object to WorkbookFactory.create, which permits lower memory processing
than the InputStream version

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
    poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1177409&r1=1177408&r2=1177409&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Sep 29 19:39:51 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta5" date="2011-??-??">
+           <action dev="poi-developers" type="add">Allow the passing of a File object
to WorkbookFactory.create, which permits lower memory processing than the InputStream version</action>
            <action dev="poi-developers" type="fix">51873 - update HSMF to ignore Outlook
2002 Olk10SideProp entries, which don't behave like normal chunks</action>
            <action dev="poi-developers" type="fix">51850 - support creating comments
in XSSF on an earlier slide when later ones already have them</action>
            <action dev="poi-developers" type="add">51804 - optionally include Master
Slide text in XSLF text extraction, as HSLF already offers</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java?rev=1177409&r1=1177408&r2=1177409&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java Thu Sep 29 19:39:51
2011
@@ -16,6 +16,8 @@
 ==================================================================== */
 package org.apache.poi.ss.usermodel;
 
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
@@ -24,6 +26,8 @@ import org.apache.poi.POIXMLDocument;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
@@ -64,4 +68,21 @@ public class WorkbookFactory {
 		}
 		throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an
OOXML stream");
 	}
+   /**
+    * Creates the appropriate HSSFWorkbook / XSSFWorkbook from
+    *  the given File, which must exist and be readable.
+    */
+	public static Workbook create(File file) throws IOException, InvalidFormatException {
+	   if(! file.exists()) {
+	      throw new FileNotFoundException(file.toString());
+	   }
+	   
+	   try {
+	      NPOIFSFileSystem fs = new NPOIFSFileSystem(file);
+	      return new HSSFWorkbook(fs.getRoot(), true);
+	   } catch(OfficeXmlFileException e) {
+	      OPCPackage pkg = OPCPackage.openOrCreate(file);
+	      return new XSSFWorkbook(pkg);
+	   }
+	}
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java?rev=1177409&r1=1177408&r2=1177409&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java Thu Sep 29 19:39:51
2011
@@ -77,7 +77,21 @@ public final class TestWorkbookFactory e
 		);
 		assertNotNull(wb);
 		assertTrue(wb instanceof XSSFWorkbook);
+		
+		// File -> either
+      wb = WorkbookFactory.create(
+            HSSFTestDataSamples.getSampleFile(xls)
+      );
+      assertNotNull(wb);
+      assertTrue(wb instanceof HSSFWorkbook);
 
+      wb = WorkbookFactory.create(
+            HSSFTestDataSamples.getSampleFile(xlsx)
+      );
+      assertNotNull(wb);
+      assertTrue(wb instanceof XSSFWorkbook);
+
+		// Invalid type -> exception
 		try {
 			wb = WorkbookFactory.create(
 					HSSFTestDataSamples.openSampleFileStream(txt)

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java?rev=1177409&r1=1177408&r2=1177409&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java Thu Sep 29 19:39:51
2011
@@ -38,7 +38,7 @@ public final class HSSFTestDataSamples {
 	public static InputStream openSampleFileStream(String sampleFileName) {
 		return _inst.openResourceAsStream(sampleFileName);
 	}
-	public static File getSampeFile(String sampleFileName) {
+	public static File getSampleFile(String sampleFileName) {
 	   return _inst.getFile(sampleFileName);
 	}
 	public static byte[] getTestDataFileContent(String fileName) {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=1177409&r1=1177408&r2=1177409&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Thu Sep 29
19:39:51 2011
@@ -540,7 +540,7 @@ public final class TestHSSFWorkbook exte
        // Open the two filesystems
        DirectoryNode[] files = new DirectoryNode[2];
        files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"))).getRoot();
-       files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampeFile("Simple.xls"))).getRoot();
+       files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("Simple.xls"))).getRoot();
        
        // Open without preserving nodes 
        for(DirectoryNode dir : files) {
@@ -563,7 +563,7 @@ public final class TestHSSFWorkbook exte
        // Open the two filesystems
        DirectoryNode[] files = new DirectoryNode[2];
        files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"))).getRoot();
-       files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampeFile("WithEmbeddedObjects.xls"))).getRoot();
+       files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithEmbeddedObjects.xls"))).getRoot();
        
        // Check the embedded parts
        for(DirectoryNode root : files) {



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


Mime
View raw message