You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2015/05/11 20:04:31 UTC
svn commit: r1678783 - in /poi/trunk/src: java/org/apache/poi/
java/org/apache/poi/hpsf/ java/org/apache/poi/hssf/usermodel/
java/org/apache/poi/poifs/filesystem/ scratchpad/src/org/apache/poi/hslf/
scratchpad/src/org/apache/poi/hslf/record/ scratchpad...
Author: nick
Date: Mon May 11 18:04:30 2015
New Revision: 1678783
URL: http://svn.apache.org/r1678783
Log:
#56791 More updates from OPOIFS to NPOIFS
Modified:
poi/trunk/src/java/org/apache/poi/POIDocument.java
poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java
poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java
poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java
Modified: poi/trunk/src/java/org/apache/poi/POIDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIDocument.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIDocument.java Mon May 11 18:04:30 2015
@@ -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();
Modified: poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java Mon May 11 18:04:30 2015
@@ -20,7 +20,6 @@ import org.apache.poi.hpsf.DocumentSumma
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 POIOLE2TextExtract
{
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();
- }
}
Modified: poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java Mon May 11 18:04:30 2015
@@ -44,7 +44,7 @@ public class HPSFPropertiesOnlyDocument
* 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);
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Mon May 11 18:04:30 2015
@@ -1277,7 +1277,7 @@ public final class HSSFWorkbook extends
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
Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java Mon May 11 18:04:30 2015
@@ -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),
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java Mon May 11 18:04:30 2015
@@ -52,6 +52,7 @@ import org.apache.poi.poifs.filesystem.D
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.EntryUtils;
+import org.apache.poi.poifs.filesystem.FilteringDirectoryNode;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian;
@@ -584,7 +585,7 @@ public final class HSLFSlideShow extends
_records = encryptedSS.updateEncryptionRecord(_records);
// Get a new Filesystem to write into
- POIFSFileSystem outFS = new POIFSFileSystem();
+ NPOIFSFileSystem outFS = new NPOIFSFileSystem();
// The list of entries we've written out
List<String> writtenEntries = new ArrayList<String>(1);
@@ -628,7 +629,9 @@ public final class HSLFSlideShow extends
// If requested, write out any other streams we spot
if(preserveNodes) {
- EntryUtils.copyNodes(directory.getFileSystem(), outFS, writtenEntries);
+ FilteringDirectoryNode sNode = new FilteringDirectoryNode(directory, writtenEntries);
+ FilteringDirectoryNode dNode = new FilteringDirectoryNode(outFS.getRoot(), writtenEntries);
+ EntryUtils.copyNodes(sNode, dNode);
}
// Send the POIFSFileSystem object out to the underlying stream
@@ -651,13 +654,14 @@ public final class HSLFSlideShow extends
/**
* Writes out the standard Documment Information Properties (HPSF)
- * @param outFS the POIFSFileSystem to write the properties into
+ * @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
*/
- protected void writeProperties(POIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
+ @Override
+ protected void writeProperties(NPOIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
super.writeProperties(outFS, writtenEntries);
DocumentEncryptionAtom dea = getDocumentEncryptionAtom();
if (dea != null) {
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java Mon May 11 18:04:30 2015
@@ -30,21 +30,18 @@ import org.apache.poi.hslf.exceptions.Co
import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentEntry;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil;
-
/**
- * This is a special kind of Atom, becauase it doesn't live inside the
- * PowerPoint document. Instead, it lives in a seperate stream in the
- * document. As such, it has to be treaded specially
- *
- * @author Nick Burch
+ * This is a special kind of Atom, because it doesn't live inside the
+ * PowerPoint document. Instead, it lives in a separate stream in the
+ * document. As such, it has to be treated specially
*/
-
public class CurrentUserAtom
{
private static POILogger logger = POILogFactory.getLogger(CurrentUserAtom.class);
@@ -117,6 +114,7 @@ public class CurrentUserAtom
/**
* Find the Current User in the filesystem, and create from that
+ * @deprecated Use {@link #CurrentUserAtom(DirectoryNode)} instead
*/
public CurrentUserAtom(POIFSFileSystem fs) throws IOException {
this(fs.getRoot());
@@ -278,7 +276,7 @@ public class CurrentUserAtom
/**
* Writes ourselves back out to a filesystem
*/
- public void writeToFS(POIFSFileSystem fs) throws IOException {
+ public void writeToFS(NPOIFSFileSystem fs) throws IOException {
// Grab contents
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeOut(baos);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Mon May 11 18:04:30 2015
@@ -67,10 +67,10 @@ import org.apache.poi.poifs.filesystem.D
import org.apache.poi.poifs.filesystem.DocumentEntry;
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;
-
/**
*
* This class acts as the bucket that we throw all of the Word data structures
@@ -924,7 +924,7 @@ public final class HWPFDocument extends
}
// create new document preserving order of entries
- POIFSFileSystem pfs = new POIFSFileSystem();
+ NPOIFSFileSystem pfs = new NPOIFSFileSystem();
boolean docWritten = false;
boolean dataWritten = false;
boolean objectPoolWritten = false;
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java Mon May 11 18:04:30 2015
@@ -74,7 +74,7 @@ public final class TestPOIDocumentScratc
public void testWriteProperties() throws Exception {
// Just check we can write them back out into a filesystem
- POIFSFileSystem outFS = new POIFSFileSystem();
+ NPOIFSFileSystem outFS = new NPOIFSFileSystem();
doc.writeProperties(outFS);
// Should now hold them
@@ -86,7 +86,7 @@ public final class TestPOIDocumentScratc
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Write them out
- POIFSFileSystem outFS = new POIFSFileSystem();
+ NPOIFSFileSystem outFS = new NPOIFSFileSystem();
doc.writeProperties(outFS);
outFS.writeFilesystem(baos);
Modified: poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java?rev=1678783&r1=1678782&r2=1678783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java Mon May 11 18:04:30 2015
@@ -26,6 +26,7 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
@@ -72,7 +73,7 @@ public final class TestPOIDocumentMain e
public void testWriteProperties() throws Exception {
// Just check we can write them back out into a filesystem
- POIFSFileSystem outFS = new POIFSFileSystem();
+ NPOIFSFileSystem outFS = new NPOIFSFileSystem();
doc.readProperties();
doc.writeProperties(outFS);
@@ -89,7 +90,7 @@ public final class TestPOIDocumentMain e
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Write them out
- POIFSFileSystem outFS = new POIFSFileSystem();
+ NPOIFSFileSystem outFS = new NPOIFSFileSystem();
doc.readProperties();
doc.writeProperties(outFS);
outFS.writeFilesystem(baos);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org