From: Nick Burch Date: Wed, 29 Dec 2010 03:19:46 +0000 (+0000) Subject: Since a DirectoryNode has a reference to the underlying POIFSFileSystem, tidy up... X-Git-Tag: REL_3_8_BETA1~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f22e831a0fb723b801f726d0d3aeb1bc7fb162ba;p=poi.git 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 --- diff --git a/src/java/org/apache/poi/POIDocument.java b/src/java/org/apache/poi/POIDocument.java index dacc9235ca..b5b01bb641 100644 --- a/src/java/org/apache/poi/POIDocument.java +++ b/src/java/org/apache/poi/POIDocument.java @@ -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()); } /** diff --git a/src/java/org/apache/poi/POIOLE2TextExtractor.java b/src/java/org/apache/poi/POIOLE2TextExtractor.java index f198c19337..9ec09fe47a 100644 --- a/src/java/org/apache/poi/POIOLE2TextExtractor.java +++ b/src/java/org/apache/poi/POIOLE2TextExtractor.java @@ -66,6 +66,6 @@ public abstract class POIOLE2TextExtractor extends POITextExtractor { * this document. */ public POIFSFileSystem getFileSystem() { - return document.filesystem; + return document.directory.getFileSystem(); } } diff --git a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java index 1ba9b6441c..32f9049639 100644 --- a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java +++ b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java @@ -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()); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index a26d65aa16..5af79e921e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -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())); } } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java index 7a739ac3cb..a317b29142 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index a4b6fad8d1..b64c796c4d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -128,23 +128,37 @@ 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 embeded documents. + * 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. + * Used typically to open embeded 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) 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) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java index f9ebc37801..75eb565f3a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java @@ -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) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java index 4226c7f492..093134d2b5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java @@ -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); diff --git a/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java b/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java index 7e7d0b249a..b3f91236ec 100644 --- a/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java +++ b/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java @@ -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 diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java index 016a7d0f58..be1a3dcb0c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java @@ -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) diff --git a/src/testcases/org/apache/poi/TestPOIDocumentMain.java b/src/testcases/org/apache/poi/TestPOIDocumentMain.java index f6e0a1e9e5..ef4d891745 100644 --- a/src/testcases/org/apache/poi/TestPOIDocumentMain.java +++ b/src/testcases/org/apache/poi/TestPOIDocumentMain.java @@ -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