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 2010/12/29 04:19:47 UTC

svn commit: r1053521 - in /poi/trunk/src: java/org/apache/poi/ java/org/apache/poi/hpsf/extractor/ java/org/apache/poi/hssf/usermodel/ scratchpad/src/org/apache/poi/hslf/ scratchpad/src/org/apache/poi/hwpf/ scratchpad/testcases/org/apache/poi/ scratchp...

Author: nick
Date: Wed Dec 29 03:19:46 2010
New Revision: 1053521

URL: http://svn.apache.org/viewvc?rev=1053521&view=rev
Log:
Since a DirectoryNode has a reference to the underlying POIFSFileSystem, tidy up the POIDocument constructor to not need both passing in

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/extractor/HPSFPropertiesExtractor.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/HSLFSlideShow.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.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=1053521&r1=1053520&r2=1053521&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIDocument.java Wed Dec 29 03:19:46 2010
@@ -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());
     }
 
 	/**

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=1053521&r1=1053520&r2=1053521&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java Wed Dec 29 03:19:46 2010
@@ -66,6 +66,6 @@ public abstract class POIOLE2TextExtract
 	 *  this document.
 	 */
 	public POIFSFileSystem getFileSystem() {
-		return document.filesystem;
+		return document.directory.getFileSystem();
 	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java?rev=1053521&r1=1053520&r2=1053521&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java Wed Dec 29 03:19:46 2010
@@ -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 ext
 	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 ext
 	 *  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 ext
 	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());
 	   }

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=1053521&r1=1053520&r2=1053521&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 Wed Dec 29 03:19:46 2010
@@ -168,7 +168,7 @@ public final class HSSFWorkbook extends 
     }
 
 	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 
     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 
         // 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 
             //  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 
                     Object sub = subRecordIter.next();
                     if (sub instanceof EmbeddedObjectRefSubRecord)
                     {
-                        objects.add(new HSSFObjectData((ObjRecord) obj, filesystem));
+                        objects.add(new HSSFObjectData((ObjRecord) obj, directory.getFileSystem()));
                     }
                 }
             }

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=1053521&r1=1053520&r2=1053521&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 Wed Dec 29 03:19:46 2010
@@ -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
 	 *  that is open.
 	 */
 	protected POIFSFileSystem getPOIFSFileSystem() {
-		return filesystem;
+		return directory.getFileSystem();
 	}
 
 	/**
@@ -112,21 +117,34 @@ public final class HSLFSlideShow extends
 	 */
 	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
 
         // 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

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=1053521&r1=1053520&r2=1053521&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 Wed Dec 29 03:19:46 2010
@@ -128,13 +128,13 @@ public final class HWPFDocument extends 
    */
   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
@@ -142,9 +142,23 @@ public final class HWPFDocument extends 
    */
   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 
       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)
     {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java?rev=1053521&r1=1053520&r2=1053521&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java Wed Dec 29 03:19:46 2010
@@ -71,7 +71,7 @@ public abstract class HWPFDocumentCore e
 
   protected HWPFDocumentCore()
   {
-     super(null, null);
+     super((DirectoryNode)null);
   }
 
   /**
@@ -118,7 +118,7 @@ public abstract class HWPFDocumentCore e
    */
   public HWPFDocumentCore(POIFSFileSystem pfilesystem) throws IOException
   {
-	this(pfilesystem.getRoot(), pfilesystem);
+	this(pfilesystem.getRoot());
   }
 
   /**
@@ -130,10 +130,10 @@ public abstract class HWPFDocumentCore e
    * @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)

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java?rev=1053521&r1=1053520&r2=1053521&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java Wed Dec 29 03:19:46 2010
@@ -39,12 +39,16 @@ public class HWPFOldDocument extends HWP
     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);

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=1053521&r1=1053520&r2=1053521&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/TestPOIDocumentScratchpad.java Wed Dec 29 03:19:46 2010
@@ -95,7 +95,7 @@ public final class TestPOIDocumentScratc
     	POIFSFileSystem inFS = new POIFSFileSystem(bais);
 
     	// Check they're still there
-    	doc.filesystem = inFS;
+    	doc.directory = inFS.getRoot();
     	doc.readProperties();
 
     	// Delegate test

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1053521&r1=1053520&r2=1053521&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java Wed Dec 29 03:19:46 2010
@@ -150,14 +150,14 @@ public final class TestExtractor extends
          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)

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=1053521&r1=1053520&r2=1053521&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/TestPOIDocumentMain.java Wed Dec 29 03:19:46 2010
@@ -100,7 +100,7 @@ public final class TestPOIDocumentMain e
 		POIFSFileSystem inFS = new POIFSFileSystem(bais);
 
 		// Check they're still there
-		doc.filesystem = inFS;
+		doc.directory = inFS.getRoot();
 		doc.readProperties();
 
 		// Delegate test



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org