*
* @author Marc Johnson (mjohnson at apache dot org)
*/
-
public class DirectoryNode
extends EntryNode
implements DirectoryEntry, POIFSViewable, Iterable<Entry>
// 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;
* @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)
property.getName()
});
}
- _filesystem = filesystem;
_byname = new HashMap<String, Entry>();
_entries = new ArrayList<Entry>();
Iterator<Property> iter = property.getChildren();
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
{
/**
* @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;
}
/**
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;
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;
}
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;
package org.apache.poi.poifs.filesystem;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
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;
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
*
}
/**
- * 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;
}
// one of these stores will be valid
private SmallBlockStore _small_store;
- private BigBlockStore _big_store;
+ private BigBlockStore _big_store;
/**
* Constructor from large blocks
_workbook = new DocumentNode(
document.getDocumentProperty(),
new DirectoryNode(
- new DirectoryProperty("Root Entry"), null, null));
+ new DirectoryProperty("Root Entry"), (POIFSFileSystem)null, null));
}
private DocumentNode _workbook;
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
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());
}
}
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;
+
+
}
}