Search in sources :

Example 1 with HPSFException

use of org.apache.poi.hpsf.HPSFException in project poi by apache.

the class TreeReaderListener method processPOIFSReaderEvent.

/**
     * <p>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.</p>
     */
@Override
public void processPOIFSReaderEvent(final POIFSReaderEvent event) {
    DocumentDescriptor d;
    final DocumentInputStream is = event.getStream();
    if (!is.markSupported()) {
        throw new UnsupportedOperationException(is.getClass().getName() + " does not support mark().");
    }
    /* Try do handle this document as a property set. We receive
         * an exception if is no property set and handle it as a
         * document of some other format. We are not concerned about
         * that document's details. */
    try {
        d = new PropertySetDescriptor(event.getName(), event.getPath(), is, nrOfBytes);
    } catch (HPSFException ex) {
        d = new DocumentDescriptor(event.getName(), event.getPath(), is, nrOfBytes);
    } catch (Exception t) {
        throw new RuntimeException("Unexpected exception while processing " + event.getName() + " in " + event.getPath(), t);
    }
    is.close();
    final MutableTreeNode parentNode = getNode(d.path, filename, rootNode);
    final MutableTreeNode nameNode = new DefaultMutableTreeNode(d.name);
    parentNode.insert(nameNode, 0);
    final MutableTreeNode dNode = new DefaultMutableTreeNode(d);
    nameNode.insert(dNode, 0);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DocumentInputStream(org.apache.poi.poifs.filesystem.DocumentInputStream) HPSFException(org.apache.poi.hpsf.HPSFException) HPSFException(org.apache.poi.hpsf.HPSFException) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 MutableTreeNode (javax.swing.tree.MutableTreeNode)1 HPSFException (org.apache.poi.hpsf.HPSFException)1 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)1