Since a DirectoryNode has a reference to the underlying POIFSFileSystem, tidy up the POIDocument constructor to not need both passing in

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1053521 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2010-12-29 03:19:46 +00:00
parent 3f85bdc6d3
commit f2b541e026
11 changed files with 78 additions and 34 deletions

View File

@ -50,8 +50,6 @@ public abstract class POIDocument {
private SummaryInformation sInf;
/** Holds further metadata on our document */
private DocumentSummaryInformation dsInf;
/** The open POIFS FileSystem that contains our document */
protected POIFSFileSystem filesystem;
/** The directory that our document lives in */
protected DirectoryNode directory;
@ -62,12 +60,15 @@ public abstract class POIDocument {
private boolean initialized = false;
protected POIDocument(DirectoryNode dir, POIFSFileSystem fs) {
this.filesystem = fs;
protected POIDocument(DirectoryNode dir) {
this.directory = dir;
}
@Deprecated
protected POIDocument(DirectoryNode dir, POIFSFileSystem fs) {
this.directory = dir;
}
protected POIDocument(POIFSFileSystem fs) {
this(fs.getRoot(), fs);
this(fs.getRoot());
}
/**

View File

@ -66,6 +66,6 @@ public abstract class POIOLE2TextExtractor extends POITextExtractor {
* this document.
*/
public POIFSFileSystem getFileSystem() {
return document.filesystem;
return document.directory.getFileSystem();
}
}

View File

@ -17,6 +17,7 @@
package org.apache.poi.hpsf.extractor;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
@ -30,6 +31,7 @@ import org.apache.poi.hpsf.Property;
import org.apache.poi.hpsf.SpecialPropertySet;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LittleEndian;
@ -48,6 +50,9 @@ public class HPSFPropertiesExtractor extends POITextExtractor {
public HPSFPropertiesExtractor(POIFSFileSystem fs) {
super(new PropertiesOnlyDocument(fs));
}
public HPSFPropertiesExtractor(NPOIFSFileSystem fs) {
super(new PropertiesOnlyDocument(fs));
}
public String getDocumentSummaryInformationText() {
DocumentSummaryInformation dsi = document.getDocumentSummaryInformation();
@ -144,6 +149,9 @@ public class HPSFPropertiesExtractor extends POITextExtractor {
* random OLE2 document.
*/
private static final class PropertiesOnlyDocument extends POIDocument {
public PropertiesOnlyDocument(NPOIFSFileSystem fs) {
super(fs.getRoot());
}
public PropertiesOnlyDocument(POIFSFileSystem fs) {
super(fs);
}
@ -156,7 +164,7 @@ public class HPSFPropertiesExtractor extends POITextExtractor {
public static void main(String[] args) throws IOException {
for(String file : args) {
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(
new POIFSFileSystem(new FileInputStream(file))
new NPOIFSFileSystem(new File(file))
);
System.out.println(ext.getText());
}

View File

@ -168,7 +168,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
}
private HSSFWorkbook(InternalWorkbook book) {
super(null, null);
super((DirectoryNode)null);
workbook = book;
_sheets = new ArrayList(INITIAL_CAPACITY);
names = new ArrayList(INITIAL_CAPACITY);
@ -249,7 +249,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
public HSSFWorkbook(DirectoryNode directory, POIFSFileSystem fs, boolean preserveNodes)
throws IOException
{
super(directory, fs);
super(directory);
String workbookName = getWorkbookDirEntryName(directory);
this.preserveNodes = preserveNodes;
@ -257,7 +257,6 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// If we're not preserving nodes, don't track the
// POIFS any more
if(! preserveNodes) {
this.filesystem = null;
this.directory = null;
}
@ -1174,7 +1173,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// out correctly shortly, so don't include the old one
excepts.add("WORKBOOK");
POIFSFileSystem srcFs = this.filesystem;
POIFSFileSystem srcFs = this.directory.getFileSystem();
// Copy over all the other nodes to our new poifs
copyNodes(srcFs, fs, excepts);
@ -1673,7 +1672,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
Object sub = subRecordIter.next();
if (sub instanceof EmbeddedObjectRefSubRecord)
{
objects.add(new HSSFObjectData((ObjRecord) obj, filesystem));
objects.add(new HSSFObjectData((ObjRecord) obj, directory.getFileSystem()));
}
}
}

View File

@ -28,14 +28,19 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.POIDocument;
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.hslf.record.*;
import org.apache.poi.hslf.record.CurrentUserAtom;
import org.apache.poi.hslf.record.ExOleObjStg;
import org.apache.poi.hslf.record.PersistPtrHolder;
import org.apache.poi.hslf.record.PersistRecord;
import org.apache.poi.hslf.record.PositionDependentRecord;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.UserEditAtom;
import org.apache.poi.hslf.usermodel.ObjectData;
import org.apache.poi.hslf.usermodel.PictureData;
import org.apache.poi.poifs.filesystem.DirectoryNode;
@ -76,7 +81,7 @@ public final class HSLFSlideShow extends POIDocument {
* that is open.
*/
protected POIFSFileSystem getPOIFSFileSystem() {
return filesystem;
return directory.getFileSystem();
}
/**
@ -112,21 +117,34 @@ public final class HSLFSlideShow extends POIDocument {
*/
public HSLFSlideShow(POIFSFileSystem filesystem) throws IOException
{
this(filesystem.getRoot(), filesystem);
this(filesystem.getRoot());
}
/**
* Constructs a Powerpoint document from a specific point in a
* POIFS Filesystem. Parses the document and places all the
* important stuff into data structures.
*
* @param dir the POIFS directory to read from
* @param filesystem the POIFS FileSystem to read from
* @throws IOException if there is a problem while parsing the document.
*/
public HSLFSlideShow(DirectoryNode dir, POIFSFileSystem filesystem) throws IOException
{
this(dir);
}
/**
* Constructs a Powerpoint document from a specific point in a
* POIFS Filesystem. Parses the document and places all the
* important stuff into data structures.
*
* @param dir the POIFS directory to read from
* @param filesystem the POIFS FileSystem to read from
* @throws IOException if there is a problem while parsing the document.
*/
public HSLFSlideShow(DirectoryNode dir, POIFSFileSystem filesystem) throws IOException
public HSLFSlideShow(DirectoryNode dir) throws IOException
{
super(dir, filesystem);
super(dir);
// First up, grab the "Current User" stream
// We need this before we can detect Encrypted Documents
@ -459,7 +477,7 @@ public final class HSLFSlideShow extends POIDocument {
// If requested, write out any other streams we spot
if(preserveNodes) {
copyNodes(filesystem, outFS, writtenEntries);
copyNodes(directory.getFileSystem(), outFS, writtenEntries);
}
// Send the POIFSFileSystem object out to the underlying stream

View File

@ -128,9 +128,23 @@ public final class HWPFDocument extends HWPFDocumentCore
*/
public HWPFDocument(POIFSFileSystem pfilesystem) throws IOException
{
this(pfilesystem.getRoot(), pfilesystem);
this(pfilesystem.getRoot());
}
/**
* This constructor loads a Word document from a specific point
* in a POIFSFileSystem, probably not the default.
* Used typically to open embedded documents.
*
* @param pfilesystem The POIFSFileSystem that contains the Word document.
* @throws IOException If there is an unexpected IOException from the passed
* in POIFSFileSystem.
*/
public HWPFDocument(DirectoryNode directory, POIFSFileSystem pfilesystem) throws IOException
{
this(directory);
}
/**
* This constructor loads a Word document from a specific point
* in a POIFSFileSystem, probably not the default.
@ -140,11 +154,11 @@ public final class HWPFDocument extends HWPFDocumentCore
* @throws IOException If there is an unexpected IOException from the passed
* in POIFSFileSystem.
*/
public HWPFDocument(DirectoryNode directory, POIFSFileSystem pfilesystem) throws IOException
public HWPFDocument(DirectoryNode directory) throws IOException
{
// Load the main stream and FIB
// Also handles HPSF bits
super(directory, pfilesystem);
super(directory);
// Do the CP Split
_cpSplit = new CPSplitCalculator(_fib);
@ -182,7 +196,7 @@ public final class HWPFDocument extends HWPFDocumentCore
DocumentEntry dataProps =
(DocumentEntry)directory.getEntry("Data");
_dataStream = new byte[dataProps.getSize()];
filesystem.createDocumentInputStream("Data").read(_dataStream);
directory.createDocumentInputStream("Data").read(_dataStream);
}
catch(java.io.FileNotFoundException e)
{

View File

@ -71,7 +71,7 @@ public abstract class HWPFDocumentCore extends POIDocument
protected HWPFDocumentCore()
{
super(null, null);
super((DirectoryNode)null);
}
/**
@ -118,7 +118,7 @@ public abstract class HWPFDocumentCore extends POIDocument
*/
public HWPFDocumentCore(POIFSFileSystem pfilesystem) throws IOException
{
this(pfilesystem.getRoot(), pfilesystem);
this(pfilesystem.getRoot());
}
/**
@ -130,10 +130,10 @@ public abstract class HWPFDocumentCore extends POIDocument
* @throws IOException If there is an unexpected IOException from the passed
* in POIFSFileSystem.
*/
public HWPFDocumentCore(DirectoryNode directory, POIFSFileSystem pfilesystem) throws IOException
public HWPFDocumentCore(DirectoryNode directory) throws IOException
{
// Sort out the hpsf properties
super(directory, pfilesystem);
super(directory);
// read in the main stream.
DocumentEntry documentProps = (DocumentEntry)

View File

@ -39,12 +39,16 @@ public class HWPFOldDocument extends HWPFDocumentCore {
private TextPieceTable tpt;
public HWPFOldDocument(POIFSFileSystem fs) throws IOException {
this(fs.getRoot(), fs);
this(fs.getRoot());
}
public HWPFOldDocument(DirectoryNode directory, POIFSFileSystem fs)
throws IOException {
super(directory, fs);
this(directory);
}
public HWPFOldDocument(DirectoryNode directory)
throws IOException {
super(directory);
// Where are things?
int sedTableOffset = LittleEndian.getInt(_mainStream, 0x88);

View File

@ -95,7 +95,7 @@ public final class TestPOIDocumentScratchpad extends TestCase {
POIFSFileSystem inFS = new POIFSFileSystem(bais);
// Check they're still there
doc.filesystem = inFS;
doc.directory = inFS.getRoot();
doc.readProperties();
// Delegate test

View File

@ -150,14 +150,14 @@ public final class TestExtractor extends TestCase {
assertNotNull(dirB.getEntry("PowerPoint Document"));
// Check the first file
ss = new HSLFSlideShow(dirA, fs);
ss = new HSLFSlideShow(dirA);
ppe = new PowerPointExtractor(ss);
assertEquals("Sample PowerPoint file\nThis is the 1st file\nNot much too it\n",
ppe.getText(true, false)
);
// And the second
ss = new HSLFSlideShow(dirB, fs);
ss = new HSLFSlideShow(dirB);
ppe = new PowerPointExtractor(ss);
assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n",
ppe.getText(true, false)

View File

@ -100,7 +100,7 @@ public final class TestPOIDocumentMain extends TestCase {
POIFSFileSystem inFS = new POIFSFileSystem(bais);
// Check they're still there
doc.filesystem = inFS;
doc.directory = inFS.getRoot();
doc.readProperties();
// Delegate test