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/28 07:21:41 UTC

svn commit: r1053269 - in /poi/trunk/src: java/org/apache/poi/poifs/filesystem/ testcases/org/apache/poi/poifs/filesystem/

Author: nick
Date: Tue Dec 28 06:21:40 2010
New Revision: 1053269

URL: http://svn.apache.org/viewvc?rev=1053269&view=rev
Log:
Start on refactoring ready to support NPOIFS Directory/Document nodes

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java?rev=1053269&r1=1053268&r2=1053269&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java Tue Dec 28 06:21:40 2010
@@ -34,7 +34,6 @@ import org.apache.poi.poifs.property.Pro
  *
  * @author Marc Johnson (mjohnson at apache dot org)
  */
-
 public class DirectoryNode
     extends EntryNode
     implements DirectoryEntry, POIFSViewable, Iterable<Entry>
@@ -45,8 +44,11 @@ public class DirectoryNode
     // Our list of entries, kept sorted to preserve order
     private ArrayList<Entry> _entries;
 
+   // Only one of these two will exist
     // the POIFSFileSystem we belong to
-    private POIFSFileSystem   _filesystem;
+    private POIFSFileSystem   _ofilesystem;
+    // the NPOIFSFileSytem we belong to
+    private NPOIFSFileSystem  _nfilesystem; 
 
     // the path described by this document
     private POIFSDocumentPath _path;
@@ -59,11 +61,33 @@ public class DirectoryNode
      * @param filesystem the POIFSFileSystem we belong to
      * @param parent the parent of this entry
      */
-
     DirectoryNode(final DirectoryProperty property,
                   final POIFSFileSystem filesystem,
                   final DirectoryNode parent)
     {
+       this(property, parent);
+       _ofilesystem = filesystem;
+    }
+    
+    /**
+     * create a DirectoryNode. This method is not public by design; it
+     * is intended strictly for the internal use of this package
+     *
+     * @param property the DirectoryProperty for this DirectoryEntry
+     * @param nfilesystem the NPOIFSFileSystem we belong to
+     * @param parent the parent of this entry
+     */
+    DirectoryNode(final DirectoryProperty property,
+                  final NPOIFSFileSystem nfilesystem,
+                  final DirectoryNode parent)
+    {
+       this(property, parent);
+       _nfilesystem = nfilesystem;
+    }
+    
+    private DirectoryNode(final DirectoryProperty property,
+                          final DirectoryNode parent)
+    {
         super(property, parent);
         if (parent == null)
         {
@@ -76,7 +100,6 @@ public class DirectoryNode
                 property.getName()
             });
         }
-        _filesystem = filesystem;
         _byname     = new HashMap<String, Entry>();
         _entries    = new ArrayList<Entry>();
         Iterator<Property> iter = property.getChildren();
