FileDocCategorySizeDatePackage
DirectoryNode.javaAPI DocApache Poi 3.0.111802Mon Jan 01 12:39:34 GMT 2007org.apache.poi.poifs.filesystem

DirectoryNode

public class DirectoryNode extends EntryNode implements POIFSViewable, DirectoryEntry
Simple implementation of DirectoryEntry
author
Marc Johnson (mjohnson at apache dot org)

Fields Summary
private Map
_entries
private POIFSFileSystem
_filesystem
private POIFSDocumentPath
_path
Constructors Summary
DirectoryNode(DirectoryProperty property, POIFSFileSystem filesystem, DirectoryNode parent)
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
filesystem the POIFSFileSystem we belong to
param
parent the parent of this entry

        super(property, parent);
        if (parent == null)
        {
            _path = new POIFSDocumentPath();
        }
        else
        {
            _path = new POIFSDocumentPath(parent._path, new String[]
            {
                property.getName()
            });
        }
        _filesystem = filesystem;
        _entries    = new HashMap();
        Iterator iter = property.getChildren();

        while (iter.hasNext())
        {
            Property child     = ( Property ) iter.next();
            Entry    childNode = null;

            if (child.isDirectory())
            {
                childNode = new DirectoryNode(( DirectoryProperty ) child,
                                              _filesystem, this);
            }
            else
            {
                childNode = new DocumentNode(( DocumentProperty ) child,
                                             this);
            }
            _entries.put(childNode.getName(), childNode);
        }
    
Methods Summary
booleanchangeName(java.lang.String oldName, java.lang.String newName)
Change a contained Entry's name

param
oldName the original name
param
newName the new name
return
true if the operation succeeded, else false

        boolean   rval  = false;
        EntryNode child = ( EntryNode ) _entries.get(oldName);

        if (child != null)
        {
            rval = (( DirectoryProperty ) getProperty())
                .changeName(child.getProperty(), newName);
            if (rval)
            {
                _entries.remove(oldName);
                _entries.put(child.getProperty().getName(), child);
            }
        }
        return rval;
    
public org.apache.poi.poifs.filesystem.DirectoryEntrycreateDirectory(java.lang.String name)
create a new DirectoryEntry

param
name the name of the new DirectoryEntry
return
the new DirectoryEntry
exception
IOException

        DirectoryProperty property = new DirectoryProperty(name);
        DirectoryNode     rval     = new DirectoryNode(property, _filesystem,
                                         this);

        (( DirectoryProperty ) getProperty()).addChild(property);
        _filesystem.addDirectory(property);
        _entries.put(name, rval);
        return rval;
    
public org.apache.poi.poifs.filesystem.DocumentEntrycreateDocument(java.lang.String name, java.io.InputStream stream)
create a new DocumentEntry

param
name the name of the new DocumentEntry
param
stream the InputStream from which to create the new DocumentEntry
return
the new DocumentEntry
exception
IOException

        return createDocument(new POIFSDocument(name, stream));
    
public org.apache.poi.poifs.filesystem.DocumentEntrycreateDocument(java.lang.String name, int size, org.apache.poi.poifs.filesystem.POIFSWriterListener writer)
create a new DocumentEntry; the data will be provided later

param
name the name of the new DocumentEntry
param
size the size of the new DocumentEntry
param
writer the writer of the new DocumentEntry
return
the new DocumentEntry
exception
IOException

        return createDocument(new POIFSDocument(name, size, _path, writer));
    
org.apache.poi.poifs.filesystem.DocumentEntrycreateDocument(org.apache.poi.poifs.filesystem.POIFSDocument document)
create a new DocumentEntry

param
document the new document
return
the new DocumentEntry
exception
IOException

        DocumentProperty property = document.getDocumentProperty();
        DocumentNode     rval     = new DocumentNode(property, this);

        (( DirectoryProperty ) getProperty()).addChild(property);
        _filesystem.addDocument(document);
        _entries.put(property.getName(), rval);
        return rval;
    
booleandeleteEntry(org.apache.poi.poifs.filesystem.EntryNode entry)
Delete an entry

param
entry the EntryNode to be deleted
return
true if the entry was deleted, else false

        boolean rval =
            (( DirectoryProperty ) getProperty())
                .deleteChild(entry.getProperty());

        if (rval)
        {
            _entries.remove(entry.getName());
            _filesystem.remove(entry);
        }
        return rval;
    
public java.util.IteratorgetEntries()
get an iterator of the Entry instances contained directly in this instance (in other words, children only; no grandchildren etc.)

return
iterator; never null, but hasNext() may return false immediately (i.e., this DirectoryEntry is empty). All objects retrieved by next() are guaranteed to be implementations of Entry.

        return _entries.values().iterator();
    
public org.apache.poi.poifs.filesystem.EntrygetEntry(java.lang.String name)
get a specified Entry by name

param
name the name of the Entry to obtain.
return
the specified Entry, if it is directly contained in this DirectoryEntry
exception
FileNotFoundException if no Entry with the specified name exists in this DirectoryEntry

        Entry rval = null;

        if (name != null)
        {
            rval = ( Entry ) _entries.get(name);
        }
        if (rval == null)
        {

            // either a null name was given, or there is no such name
            throw new FileNotFoundException("no such entry: \"" + name
                                            + "\"");
        }
        return rval;
    
public intgetEntryCount()
find out how many Entry instances are contained directly within this DirectoryEntry

return
number of immediately (no grandchildren etc.) contained Entry instances

        return _entries.size();
    
public org.apache.poi.poifs.filesystem.POIFSDocumentPathgetPath()

return
this directory's path representation

        return _path;
    
public java.lang.StringgetShortDescription()
Provides a short description of the object, to be used when a POIFSViewable object has not provided its contents.

return
short description

        return getName();
    
public org.apache.poi.hpsf.ClassIDgetStorageClsid()
Gets the storage clsid of the directory entry

return
storage Class ID

        return getProperty().getStorageClsid();
    
public java.lang.Object[]getViewableArray()
Get an array of objects, some of which may implement POIFSViewable

return
an array of Object; may not be null, but may be empty

        return new Object[ 0 ];
    
public java.util.IteratorgetViewableIterator()
Get an Iterator of objects, some of which may implement POIFSViewable

return
an Iterator; may not be null, but may have an empty back end store

        List components = new ArrayList();

        components.add(getProperty());
        SortedMap sortedEntries = new TreeMap(_entries);
        Iterator  iter          = sortedEntries.values().iterator();

        while (iter.hasNext())
        {
            components.add(iter.next());
        }
        return components.iterator();
    
protected booleanisDeleteOK()
extensions use this method to verify internal rules regarding deletion of the underlying store.

return
true if it's ok to delete the underlying store, else false


        // if this directory is empty, we can delete it
        return isEmpty();
    
public booleanisDirectoryEntry()
is this a DirectoryEntry?

return
true if the Entry is a DirectoryEntry, else false

        return true;
    
public booleanisEmpty()
is this DirectoryEntry empty?

return
true if this instance contains no Entry instances

        return _entries.isEmpty();
    
public booleanpreferArray()
Give viewers a hint as to whether to call getViewableArray or getViewableIterator

return
true if a viewer should call getViewableArray, false if a viewer should call getViewableIterator

        return false;
    
public voidsetStorageClsid(org.apache.poi.hpsf.ClassID clsidStorage)
Sets the storage clsid for the directory entry

param
clsidStorage storage Class ID

        getProperty().setStorageClsid(clsidStorage);