Example usage for org.apache.poi.poifs.filesystem POIFSDocumentPath length

List of usage examples for org.apache.poi.poifs.filesystem POIFSDocumentPath length

Introduction

In this page you can find the example usage for org.apache.poi.poifs.filesystem POIFSDocumentPath length.

Prototype


public int length() 

Source Link

Usage

From source file:poi.poifs.poibrowser.TreeReaderListener.java

License:Apache License

/**
 * <p>Locates the parent node for a document entry in the tree
 * model. If the parent node does not yet exist it will be
 * created, too. This is done recursively, if needed.</p>
 *
 * @param path The tree node for this path is located.
 *
 * @param fsName The name of the POI filesystem. This is just a
 * string which is displayed in the tree at the top lovel.
 *
 * @param root The root node.//from   ww  w. j  a  v a  2 s  .c  om
 */
private MutableTreeNode getNode(final POIFSDocumentPath path, final String fsName, final MutableTreeNode root) {
    MutableTreeNode n = (MutableTreeNode) pathToNode.get(path);
    if (n != null)
        /* Node found in map, just return it. */
        return n;
    if (path.length() == 0) {
        /* This is the root path of the POI filesystem. Its tree
         * node is resp. must be located below the tree node of
         * the POI filesystem itself. This is a tree node with the
         * POI filesystem's name (this the operating system file's
         * name) as its key it the path-to-node map. */
        n = (MutableTreeNode) pathToNode.get(fsName);
        if (n == null) {
            /* A tree node for the POI filesystem does not yet
             * exist. */
            n = new DefaultMutableTreeNode(fsName);
            pathToNode.put(fsName, n);
            root.insert(n, 0);
        }
        return n;
    }
    /* else - The path is somewhere down in the POI filesystem's
     * hierarchy. We need the tree node of this path's parent
     * and attach our new node to it. */
    final String name = path.getComponent(path.length() - 1);
    final POIFSDocumentPath parentPath = path.getParent();
    final MutableTreeNode parentNode = getNode(parentPath, fsName, root);
    n = new DefaultMutableTreeNode(name);
    pathToNode.put(path, n);
    parentNode.insert(n, 0);
    return n;
}