@@ -88,8 +111,12 @@ public class DirectoryNode
 
             if (child.isDirectory())
             {
-                childNode = new DirectoryNode(( DirectoryProperty ) child,
-                                              _filesystem, this);
+                DirectoryProperty childDir = (DirectoryProperty) child;
+                if(_ofilesystem != null) {
+                   childNode = new DirectoryNode(childDir, _ofilesystem, this);
+                } else {
+                   childNode = new DirectoryNode(childDir, _nfilesystem, this);
+                }
             }
             else
             {
@@ -113,10 +140,17 @@ public class DirectoryNode
     /**
      * @return the filesystem that this belongs to
      */
-    
     public POIFSFileSystem getFileSystem()
     {
-        return _filesystem; 
+        return _ofilesystem; 
+    }
+    
+    /**
+     * @return the filesystem that this belongs to
+     */
+    public NPOIFSFileSystem getNFileSystem()
+    {
+        return _nfilesystem; 
     }
     
     /**
@@ -161,7 +195,13 @@ public class DirectoryNode
         DocumentNode     rval     = new DocumentNode(property, this);
 
         (( DirectoryProperty ) getProperty()).addChild(property);
-        _filesystem.addDocument(document);
+        
+        if(_ofilesystem != null) {
+           _ofilesystem.addDocument(document);
+        } else {
+           _nfilesystem.addDocument(document);
+        }
+        
         _entries.add(rval);
         _byname.put(property.getName(), rval);
         return rval;
@@ -211,8 +251,13 @@ public class DirectoryNode
         if (rval)
         {
             _entries.remove(entry);
-        	_byname.remove(entry.getName());
-            _filesystem.remove(entry);
+        	   _byname.remove(entry.getName());
+        	   
+        	   if(_ofilesystem != null) {
+               _ofilesystem.remove(entry);
+        	   } else {
+        	      _nfilesystem.remove(entry);
+        	   }
         }
         return rval;
     }
@@ -341,12 +386,18 @@ public class DirectoryNode
     public DirectoryEntry createDirectory(final String name)
         throws IOException
     {
+        DirectoryNode rval;
         DirectoryProperty property = new DirectoryProperty(name);
-        DirectoryNode     rval     = new DirectoryNode(property, _filesystem,
-                                         this);
+        
+        if(_ofilesystem != null) {
+           rval = new DirectoryNode(property, _ofilesystem, this);
+           _ofilesystem.addDirectory(property);
+        } else {
+           rval = new DirectoryNode(property, _nfilesystem, this);
+           _nfilesystem.addDirectory(property);
+        }
 
         (( DirectoryProperty ) getProperty()).addChild(property);
-        _filesystem.addDirectory(property);
         _entries.add(rval);
         _byname.put(name, rval);
         return rval;

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java?rev=1053269&r1=1053268&r2=1053269&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java Tue Dec 28 06:21:40 2010
@@ -19,7 +19,6 @@
 
 package org.apache.poi.poifs.filesystem;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -45,15 +44,11 @@ import org.apache.poi.poifs.nio.DataSour
 import org.apache.poi.poifs.nio.FileBackedDataSource;
 import org.apache.poi.poifs.property.DirectoryProperty;
 import org.apache.poi.poifs.property.NPropertyTable;
-import org.apache.poi.poifs.property.Property;
 import org.apache.poi.poifs.storage.BATBlock;
 import org.apache.poi.poifs.storage.BlockAllocationTableWriter;
-import org.apache.poi.poifs.storage.BlockList;
-import org.apache.poi.poifs.storage.BlockWritable;
 import org.apache.poi.poifs.storage.HeaderBlock;
 import org.apache.poi.poifs.storage.HeaderBlockConstants;
 import org.apache.poi.poifs.storage.HeaderBlockWriter;
-import org.apache.poi.poifs.storage.SmallBlockTableWriter;
 import org.apache.poi.poifs.storage.BATBlock.BATBlockAndIndex;
 import org.apache.poi.util.CloseIgnoringInputStream;
 import org.apache.poi.util.IOUtils;
@@ -464,6 +459,26 @@ public class NPOIFSFileSystem extends Bl
        return _mini_store;
     }
 
+    /**
+     * add a new POIFSDocument to the FileSytem 
+     *
+     * @param document the POIFSDocument being added
+     */
+    void addDocument(final POIFSDocument document)
+    {
+        _property_table.addProperty(document.getDocumentProperty());
+    }
+
+    /**
+     * add a new DirectoryProperty to the FileSystem
+     *
+     * @param directory the DirectoryProperty being added
+     */
+    void addDirectory(final DirectoryProperty directory)
+    {
+        _property_table.addProperty(directory);
+    }
+
    /**
      * Create a new document to be added to the root directory
      *
@@ -610,17 +625,14 @@ public class NPOIFSFileSystem extends Bl
     }
 
     /**
-     * get the root entry
+     * Get the root entry
      *
      * @return the root entry
      */
-
     public DirectoryNode getRoot()
     {
-        if (_root == null)
-        {
-           // TODO
-//            _root = new DirectoryNode(_property_table.getRoot(), this, null);
+        if (_root == null) {
+           _root = new DirectoryNode(_property_table.getRoot(), this, null);
         }
         return _root;
     }

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java?rev=1053269&r1=1053268&r2=1053269&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSDocument.java Tue Dec 28 06:21:40 2010
@@ -54,7 +54,7 @@ public final class POIFSDocument impleme
 
 	// one of these stores will be valid
 	private SmallBlockStore  _small_store;
-	private BigBlockStore	_big_store;
+	private BigBlockStore	 _big_store;
 	
 		/**
 	 * Constructor from large blocks

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java?rev=1053269&r1=1053268&r2=1053269&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java Tue Dec 28 06:21:40 2010
@@ -57,7 +57,7 @@ public final class TestDocumentInputStre
         _workbook = new DocumentNode(
             document.getDocumentProperty(),
             new DirectoryNode(
-                new DirectoryProperty("Root Entry"), null, null));
+                new DirectoryProperty("Root Entry"), (POIFSFileSystem)null, null));
     }
 
     private DocumentNode     _workbook;

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java?rev=1053269&r1=1053268&r2=1053269&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentNode.java Tue Dec 28 06:21:40 2010
@@ -49,7 +49,7 @@ public final class TestDocumentNode exte
         POIFSDocument    document  = new POIFSDocument("document", rawBlocks,
                                          2000);
         DocumentProperty property2 = document.getDocumentProperty();
-        DirectoryNode    parent    = new DirectoryNode(property1, null, null);
+        DirectoryNode    parent    = new DirectoryNode(property1, (POIFSFileSystem)null, null);
         DocumentNode     node      = new DocumentNode(property2, parent);
 
         // verify we can retrieve the document

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java?rev=1053269&r1=1053268&r2=1053269&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java Tue Dec 28 06:21:40 2010
@@ -402,14 +402,36 @@ public final class TestNPOIFSFileSystem 
    public void testListEntries() throws Exception {
       NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
       NPOIFSFileSystem fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
-      for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB}) {
-         // TODO
-      }
-      
-      fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
-      fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
-      for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB}) {
-         // TODO
+      NPOIFSFileSystem fsC = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+      NPOIFSFileSystem fsD = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+      for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB,fsC,fsD}) {
+         DirectoryEntry root = fs.getRoot();
+         assertEquals(5, root.getEntryCount());
+         
+         // Check by the names
+         Entry thumbnail = root.getEntry("Thumbnail");
+         Entry dsi = root.getEntry("\u0005DocumentSummaryInformation");
+         Entry si = root.getEntry("\u0005SummaryInformation");
+         Entry image = root.getEntry("Image");
+         Entry tags = root.getEntry("Tags");
+         
+         assertEquals(false, thumbnail.isDirectoryEntry());
+         assertEquals(false, dsi.isDirectoryEntry());
+         assertEquals(false, si.isDirectoryEntry());
+         assertEquals(true, image.isDirectoryEntry());
+         assertEquals(false, tags.isDirectoryEntry());
+         
+         // Check via the iterator
+         Iterator<Entry> it = root.getEntries();
+         assertEquals(thumbnail.getName(), it.next().getName());
+         assertEquals(dsi.getName(), it.next().getName());
+         assertEquals(si.getName(), it.next().getName());
+         assertEquals(image.getName(), it.next().getName());
+         assertEquals(tags.getName(), it.next().getName());
+         
+         // Look inside another
+         DirectoryEntry imageD = (DirectoryEntry)image;
+         assertEquals(7, imageD.getEntryCount());
       }
    }
    
@@ -420,14 +442,16 @@ public final class TestNPOIFSFileSystem 
    public void testGetDocumentEntry() throws Exception {
       NPOIFSFileSystem fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
       NPOIFSFileSystem fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
-      for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB}) {
-         // TODO
-      }
-      
-      fsA = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
-      fsB = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
-      for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB}) {
-         // TODO
+      NPOIFSFileSystem fsC = new NPOIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+      NPOIFSFileSystem fsD = new NPOIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+      for(NPOIFSFileSystem fs : new NPOIFSFileSystem[] {fsA,fsB,fsC,fsD}) {
+         DirectoryEntry root = fs.getRoot();
+         Entry dsi = root.getEntry("\u0005DocumentSummaryInformation");
+         
+         assertEquals(true, dsi.isDocumentEntry());
+         DocumentEntry doc = (DocumentEntry)dsi;
+         
+         
       }
    }
    



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