Fix from Yegor from bug #44491 - don't have the new style handy POIDocument property stuff break old style hpsf+hssf use
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@633118 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0677bb2cff
commit
0ecbec584e
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.1-beta1" date="2008-??-??">
|
<release version="3.1-beta1" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">44491 - Don't have the new-style "HPSF properties are always available" affect the old-style use of HPSF alongside HSSF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">44471 - Crystal Reports generates files with short StyleRecords, which isn't allowed in the spec. Work around this</action>
|
<action dev="POI-DEVELOPERS" type="fix">44471 - Crystal Reports generates files with short StyleRecords, which isn't allowed in the spec. Work around this</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">44450 - Support for Lookup, HLookup and VLookup functions</action>
|
<action dev="POI-DEVELOPERS" type="add">44450 - Support for Lookup, HLookup and VLookup functions</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">44449 - Avoid getting confused when two sheets have shared formulas for the same areas, and when the shared formula is set incorrectly</action>
|
<action dev="POI-DEVELOPERS" type="fix">44449 - Avoid getting confused when two sheets have shared formulas for the same areas, and when the shared formula is set incorrectly</action>
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.1-beta1" date="2008-??-??">
|
<release version="3.1-beta1" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">44491 - Don't have the new-style "HPSF properties are always available" affect the old-style use of HPSF alongside HSSF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">44471 - Crystal Reports generates files with short StyleRecords, which isn't allowed in the spec. Work around this</action>
|
<action dev="POI-DEVELOPERS" type="fix">44471 - Crystal Reports generates files with short StyleRecords, which isn't allowed in the spec. Work around this</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">44450 - Support for Lookup, HLookup and VLookup functions</action>
|
<action dev="POI-DEVELOPERS" type="add">44450 - Support for Lookup, HLookup and VLookup functions</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">44449 - Avoid getting confused when two sheets have shared formulas for the same areas, and when the shared formula is set incorrectly</action>
|
<action dev="POI-DEVELOPERS" type="fix">44449 - Avoid getting confused when two sheets have shared formulas for the same areas, and when the shared formula is set incorrectly</action>
|
||||||
|
@ -54,16 +54,24 @@ public abstract class POIDocument {
|
|||||||
/** For our own logging use */
|
/** For our own logging use */
|
||||||
protected POILogger logger = POILogFactory.getLogger(this.getClass());
|
protected POILogger logger = POILogFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
/* Have the property streams been read yet? (Only done on-demand) */
|
||||||
/**
|
protected boolean initialized = false;
|
||||||
|
|
||||||
|
/**
|
||||||
* Fetch the Document Summary Information of the document
|
* 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
|
* 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
|
* Find, and create objects for, the standard
|
||||||
@ -89,6 +97,9 @@ public abstract class POIDocument {
|
|||||||
} else if(ps != null) {
|
} else if(ps != null) {
|
||||||
logger.log(POILogger.WARN, "SummaryInformation property set came back with wrong class - ", ps.getClass());
|
logger.log(POILogger.WARN, "SummaryInformation property set came back with wrong class - ", ps.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark the fact that we've now loaded up the properties
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,7 +144,7 @@ public abstract class POIDocument {
|
|||||||
* @param writtenEntries a list of POIFS entries to add the property names too
|
* @param writtenEntries a list of POIFS entries to add the property names too
|
||||||
*/
|
*/
|
||||||
protected void writeProperties(POIFSFileSystem outFS, List writtenEntries) throws IOException {
|
protected void writeProperties(POIFSFileSystem outFS, List writtenEntries) throws IOException {
|
||||||
if(sInf != null) {
|
if(sInf != null) {
|
||||||
writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME,sInf,outFS);
|
writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME,sInf,outFS);
|
||||||
if(writtenEntries != null) {
|
if(writtenEntries != null) {
|
||||||
writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME);
|
writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME);
|
||||||
|
@ -165,10 +165,7 @@ public class HSSFWorkbook extends POIDocument
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
this.preserveNodes = preserveNodes;
|
this.preserveNodes = preserveNodes;
|
||||||
|
|
||||||
// Read in the HPSF properties
|
|
||||||
this.filesystem = fs;
|
this.filesystem = fs;
|
||||||
readProperties();
|
|
||||||
|
|
||||||
// If we're not preserving nodes, don't track the
|
// If we're not preserving nodes, don't track the
|
||||||
// POIFS any more
|
// POIFS any more
|
||||||
|
@ -85,7 +85,8 @@ public class TestPOIDocumentMain extends TestCase {
|
|||||||
public void testWriteProperties() throws Exception {
|
public void testWriteProperties() throws Exception {
|
||||||
// Just check we can write them back out into a filesystem
|
// Just check we can write them back out into a filesystem
|
||||||
POIFSFileSystem outFS = new POIFSFileSystem();
|
POIFSFileSystem outFS = new POIFSFileSystem();
|
||||||
doc.writeProperties(outFS);
|
doc.readProperties();
|
||||||
|
doc.writeProperties(outFS);
|
||||||
|
|
||||||
// Should now hold them
|
// Should now hold them
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
@ -101,7 +102,8 @@ public class TestPOIDocumentMain extends TestCase {
|
|||||||
|
|
||||||
// Write them out
|
// Write them out
|
||||||
POIFSFileSystem outFS = new POIFSFileSystem();
|
POIFSFileSystem outFS = new POIFSFileSystem();
|
||||||
doc.writeProperties(outFS);
|
doc.readProperties();
|
||||||
|
doc.writeProperties(outFS);
|
||||||
outFS.writeFilesystem(baos);
|
outFS.writeFilesystem(baos);
|
||||||
|
|
||||||
// Create a new version
|
// Create a new version
|
||||||
|
@ -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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user