ASF Bugzilla – Attachment 21594 Details for
Bug 44491
Old-style setting of POIFS properties doesn't work with POI 3.0.2 in all cases
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
The patch
44491.patch (text/plain), 7.81 KB, created by
Yegor Kozlov
on 2008-02-26 07:42:00 UTC
(
hide
)
Description:
The patch
Filename:
MIME Type:
Creator:
Yegor Kozlov
Created:
2008-02-26 07:42:00 UTC
Size:
7.81 KB
patch
obsolete
>Index: src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (revision 631207) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (working copy) >@@ -168,7 +168,7 @@ > > // Read in the HPSF properties > this.filesystem = fs; >- readProperties(); >+ //readProperties(); > > // If we're not preserving nodes, don't track the > // POIFS any more >Index: src/java/org/apache/poi/POIDocument.java >=================================================================== >--- src/java/org/apache/poi/POIDocument.java (revision 631207) >+++ src/java/org/apache/poi/POIDocument.java (working copy) >@@ -54,16 +54,24 @@ > /** For our own logging use */ > protected POILogger logger = POILogFactory.getLogger(this.getClass()); > >- >- /** >+ //set to true in readProperties() >+ protected boolean initialized = false; >+ >+ /** > * Fetch the Document Summary Information of the document > */ >- public DocumentSummaryInformation getDocumentSummaryInformation() { return dsInf; } >+ public DocumentSummaryInformation getDocumentSummaryInformation() { >+ if(!initialized) readProperties(); >+ return dsInf; >+ } > > /** > * Fetch the Summary Information of the document > */ >- public SummaryInformation getSummaryInformation() { return sInf; } >+ public SummaryInformation getSummaryInformation() { >+ if(!initialized) readProperties(); >+ return sInf; >+ } > > /** > * Find, and create objects for, the standard >@@ -89,6 +97,8 @@ > } else if(ps != null) { > logger.log(POILogger.WARN, "SummaryInformation property set came back with wrong class - ", ps.getClass()); > } >+ >+ initialized = true; > } > > /** >@@ -133,7 +143,7 @@ > * @param writtenEntries a list of POIFS entries to add the property names too > */ > protected void writeProperties(POIFSFileSystem outFS, List writtenEntries) throws IOException { >- if(sInf != null) { >+ if(sInf != null) { > writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME,sInf,outFS); > if(writtenEntries != null) { > writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME); >Index: src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java >=================================================================== >--- src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java (revision 0) >+++ src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java (revision 0) >@@ -0,0 +1,98 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+==================================================================== */ >+ >+package org.apache.poi.hssf.usermodel; >+ >+import org.apache.poi.poifs.filesystem.POIFSFileSystem; >+import org.apache.poi.hssf.usermodel.HSSFWorkbook; >+import org.apache.poi.hpsf.SummaryInformation; >+import org.apache.poi.hpsf.PropertySetFactory; >+ >+import java.io.FileInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.ByteArrayInputStream; >+import java.io.File; >+ >+import junit.framework.TestCase; >+ >+/** >+ * Old-style setting of POIFS properties doesn't work with POI 3.0.2 >+ * >+ * @author Yegor Kozlov >+ */ >+public class TestPOIFSProperties extends TestCase{ >+ protected String cwd = System.getProperty("HSSF.testdata.path"); >+ >+ protected String title = "Testing POIFS properties"; >+ >+ public void testFail() throws Exception { >+ FileInputStream is = new FileInputStream(new File(cwd, "Simple.xls")); >+ POIFSFileSystem fs = new POIFSFileSystem(is); >+ is.close(); >+ >+ HSSFWorkbook wb = new HSSFWorkbook(fs); >+ >+ //set POIFS properties after constructing HSSFWorkbook >+ //(a piece of code that used to work up to POI 3.0.2) >+ SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME)); >+ summary1.setTitle(title); >+ //write the modified property back to POIFS >+ fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete(); >+ fs.createDocument(summary1.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME); >+ >+ //save the workbook and read the property >+ ByteArrayOutputStream out = new ByteArrayOutputStream(); >+ wb.write(out); >+ out.close(); >+ >+ POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); >+ SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME)); >+ >+ try { >+ //failing assertion >+ assertEquals(title, summary2.getTitle()); >+ >+ } catch (AssertionError e){ >+ assertTrue(true); >+ } >+ } >+ >+ public void testOK() throws Exception { >+ FileInputStream is = new FileInputStream(new File(cwd, "Simple.xls")); >+ POIFSFileSystem fs = new POIFSFileSystem(is); >+ is.close(); >+ >+ //set POIFS properties before constructing HSSFWorkbook >+ SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME)); >+ summary1.setTitle(title); >+ >+ fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete(); >+ fs.createDocument(summary1.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME); >+ >+ HSSFWorkbook wb = new HSSFWorkbook(fs); >+ >+ ByteArrayOutputStream out = new ByteArrayOutputStream(); >+ wb.write(out); >+ out.close(); >+ >+ //read the property >+ POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); >+ SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME)); >+ assertEquals(title, summary2.getTitle()); >+ >+ } >+} > >Property changes on: src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java >___________________________________________________________________ >Name: svn:executable > + * > >Index: src/testcases/org/apache/poi/TestPOIDocumentMain.java >=================================================================== >--- src/testcases/org/apache/poi/TestPOIDocumentMain.java (revision 631207) >+++ src/testcases/org/apache/poi/TestPOIDocumentMain.java (working copy) >@@ -85,7 +85,8 @@ > public void testWriteProperties() throws Exception { > // Just check we can write them back out into a filesystem > POIFSFileSystem outFS = new POIFSFileSystem(); >- doc.writeProperties(outFS); >+ doc.readProperties(); >+ doc.writeProperties(outFS); > > // Should now hold them > assertNotNull( >@@ -101,7 +102,8 @@ > > // Write them out > POIFSFileSystem outFS = new POIFSFileSystem(); >- doc.writeProperties(outFS); >+ doc.readProperties(); >+ doc.writeProperties(outFS); > outFS.writeFilesystem(baos); > > // Create a new version
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 44491
: 21594