View | Details | Raw Unified | Return to bug 44491
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (-1 / +1 lines)
Lines 168-174 Link Here
168
168
169
        // Read in the HPSF properties
169
        // Read in the HPSF properties
170
        this.filesystem = fs;
170
        this.filesystem = fs;
171
        readProperties();
171
        //readProperties();
172
        
172
        
173
        // If we're not preserving nodes, don't track the
173
        // If we're not preserving nodes, don't track the
174
        //  POIFS any more
174
        //  POIFS any more
(-)src/java/org/apache/poi/POIDocument.java (-5 / +15 lines)
Lines 54-69 Link Here
54
	/** For our own logging use */
54
	/** For our own logging use */
55
	protected POILogger logger = POILogFactory.getLogger(this.getClass());
55
	protected POILogger logger = POILogFactory.getLogger(this.getClass());
56
56
57
	
57
    //set to true in readProperties()  
58
	/** 
58
    protected boolean initialized = false;
59
60
	/**
59
	 * Fetch the Document Summary Information of the document
61
	 * Fetch the Document Summary Information of the document
60
	 */
62
	 */
61
	public DocumentSummaryInformation getDocumentSummaryInformation() { return dsInf; }
63
	public DocumentSummaryInformation getDocumentSummaryInformation() {
64
        if(!initialized) readProperties();
65
        return dsInf;
66
    }
62
67
63
	/** 
68
	/** 
64
	 * Fetch the Summary Information of the document
69
	 * Fetch the Summary Information of the document
65
	 */
70
	 */
66
	public SummaryInformation getSummaryInformation() { return sInf; }
71
	public SummaryInformation getSummaryInformation() {
72
        if(!initialized) readProperties();
73
        return sInf;
74
    }
67
75
68
	/**
76
	/**
69
	 * Find, and create objects for, the standard
77
	 * Find, and create objects for, the standard
Lines 89-94 Link Here
89
		} else if(ps != null) {
97
		} else if(ps != null) {
90
			logger.log(POILogger.WARN, "SummaryInformation property set came back with wrong class - ", ps.getClass());
98
			logger.log(POILogger.WARN, "SummaryInformation property set came back with wrong class - ", ps.getClass());
91
		}
99
		}
100
101
        initialized = true;
92
	}
102
	}
93
103
94
	/** 
104
	/** 
Lines 133-139 Link Here
133
	 * @param writtenEntries a list of POIFS entries to add the property names too
143
	 * @param writtenEntries a list of POIFS entries to add the property names too
134
	 */
144
	 */
135
	protected void writeProperties(POIFSFileSystem outFS, List writtenEntries) throws IOException {
145
	protected void writeProperties(POIFSFileSystem outFS, List writtenEntries) throws IOException {
136
		if(sInf != null) {
146
        if(sInf != null) {
137
			writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME,sInf,outFS);
147
			writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME,sInf,outFS);
138
			if(writtenEntries != null) {
148
			if(writtenEntries != null) {
139
				writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME);
149
				writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME);
(-)src/testcases/org/apache/poi/hssf/usermodel/TestPOIFSProperties.java (+98 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.usermodel;
19
20
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
22
import org.apache.poi.hpsf.SummaryInformation;
23
import org.apache.poi.hpsf.PropertySetFactory;
24
25
import java.io.FileInputStream;
26
import java.io.ByteArrayOutputStream;
27
import java.io.ByteArrayInputStream;
28
import java.io.File;
29
30
import junit.framework.TestCase;
31
32
/**
33
 * Old-style setting of POIFS properties doesn't work with POI 3.0.2
34
 *
35
 * @author Yegor Kozlov
36
 */
37
public class TestPOIFSProperties extends TestCase{
38
    protected String cwd = System.getProperty("HSSF.testdata.path");
39
40
    protected String title = "Testing POIFS properties";
41
42
    public void testFail() throws Exception {
43
        FileInputStream is = new FileInputStream(new File(cwd, "Simple.xls"));
44
        POIFSFileSystem fs = new POIFSFileSystem(is);
45
        is.close();
46
47
        HSSFWorkbook wb = new HSSFWorkbook(fs);
48
49
        //set POIFS properties after constructing HSSFWorkbook
50
        //(a piece of code that used to work up to POI 3.0.2)
51
        SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
52
        summary1.setTitle(title);
53
        //write the modified property back to POIFS
54
        fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
55
        fs.createDocument(summary1.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);
56
57
        //save the workbook and read the property
58
        ByteArrayOutputStream out = new ByteArrayOutputStream();
59
        wb.write(out);
60
        out.close();
61
62
        POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
63
        SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
64
65
        try {
66
            //failing assertion
67
            assertEquals(title, summary2.getTitle());
68
69
        } catch (AssertionError e){
70
            assertTrue(true);
71
        }
72
    }
73
74
    public void testOK() throws Exception {
75
        FileInputStream is = new FileInputStream(new File(cwd, "Simple.xls"));
76
        POIFSFileSystem fs = new POIFSFileSystem(is);
77
        is.close();
78
79
        //set POIFS properties before constructing HSSFWorkbook
80
        SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
81
        summary1.setTitle(title);
82
83
        fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
84
        fs.createDocument(summary1.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);
85
86
        HSSFWorkbook wb = new HSSFWorkbook(fs);
87
88
        ByteArrayOutputStream out = new ByteArrayOutputStream();
89
        wb.write(out);
90
        out.close();
91
92
        //read the property
93
        POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
94
        SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
95
        assertEquals(title, summary2.getTitle());
96
97
    }
98
}
0
  + *
99
  + *
(-)src/testcases/org/apache/poi/TestPOIDocumentMain.java (-2 / +4 lines)
Lines 85-91 Link Here
85
    public void testWriteProperties() throws Exception {
85
    public void testWriteProperties() throws Exception {
86
    	// Just check we can write them back out into a filesystem
86
    	// Just check we can write them back out into a filesystem
87
    	POIFSFileSystem outFS = new POIFSFileSystem();
87
    	POIFSFileSystem outFS = new POIFSFileSystem();
88
    	doc.writeProperties(outFS);
88
    	doc.readProperties();
89
        doc.writeProperties(outFS);
89
    	
90
    	
90
    	// Should now hold them
91
    	// Should now hold them
91
    	assertNotNull(
92
    	assertNotNull(
Lines 101-107 Link Here
101
		
102
		
102
    	// Write them out
103
    	// Write them out
103
    	POIFSFileSystem outFS = new POIFSFileSystem();
104
    	POIFSFileSystem outFS = new POIFSFileSystem();
104
    	doc.writeProperties(outFS);
105
    	doc.readProperties();
106
        doc.writeProperties(outFS);
105
    	outFS.writeFilesystem(baos);
107
    	outFS.writeFilesystem(baos);
106
    	
108
    	
107
    	// Create a new version
109
    	// Create a new version

Return to bug 44491