## org.apache.poi.contrib.poibrowser
Class TreeReaderListener

    java.lang.Object
      org.apache.poi.contrib.poibrowser.TreeReaderListener

All Implemented Interfaces:
  POIFSReaderListener

public class TreeReaderListener
extends java.lang.Object
implements POIFSReaderListener

Organizes document information in a tree model in order to be e.g. displayed in a Swing `JTree`. An instance of this class is created with a root tree node (`MutableTreeNode`) and registered as a `POIFSReaderListener` with a `POIFSReader`. While the latter processes a POI filesystem it calls this class' `processPOIFSReaderEvent(org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent)` for each document it has been registered for. This method appends the document it processes at the appropriate position into the tree rooted at the above mentioned root tree node.

The root tree node should be the root tree node of a `TreeModel`.

A top-level element in the tree model, i.e. an immediate child node of the root node, describes a POI filesystem as such. It is suggested to use the file's name (as seen by the operating system) but it could be any other string.

The value of a tree node is a `DocumentDescriptor`. Unlike a `POIFSDocument` which may be as heavy as many megabytes, an instance of `DocumentDescriptor` is a light-weight object and contains only some meta-information about a document.

Since:
  2002-01-24
Version:
  $Id: TreeReaderListener.java,v 1.2.8.1 2004/02/22 11:22:14 glens Exp $
Author:
  Rainer Klute (klute@rainer-klute.de)

Field Summary
`protected java.lang.String` `filename` The name of the file this `TreeReaderListener` processes.
`protected java.util.Map` `pathToNode` Maps filenames and POI document paths to their associated tree nodes.
`protected javax.swing.tree.MutableTreeNode` `rootNode` The tree's root node.

Constructor Summary
`TreeReaderListener(java.lang.String filename, javax.swing.tree.MutableTreeNode rootNode)` Creates a `TreeReaderListener` which should then be registered with a `POIFSReader`.

Method Summary
`int` `getNrOfBytes()`
`void` `processPOIFSReaderEvent(POIFSReaderEvent event)` A document in the POI filesystem has been opened for reading.
`void` `setNrOfBytes(int nrOfBytes)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### rootNode

    protected javax.swing.tree.MutableTreeNode rootNode

  The tree's root node. POI filesystems get attached to this node as children.

### pathToNode

    protected java.util.Map pathToNode

  Maps filenames and POI document paths to their associated tree nodes.

### filename

    protected java.lang.String filename

  The name of the file this `TreeReaderListener` processes. It is used to identify a top-level element in the tree. Alternatively any other string can be used. It is just a label which should identify a POI filesystem.

Constructor Detail

### TreeReaderListener

    public TreeReaderListener(java.lang.String filename,
                              javax.swing.tree.MutableTreeNode rootNode)

  Creates a `TreeReaderListener` which should then be registered with a `POIFSReader`.

Parameters:
  `filename` - The name of the POI filesystem, i.e. the name of the file the POI filesystem resides in. Alternatively any other string can be used.
  `rootNode` - All document information will be attached as descendands to this tree node.

Method Detail

### setNrOfBytes

    public void setNrOfBytes(int nrOfBytes)

### getNrOfBytes

    public int getNrOfBytes()

### processPOIFSReaderEvent

    public void processPOIFSReaderEvent(POIFSReaderEvent event)

  A document in the POI filesystem has been opened for reading. This method retrieves properties of the document and adds them to a tree model.

  Specified by:
    `processPOIFSReaderEvent` in interface `POIFSReaderListener`
  Parameters:
    `event` - the POIFSReaderEvent

Copyright © 2003 Apache Software Foundation.