2007-09-19 11:56:36 +00:00
|
|
|
/* ====================================================================
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
|
|
|
|
import org.apache.poi.hpsf.MutablePropertySet;
|
|
|
|
|
import org.apache.poi.hpsf.PropertySet;
|
|
|
|
|
import org.apache.poi.hpsf.PropertySetFactory;
|
|
|
|
|
import org.apache.poi.hpsf.SummaryInformation;
|
|
|
|
|
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
|
|
|
|
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
|
|
|
|
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
|
|
|
|
import org.apache.poi.poifs.filesystem.Entry;
|
|
|
|
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
|
|
|
import org.apache.poi.util.POILogFactory;
|
|
|
|
|
import org.apache.poi.util.POILogger;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This holds the common functionality for all POI
|
|
|
|
|
* Document classes.
|
|
|
|
|
* Currently, this relates to Document Information Properties
|
|
|
|
|
*
|
|
|
|
|
* @author Nick Burch
|
|
|
|
|
*/
|
|
|
|
|
public abstract class POIDocument {
|
|
|
|
|
/** Holds metadata on our document */
|
|
|
|
|
protected SummaryInformation sInf;
|
|
|
|
|
/** Holds further metadata on our document */
|
|
|
|
|
protected DocumentSummaryInformation dsInf;
|
|
|
|
|
/** The open POIFS FileSystem that contains our document */
|
|
|
|
|
protected POIFSFileSystem filesystem;
|
|
|
|
|
|
|
|
|
|
/** For our own logging use */
|
|
|
|
|
protected POILogger logger = POILogFactory.getLogger(this.getClass());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the Document Summary Information of the document
|
|
|
|
|
*/
|
|
|
|
|
public DocumentSummaryInformation getDocumentSummaryInformation() { return dsInf; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the Summary Information of the document
|
|
|
|
|
*/
|
|
|
|
|
public SummaryInformation getSummaryInformation() { return sInf; }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Find, and create objects for, the standard
|
Merged revisions 618680-620582 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r618680 | nick | 2008-02-05 16:51:29 +0100 (Tue, 05 Feb 2008) | 1 line
Add java.lang.Iterable style methods for iterating over rows and cells, but don't actually implement that, as it wasn't in jdk 1.3 or jdk 1.4, with is rather tedious
........
r618690 | nick | 2008-02-05 17:21:21 +0100 (Tue, 05 Feb 2008) | 1 line
Tweaks to the iterator use guides for hssf
........
r618692 | nick | 2008-02-05 17:32:45 +0100 (Tue, 05 Feb 2008) | 1 line
Few tweaks to the patching guide
........
r618940 | yegor | 2008-02-06 10:47:13 +0100 (Wed, 06 Feb 2008) | 1 line
3.0.2-FINAL released
........
r619001 | nick | 2008-02-06 15:35:05 +0100 (Wed, 06 Feb 2008) | 1 line
Implement hashCode and equals for HSSFFont and HSSFCellStyle
........
r619310 | yegor | 2008-02-07 09:56:59 +0100 (Thu, 07 Feb 2008) | 1 line
support for excel hypelrinks
........
r619382 | nick | 2008-02-07 13:39:12 +0100 (Thu, 07 Feb 2008) | 1 line
Patch from bug #44373 - Have HSSFDateUtil.isADateFormat support more date formats
........
r619502 | nick | 2008-02-07 17:53:23 +0100 (Thu, 07 Feb 2008) | 1 line
Handle timezones better with cell.setCellValue(Calendar), so now 20:00-03:00, 20:00+00:00 and 20:00+03:00 will all be recorded as 20:00, and not 17:00 / 20:00 / 23:00 (pass a Date not a Calendar for old behaviour) - patch from bug #38641
........
r619509 | nick | 2008-02-07 18:12:09 +0100 (Thu, 07 Feb 2008) | 1 line
Add (disabled) failing testcase for bug #44375
........
r619848 | klute | 2008-02-08 12:55:43 +0100 (Fri, 08 Feb 2008) | 1 line
- Fixed bug 44375 - HPSF now copes with a broken dictionary in Document Summary Information stream. RuntimeExceptions that occured when trying to read bogus data are now caught. Dictionary entries up to but not including the bogus one are preserved, the rest is ignored.
........
r619849 | klute | 2008-02-08 12:56:11 +0100 (Fri, 08 Feb 2008) | 1 line
- Fixed bug 44375 - HPSF now copes with a broken dictionary in Document Summary Information stream. RuntimeExceptions that occured when trying to read bogus data are now caught. Dictionary entries up to but not including the bogus one are preserved, the rest is ignored.
........
r619851 | nick | 2008-02-08 13:02:10 +0100 (Fri, 08 Feb 2008) | 1 line
Copy Rainer's change note from changes.xml to status.xml, as it's needed in both
........
r619968 | nick | 2008-02-08 19:17:29 +0100 (Fri, 08 Feb 2008) | 1 line
Tweak layout
........
r620341 | nick | 2008-02-10 22:54:13 +0100 (Sun, 10 Feb 2008) | 1 line
Test for bug #42564 - appears to already be fixed
........
r620557 | nick | 2008-02-11 18:55:09 +0100 (Mon, 11 Feb 2008) | 1 line
Another test relating to bug #42564 - this one is still failing
........
r620582 | nick | 2008-02-11 20:14:04 +0100 (Mon, 11 Feb 2008) | 1 line
If we have a document with a hpsf stream that exists, but is of the wrong type, then log a warning but continue
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@627544 13f79535-47bb-0310-9956-ffa450edef68
2008-02-13 17:34:43 +00:00
|
|
|
* Documment Information Properties (HPSF).
|
|
|
|
|
* If a given property set is missing or corrupt,
|
|
|
|
|
* it will remain null;
|
2007-09-19 11:56:36 +00:00
|
|
|
*/
|
|
|
|
|
protected void readProperties() {
|
Merged revisions 618680-620582 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r618680 | nick | 2008-02-05 16:51:29 +0100 (Tue, 05 Feb 2008) | 1 line
Add java.lang.Iterable style methods for iterating over rows and cells, but don't actually implement that, as it wasn't in jdk 1.3 or jdk 1.4, with is rather tedious
........
r618690 | nick | 2008-02-05 17:21:21 +0100 (Tue, 05 Feb 2008) | 1 line
Tweaks to the iterator use guides for hssf
........
r618692 | nick | 2008-02-05 17:32:45 +0100 (Tue, 05 Feb 2008) | 1 line
Few tweaks to the patching guide
........
r618940 | yegor | 2008-02-06 10:47:13 +0100 (Wed, 06 Feb 2008) | 1 line
3.0.2-FINAL released
........
r619001 | nick | 2008-02-06 15:35:05 +0100 (Wed, 06 Feb 2008) | 1 line
Implement hashCode and equals for HSSFFont and HSSFCellStyle
........
r619310 | yegor | 2008-02-07 09:56:59 +0100 (Thu, 07 Feb 2008) | 1 line
support for excel hypelrinks
........
r619382 | nick | 2008-02-07 13:39:12 +0100 (Thu, 07 Feb 2008) | 1 line
Patch from bug #44373 - Have HSSFDateUtil.isADateFormat support more date formats
........
r619502 | nick | 2008-02-07 17:53:23 +0100 (Thu, 07 Feb 2008) | 1 line
Handle timezones better with cell.setCellValue(Calendar), so now 20:00-03:00, 20:00+00:00 and 20:00+03:00 will all be recorded as 20:00, and not 17:00 / 20:00 / 23:00 (pass a Date not a Calendar for old behaviour) - patch from bug #38641
........
r619509 | nick | 2008-02-07 18:12:09 +0100 (Thu, 07 Feb 2008) | 1 line
Add (disabled) failing testcase for bug #44375
........
r619848 | klute | 2008-02-08 12:55:43 +0100 (Fri, 08 Feb 2008) | 1 line
- Fixed bug 44375 - HPSF now copes with a broken dictionary in Document Summary Information stream. RuntimeExceptions that occured when trying to read bogus data are now caught. Dictionary entries up to but not including the bogus one are preserved, the rest is ignored.
........
r619849 | klute | 2008-02-08 12:56:11 +0100 (Fri, 08 Feb 2008) | 1 line
- Fixed bug 44375 - HPSF now copes with a broken dictionary in Document Summary Information stream. RuntimeExceptions that occured when trying to read bogus data are now caught. Dictionary entries up to but not including the bogus one are preserved, the rest is ignored.
........
r619851 | nick | 2008-02-08 13:02:10 +0100 (Fri, 08 Feb 2008) | 1 line
Copy Rainer's change note from changes.xml to status.xml, as it's needed in both
........
r619968 | nick | 2008-02-08 19:17:29 +0100 (Fri, 08 Feb 2008) | 1 line
Tweak layout
........
r620341 | nick | 2008-02-10 22:54:13 +0100 (Sun, 10 Feb 2008) | 1 line
Test for bug #42564 - appears to already be fixed
........
r620557 | nick | 2008-02-11 18:55:09 +0100 (Mon, 11 Feb 2008) | 1 line
Another test relating to bug #42564 - this one is still failing
........
r620582 | nick | 2008-02-11 20:14:04 +0100 (Mon, 11 Feb 2008) | 1 line
If we have a document with a hpsf stream that exists, but is of the wrong type, then log a warning but continue
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@627544 13f79535-47bb-0310-9956-ffa450edef68
2008-02-13 17:34:43 +00:00
|
|
|
PropertySet ps;
|
|
|
|
|
|
2007-09-19 11:56:36 +00:00
|
|
|
// DocumentSummaryInformation
|
Merged revisions 618680-620582 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r618680 | nick | 2008-02-05 16:51:29 +0100 (Tue, 05 Feb 2008) | 1 line
Add java.lang.Iterable style methods for iterating over rows and cells, but don't actually implement that, as it wasn't in jdk 1.3 or jdk 1.4, with is rather tedious
........
r618690 | nick | 2008-02-05 17:21:21 +0100 (Tue, 05 Feb 2008) | 1 line
Tweaks to the iterator use guides for hssf
........
r618692 | nick | 2008-02-05 17:32:45 +0100 (Tue, 05 Feb 2008) | 1 line
Few tweaks to the patching guide
........
r618940 | yegor | 2008-02-06 10:47:13 +0100 (Wed, 06 Feb 2008) | 1 line
3.0.2-FINAL released
........
r619001 | nick | 2008-02-06 15:35:05 +0100 (Wed, 06 Feb 2008) | 1 line
Implement hashCode and equals for HSSFFont and HSSFCellStyle
........
r619310 | yegor | 2008-02-07 09:56:59 +0100 (Thu, 07 Feb 2008) | 1 line
support for excel hypelrinks
........
r619382 | nick | 2008-02-07 13:39:12 +0100 (Thu, 07 Feb 2008) | 1 line
Patch from bug #44373 - Have HSSFDateUtil.isADateFormat support more date formats
........
r619502 | nick | 2008-02-07 17:53:23 +0100 (Thu, 07 Feb 2008) | 1 line
Handle timezones better with cell.setCellValue(Calendar), so now 20:00-03:00, 20:00+00:00 and 20:00+03:00 will all be recorded as 20:00, and not 17:00 / 20:00 / 23:00 (pass a Date not a Calendar for old behaviour) - patch from bug #38641
........
r619509 | nick | 2008-02-07 18:12:09 +0100 (Thu, 07 Feb 2008) | 1 line
Add (disabled) failing testcase for bug #44375
........
r619848 | klute | 2008-02-08 12:55:43 +0100 (Fri, 08 Feb 2008) | 1 line
- Fixed bug 44375 - HPSF now copes with a broken dictionary in Document Summary Information stream. RuntimeExceptions that occured when trying to read bogus data are now caught. Dictionary entries up to but not including the bogus one are preserved, the rest is ignored.
........
r619849 | klute | 2008-02-08 12:56:11 +0100 (Fri, 08 Feb 2008) | 1 line
- Fixed bug 44375 - HPSF now copes with a broken dictionary in Document Summary Information stream. RuntimeExceptions that occured when trying to read bogus data are now caught. Dictionary entries up to but not including the bogus one are preserved, the rest is ignored.
........
r619851 | nick | 2008-02-08 13:02:10 +0100 (Fri, 08 Feb 2008) | 1 line
Copy Rainer's change note from changes.xml to status.xml, as it's needed in both
........
r619968 | nick | 2008-02-08 19:17:29 +0100 (Fri, 08 Feb 2008) | 1 line
Tweak layout
........
r620341 | nick | 2008-02-10 22:54:13 +0100 (Sun, 10 Feb 2008) | 1 line
Test for bug #42564 - appears to already be fixed
........
r620557 | nick | 2008-02-11 18:55:09 +0100 (Mon, 11 Feb 2008) | 1 line
Another test relating to bug #42564 - this one is still failing
........
r620582 | nick | 2008-02-11 20:14:04 +0100 (Mon, 11 Feb 2008) | 1 line
If we have a document with a hpsf stream that exists, but is of the wrong type, then log a warning but continue
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@627544 13f79535-47bb-0310-9956-ffa450edef68
2008-02-13 17:34:43 +00:00
|
|
|
ps = getPropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
|
|
|
|
|
if(ps != null && ps instanceof DocumentSummaryInformation) {
|
|
|
|
|
dsInf = (DocumentSummaryInformation)ps;
|
|
|
|
|
} else if(ps != null) {
|
|
|
|
|
logger.log(POILogger.WARN, "DocumentSummaryInformation property set came back with wrong class - ", ps.getClass());
|
|
|
|
|
}
|
2007-09-19 11:56:36 +00:00
|
|
|
|
|
|
|
|
// SummaryInformation
|
Merged revisions 618680-620582 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r618680 | nick | 2008-02-05 16:51:29 +0100 (Tue, 05 Feb 2008) | 1 line
Add java.lang.Iterable style methods for iterating over rows and cells, but don't actually implement that, as it wasn't in jdk 1.3 or jdk 1.4, with is rather tedious
........
r618690 | nick | 2008-02-05 17:21:21 +0100 (Tue, 05 Feb 2008) | 1 line
Tweaks to the iterator use guides for hssf
........
r618692 | nick | 2008-02-05 17:32:45 +0100 (Tue, 05 Feb 2008) | 1 line
Few tweaks to the patching guide
........
r618940 | yegor | 2008-02-06 10:47:13 +0100 (Wed, 06 Feb 2008) | 1 line
3.0.2-FINAL released
........
r619001 | nick | 2008-02-06 15:35:05 +0100 (Wed, 06 Feb 2008) | 1 line
Implement hashCode and equals for HSSFFont and HSSFCellStyle
........
r619310 | yegor | 2008-02-07 09:56:59 +0100 (Thu, 07 Feb 2008) | 1 line
support for excel hypelrinks
........
r619382 | nick | 2008-02-07 13:39:12 +0100 (Thu, 07 Feb 2008) | 1 line
Patch from bug #44373 - Have HSSFDateUtil.isADateFormat support more date formats
........
r619502 | nick | 2008-02-07 17:53:23 +0100 (Thu, 07 Feb 2008) | 1 line
Handle timezones better with cell.setCellValue(Calendar), so now 20:00-03:00, 20:00+00:00 and 20:00+03:00 will all be recorded as 20:00, and not 17:00 / 20:00 / 23:00 (pass a Date not a Calendar for old behaviour) - patch from bug #38641
........
r619509 | nick | 2008-02-07 18:12:09 +0100 (Thu, 07 Feb 2008) | 1 line
Add (disabled) failing testcase for bug #44375
........
r619848 | klute | 2008-02-08 12:55:43 +0100 (Fri, 08 Feb 2008) | 1 line
- Fixed bug 44375 - HPSF now copes with a broken dictionary in Document Summary Information stream. RuntimeExceptions that occured when trying to read bogus data are now caught. Dictionary entries up to but not including the bogus one are preserved, the rest is ignored.
........
r619849 | klute | 2008-02-08 12:56:11 +0100 (Fri, 08 Feb 2008) | 1 line
- Fixed bug 44375 - HPSF now copes with a broken dictionary in Document Summary Information stream. RuntimeExceptions that occured when trying to read bogus data are now caught. Dictionary entries up to but not including the bogus one are preserved, the rest is ignored.
........
r619851 | nick | 2008-02-08 13:02:10 +0100 (Fri, 08 Feb 2008) | 1 line
Copy Rainer's change note from changes.xml to status.xml, as it's needed in both
........
r619968 | nick | 2008-02-08 19:17:29 +0100 (Fri, 08 Feb 2008) | 1 line
Tweak layout
........
r620341 | nick | 2008-02-10 22:54:13 +0100 (Sun, 10 Feb 2008) | 1 line
Test for bug #42564 - appears to already be fixed
........
r620557 | nick | 2008-02-11 18:55:09 +0100 (Mon, 11 Feb 2008) | 1 line
Another test relating to bug #42564 - this one is still failing
........
r620582 | nick | 2008-02-11 20:14:04 +0100 (Mon, 11 Feb 2008) | 1 line
If we have a document with a hpsf stream that exists, but is of the wrong type, then log a warning but continue
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@627544 13f79535-47bb-0310-9956-ffa450edef68
2008-02-13 17:34:43 +00:00
|
|
|
ps = getPropertySet(SummaryInformation.DEFAULT_STREAM_NAME);
|
|
|
|
|
if(ps instanceof SummaryInformation) {
|
|
|
|
|
sInf = (SummaryInformation)ps;
|
|
|
|
|
} else if(ps != null) {
|
|
|
|
|
logger.log(POILogger.WARN, "SummaryInformation property set came back with wrong class - ", ps.getClass());
|
|
|
|
|
}
|
2007-09-19 11:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For a given named property entry, either return it or null if
|
|
|
|
|
* if it wasn't found
|
|
|
|
|
*/
|
|
|
|
|
protected PropertySet getPropertySet(String setName) {
|
|
|
|
|
DocumentInputStream dis;
|
|
|
|
|
try {
|
|
|
|
|
// Find the entry, and get an input stream for it
|
|
|
|
|
dis = filesystem.createDocumentInputStream(setName);
|
|
|
|
|
} catch(IOException ie) {
|
|
|
|
|
// Oh well, doesn't exist
|
2007-09-19 14:40:44 +00:00
|
|
|
logger.log(POILogger.WARN, "Error getting property set with name " + setName + "\n" + ie);
|
2007-09-19 11:56:36 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Create the Property Set
|
|
|
|
|
PropertySet set = PropertySetFactory.create(dis);
|
|
|
|
|
return set;
|
|
|
|
|
} catch(IOException ie) {
|
|
|
|
|
// Must be corrupt or something like that
|
2007-09-19 14:40:44 +00:00
|
|
|
logger.log(POILogger.WARN, "Error creating property set with name " + setName + "\n" + ie);
|
2007-09-19 11:56:36 +00:00
|
|
|
} catch(org.apache.poi.hpsf.HPSFException he) {
|
|
|
|
|
// Oh well, doesn't exist
|
2007-09-19 14:40:44 +00:00
|
|
|
logger.log(POILogger.WARN, "Error creating property set with name " + setName + "\n" + he);
|
2007-09-19 11:56:36 +00:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Writes out the standard Documment Information Properties (HPSF)
|
|
|
|
|
* @param outFS the POIFSFileSystem to write the properties into
|
|
|
|
|
*/
|
|
|
|
|
protected void writeProperties(POIFSFileSystem outFS) throws IOException {
|
|
|
|
|
writeProperties(outFS, null);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Writes out the standard Documment Information Properties (HPSF)
|
|
|
|
|
* @param outFS the POIFSFileSystem to write the properties into
|
|
|
|
|
* @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) {
|
|
|
|
|
writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME,sInf,outFS);
|
|
|
|
|
if(writtenEntries != null) {
|
|
|
|
|
writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(dsInf != null) {
|
|
|
|
|
writePropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME,dsInf,outFS);
|
|
|
|
|
if(writtenEntries != null) {
|
|
|
|
|
writtenEntries.add(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Writes out a given ProperySet
|
|
|
|
|
* @param name the (POIFS Level) name of the property to write
|
|
|
|
|
* @param set the PropertySet to write out
|
|
|
|
|
* @param outFS the POIFSFileSystem to write the property into
|
|
|
|
|
*/
|
|
|
|
|
protected void writePropertySet(String name, PropertySet set, POIFSFileSystem outFS) throws IOException {
|
|
|
|
|
try {
|
|
|
|
|
MutablePropertySet mSet = new MutablePropertySet(set);
|
|
|
|
|
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
|
|
mSet.write(bOut);
|
|
|
|
|
byte[] data = bOut.toByteArray();
|
|
|
|
|
ByteArrayInputStream bIn = new ByteArrayInputStream(data);
|
|
|
|
|
outFS.createDocument(bIn,name);
|
|
|
|
|
|
|
|
|
|
logger.log(POILogger.INFO, "Wrote property set " + name + " of size " + data.length);
|
|
|
|
|
} catch(org.apache.poi.hpsf.WritingNotSupportedException wnse) {
|
|
|
|
|
System.err.println("Couldn't write property set with name " + name + " as not supported by HPSF yet");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copies nodes from one POIFS to the other minus the excepts
|
|
|
|
|
* @param source is the source POIFS to copy from
|
|
|
|
|
* @param target is the target POIFS to copy to
|
|
|
|
|
* @param excepts is a list of Strings specifying what nodes NOT to copy
|
|
|
|
|
*/
|
|
|
|
|
protected void copyNodes(POIFSFileSystem source, POIFSFileSystem target,
|
|
|
|
|
List excepts) throws IOException {
|
|
|
|
|
//System.err.println("CopyNodes called");
|
|
|
|
|
|
|
|
|
|
DirectoryEntry root = source.getRoot();
|
|
|
|
|
DirectoryEntry newRoot = target.getRoot();
|
|
|
|
|
|
|
|
|
|
Iterator entries = root.getEntries();
|
|
|
|
|
|
|
|
|
|
while (entries.hasNext()) {
|
|
|
|
|
Entry entry = (Entry)entries.next();
|
|
|
|
|
if (!isInList(entry.getName(), excepts)) {
|
|
|
|
|
copyNodeRecursively(entry,newRoot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks to see if the String is in the list, used when copying
|
|
|
|
|
* nodes between one POIFS and another
|
|
|
|
|
*/
|
|
|
|
|
private boolean isInList(String entry, List list) {
|
|
|
|
|
for (int k = 0; k < list.size(); k++) {
|
|
|
|
|
if (list.get(k).equals(entry)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copies an Entry into a target POIFS directory, recursively
|
|
|
|
|
*/
|
|
|
|
|
private void copyNodeRecursively(Entry entry, DirectoryEntry target)
|
|
|
|
|
throws IOException {
|
|
|
|
|
//System.err.println("copyNodeRecursively called with "+entry.getName()+
|
|
|
|
|
// ","+target.getName());
|
|
|
|
|
DirectoryEntry newTarget = null;
|
|
|
|
|
if (entry.isDirectoryEntry()) {
|
|
|
|
|
newTarget = target.createDirectory(entry.getName());
|
|
|
|
|
Iterator entries = ((DirectoryEntry)entry).getEntries();
|
|
|
|
|
|
|
|
|
|
while (entries.hasNext()) {
|
|
|
|
|
copyNodeRecursively((Entry)entries.next(),newTarget);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
DocumentEntry dentry = (DocumentEntry)entry;
|
|
|
|
|
DocumentInputStream dstream = new DocumentInputStream(dentry);
|
|
|
|
|
target.createDocument(dentry.getName(),dstream);
|
|
|
|
|
dstream.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|