You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2007/08/23 19:40:25 UTC
svn commit: r569082 - in /poi/trunk/src:
java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java
Author: nick
Date: Thu Aug 23 10:40:24 2007
New Revision: 569082
URL: http://svn.apache.org/viewvc?rev=569082&view=rev
Log:
When writing out a workbook, skip a WORKBOOK stream (if there is one), since we always write out as Workbook + test (bug #43055)
Modified:
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=569082&r1=569081&r2=569082&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Thu Aug 23 10:40:24 2007
@@ -908,7 +908,14 @@
if (preserveNodes) {
List excepts = new ArrayList(1);
+
+ // Don't write out the old Workbook, we'll be doing our new one
excepts.add("Workbook");
+ // If the file had WORKBOOK instead of Workbook, we'll write it
+ // out correctly shortly, so don't include the old one
+ excepts.add("WORKBOOK");
+
+ // Copy over all the other nodes to our new poifs
copyNodes(this.poifs,fs,excepts);
}
fs.writeFilesystem(stream);
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java?rev=569082&r1=569081&r2=569082&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestUppercaseWorkbook.java Thu Aug 23 10:40:24 2007
@@ -16,7 +16,10 @@
*/
package org.apache.poi.hssf.usermodel;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -47,9 +50,76 @@
// Ensure that we have a WORKBOOK entry
fs.getRoot().getEntry("WORKBOOK");
+ // And a summary
+ fs.getRoot().getEntry("\005SummaryInformation");
assertTrue(true);
+
+ // But not a Workbook one
+ try {
+ fs.getRoot().getEntry("Workbook");
+ fail();
+ } catch(FileNotFoundException e) {}
// Try to open the workbook
HSSFWorkbook wb = new HSSFWorkbook(fs);
+ }
+
+ /**
+ * Test that when we write out, we go back to the correct case
+ */
+ public void testWrite() throws Exception {
+ FileInputStream is = new FileInputStream(dirPath + "/" + xlsA);
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+
+ // Open the workbook, not preserving nodes
+ HSSFWorkbook wb = new HSSFWorkbook(fs);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ wb.write(out);
+
+ // Check now
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ POIFSFileSystem fs2 = new POIFSFileSystem(in);
+
+ // Check that we have the new entries
+ fs2.getRoot().getEntry("Workbook");
+ try {
+ fs2.getRoot().getEntry("WORKBOOK");
+ fail();
+ } catch(FileNotFoundException e) {}
+
+ // And it can be opened
+ HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
+ }
+
+ /**
+ * Test that when we write out preserving nodes, we go back to the
+ * correct case
+ */
+ public void testWritePreserve() throws Exception {
+ FileInputStream is = new FileInputStream(dirPath + "/" + xlsA);
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+
+ // Open the workbook, not preserving nodes
+ HSSFWorkbook wb = new HSSFWorkbook(fs,true);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ wb.write(out);
+
+ // Check now
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ POIFSFileSystem fs2 = new POIFSFileSystem(in);
+
+ // Check that we have the new entries
+ fs2.getRoot().getEntry("Workbook");
+ try {
+ fs2.getRoot().getEntry("WORKBOOK");
+ fail();
+ } catch(FileNotFoundException e) {}
+
+ // As we preserved, should also have a few other streams
+ fs2.getRoot().getEntry("\005SummaryInformation");
+
+ // And it can be opened
+ HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org