aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2015-05-11 18:04:30 +0000
committerNick Burch <nick@apache.org>2015-05-11 18:04:30 +0000
commit32579cda68087cce7ccaab56240d6bfa7e59ec4d (patch)
treee9e1f4616b5b300a94280ad8b3079e27a17ccb81 /src/java/org
parent680740dc252be1a172dc5d298b4ee09b30431665 (diff)
downloadpoi-32579cda68087cce7ccaab56240d6bfa7e59ec4d.tar.gz
poi-32579cda68087cce7ccaab56240d6bfa7e59ec4d.zip
#56791 More updates from OPOIFS to NPOIFS
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678783 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/poi/POIDocument.java57
-rw-r--r--src/java/org/apache/poi/POIOLE2TextExtractor.java14
-rw-r--r--src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java2
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java2
-rw-r--r--src/java/org/apache/poi/poifs/filesystem/EntryUtils.java39
5 files changed, 68 insertions, 46 deletions
diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java
index bcef600549..50c088ba7b 100644
--- a/src/java/org/apache/poi/POIDocument.java
+++ b/src/java/org/apache/poi/POIDocument.java
@@ -30,14 +30,10 @@ import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.poifs.crypt.EncryptionInfo;
-import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
-import org.apache.poi.poifs.filesystem.Entry;
-import org.apache.poi.poifs.filesystem.EntryUtils;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
@@ -45,8 +41,6 @@ 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 */
@@ -71,14 +65,6 @@ public abstract class POIDocument {
this.directory = dir;
}
- /**
- * @deprecated use {@link POIDocument#POIDocument(DirectoryNode)} instead
- */
- @Deprecated
- protected POIDocument(DirectoryNode dir, POIFSFileSystem fs) {
- this.directory = dir;
- }
-
protected POIDocument(POIFSFileSystem fs) {
this(fs.getRoot());
}
@@ -179,12 +165,13 @@ public abstract class POIDocument {
protected PropertySet getPropertySet(String setName, EncryptionInfo encryptionInfo) {
DirectoryNode dirNode = directory;
+ NPOIFSFileSystem encPoifs = null;
if (encryptionInfo != null) {
try {
InputStream is = encryptionInfo.getDecryptor().getDataStream(directory);
- NPOIFSFileSystem poifs = new NPOIFSFileSystem(is);
+ encPoifs = new NPOIFSFileSystem(is);
is.close();
- dirNode = poifs.getRoot();
+ dirNode = encPoifs.getRoot();
} catch (Exception e) {
logger.log(POILogger.ERROR, "Error getting encrypted property set with name " + setName, e);
return null;
@@ -208,6 +195,11 @@ public abstract class POIDocument {
try {
// Create the Property Set
PropertySet set = PropertySetFactory.create(dis);
+ // Tidy up if needed
+ if (encPoifs != null) {
+ encPoifs.close();
+ }
+ // Return the properties
return set;
} catch(IOException ie) {
// Must be corrupt or something like that
@@ -218,26 +210,39 @@ public abstract class POIDocument {
}
return null;
}
+
+ /**
+ * Writes out the updated standard Document Information Properties (HPSF)
+ * into the currently open NPOIFSFileSystem
+ * TODO Implement in-place update
+ *
+ * @throws IOException if an error when writing to the open
+ * {@link NPOIFSFileSystem} occurs
+ * TODO throws exception if open from stream not file
+ */
+ protected void writeProperties() throws IOException {
+ throw new IllegalStateException("In-place write is not yet supported");
+ }
/**
- * Writes out the standard Documment Information Properties (HPSF)
+ * Writes out the standard Document Information Properties (HPSF)
* @param outFS the POIFSFileSystem to write the properties into
*
* @throws IOException if an error when writing to the
- * {@link POIFSFileSystem} occurs
+ * {@link NPOIFSFileSystem} occurs
*/
- protected void writeProperties(POIFSFileSystem outFS) throws IOException {
+ protected void writeProperties(NPOIFSFileSystem outFS) throws IOException {
writeProperties(outFS, null);
}
/**
- * Writes out the standard Documment Information Properties (HPSF)
- * @param outFS the POIFSFileSystem to write the properties into
+ * Writes out the standard Document Information Properties (HPSF)
+ * @param outFS the NPOIFSFileSystem to write the properties into
* @param writtenEntries a list of POIFS entries to add the property names too
*
* @throws IOException if an error when writing to the
- * {@link POIFSFileSystem} occurs
+ * {@link NPOIFSFileSystem} occurs
*/
- protected void writeProperties(POIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
+ protected void writeProperties(NPOIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
SummaryInformation si = getSummaryInformation();
if (si != null) {
writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME, si, outFS);
@@ -258,12 +263,12 @@ public abstract class POIDocument {
* 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
+ * @param outFS the NPOIFSFileSystem to write the property into
*
* @throws IOException if an error when writing to the
- * {@link POIFSFileSystem} occurs
+ * {@link NPOIFSFileSystem} occurs
*/
- protected void writePropertySet(String name, PropertySet set, POIFSFileSystem outFS) throws IOException {
+ protected void writePropertySet(String name, PropertySet set, NPOIFSFileSystem outFS) throws IOException {
try {
MutablePropertySet mSet = new MutablePropertySet(set);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
diff --git a/src/java/org/apache/poi/POIOLE2TextExtractor.java b/src/java/org/apache/poi/POIOLE2TextExtractor.java
index c0f4cbd1d7..7679136c89 100644
--- a/src/java/org/apache/poi/POIOLE2TextExtractor.java
+++ b/src/java/org/apache/poi/POIOLE2TextExtractor.java
@@ -20,7 +20,6 @@ import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
* Common Parent for OLE2 based Text Extractors
@@ -81,17 +80,4 @@ public abstract class POIOLE2TextExtractor extends POITextExtractor {
{
return document.directory;
}
-
- /**
- * Return the underlying POIFS FileSystem of this document.
- *
- * @return the POIFSFileSystem that is associated with the POIDocument of this extractor.
- *
- * @deprecated Use {@link #getRoot()} instead
- */
- @Deprecated
- public POIFSFileSystem getFileSystem()
- {
- return document.directory.getFileSystem();
- }
}
diff --git a/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java b/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
index f1b9ca9629..ea6bc0b1bc 100644
--- a/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
+++ b/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
@@ -44,7 +44,7 @@ public class HPSFPropertiesOnlyDocument extends POIDocument {
* Write out, with any properties changes, but nothing else
*/
public void write(OutputStream out) throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
+ NPOIFSFileSystem fs = new NPOIFSFileSystem();
// For tracking what we've written out, so far
List<String> excepts = new ArrayList<String>(1);
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index aee2d5444a..be1c7ef9fb 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -1277,7 +1277,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
throws IOException
{
byte[] bytes = getBytes();
- POIFSFileSystem fs = new POIFSFileSystem();
+ NPOIFSFileSystem fs = new NPOIFSFileSystem();
// For tracking what we've written out, used if we're
// going to be preserving nodes
diff --git a/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java b/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
index 4bce0641ab..d8a55563a2 100644
--- a/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
+++ b/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
@@ -124,8 +124,21 @@ public class EntryUtils
* @param target
* is the target POIFS to copy to
*/
- public static void copyNodes( POIFSFileSystem source,
- POIFSFileSystem target ) throws IOException
+ public static void copyNodes( OPOIFSFileSystem source,
+ OPOIFSFileSystem target ) throws IOException
+ {
+ copyNodes( source.getRoot(), target.getRoot() );
+ }
+ /**
+ * Copies all nodes from one POIFS to the other
+ *
+ * @param source
+ * is the source POIFS to copy from
+ * @param target
+ * is the target POIFS to copy to
+ */
+ public static void copyNodes( NPOIFSFileSystem source,
+ NPOIFSFileSystem target ) throws IOException
{
copyNodes( source.getRoot(), target.getRoot() );
}
@@ -140,8 +153,26 @@ public class EntryUtils
* @param target is the target POIFS to copy to
* @param excepts is a list of Entry Names to be excluded from the copy
*/
- public static void copyNodes( POIFSFileSystem source,
- POIFSFileSystem target, List<String> excepts ) throws IOException
+ public static void copyNodes( OPOIFSFileSystem source,
+ OPOIFSFileSystem target, List<String> excepts ) throws IOException
+ {
+ copyNodes(
+ new FilteringDirectoryNode(source.getRoot(), excepts),
+ new FilteringDirectoryNode(target.getRoot(), excepts)
+ );
+ }
+ /**
+ * Copies nodes from one POIFS to the other, minus the excepts.
+ * This delegates the filtering work to {@link FilteringDirectoryNode},
+ * so excepts can be of the form "NodeToExclude" or
+ * "FilteringDirectory/ExcludedChildNode"
+ *
+ * @param source is the source POIFS to copy from
+ * @param target is the target POIFS to copy to
+ * @param excepts is a list of Entry Names to be excluded from the copy
+ */
+ public static void copyNodes( NPOIFSFileSystem source,
+ NPOIFSFileSystem target, List<String> excepts ) throws IOException
{
copyNodes(
new FilteringDirectoryNode(source.getRoot(), excepts),