Browse Source

#56791 More updates from OPOIFS to NPOIFS

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678783 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_13_BETA1
Nick Burch 9 years ago
parent
commit
32579cda68

+ 31
- 26
src/java/org/apache/poi/POIDocument.java View File

@@ -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();

+ 0
- 14
src/java/org/apache/poi/POIOLE2TextExtractor.java View File

@@ -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();
}
}

+ 1
- 1
src/java/org/apache/poi/hpsf/HPSFPropertiesOnlyDocument.java View File

@@ -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);

+ 1
- 1
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java View File

@@ -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

+ 35
- 4
src/java/org/apache/poi/poifs/filesystem/EntryUtils.java View File

@@ -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),

+ 8
- 4
src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java View File

@@ -52,6 +52,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
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 POIDocument {
_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 POIDocument {

// 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 POIDocument {

/**
* 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) {

+ 6
- 8
src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java View File

@@ -30,21 +30,18 @@ import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
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);

+ 2
- 2
src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java View File

@@ -67,10 +67,10 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
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 HWPFDocumentCore
}

// create new document preserving order of entries
POIFSFileSystem pfs = new POIFSFileSystem();
NPOIFSFileSystem pfs = new NPOIFSFileSystem();
boolean docWritten = false;
boolean dataWritten = false;
boolean objectPoolWritten = false;

+ 2
- 2
src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java View File

@@ -74,7 +74,7 @@ public final class TestPOIDocumentScratchpad extends TestCase {

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 TestPOIDocumentScratchpad extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();

// Write them out
POIFSFileSystem outFS = new POIFSFileSystem();
NPOIFSFileSystem outFS = new NPOIFSFileSystem();
doc.writeProperties(outFS);
outFS.writeFilesystem(baos);


+ 3
- 2
src/testcases/org/apache/poi/TestPOIDocumentMain.java View File

@@ -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 extends TestCase {

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 extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();

// Write them out
POIFSFileSystem outFS = new POIFSFileSystem();
NPOIFSFileSystem outFS = new NPOIFSFileSystem();
doc.readProperties();
doc.writeProperties(outFS);
outFS.writeFilesystem(baos);

Loading…
Cancel
Save