FileDocCategorySizeDatePackage
POIBrowser.javaAPI DocApache Poi 3.0.14606Mon Jan 01 12:39:34 GMT 2007org.apache.poi.contrib.poibrowser

POIBrowser

public class POIBrowser extends JFrame

The main class of the POI Browser. It shows the structure of POI filesystems (Microsoft Office documents) in a {@link JTree}. Specify their filenames on the command line!

see
POIFSReader
author
Rainer Klute <klute@rainer-klute.de>
version
$Id: POIBrowser.java 489730 2006-12-22 19:18:16Z bayard $
since
2002-01-19

Fields Summary
protected MutableTreeNode
rootNode

The tree's root node must be visible to all methods.

Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

Takes a bunch of file names as command line parameters, opens each of them as a POI filesystem and displays their internal structures in a {@link JTree}.

        new POIBrowser().run(args);
    
protected voidrun(java.lang.String[] args)

        addWindowListener(new WindowAdapter()
            {
                public void windowClosing(WindowEvent e)
                {
                        System.exit(0);
                }
            });

        /* Create the tree model with a root node. The latter is
         * invisible but it must be present because a tree model
         * always needs a root. */
        rootNode = new DefaultMutableTreeNode("POI Filesystems");
        DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);

        /* Create the tree UI element. */
        final JTree treeUI = new JTree(treeModel);
        getContentPane().add(new JScrollPane(treeUI));

        /* Add the POI filesystems to the tree. */
        int displayedFiles = 0;
        for (int i = 0; i < args.length; i++)
        {
            final String filename = args[i];
            try
            {
                POIFSReader r = new POIFSReader();
                r.registerListener(new TreeReaderListener(filename, rootNode));
                r.read(new FileInputStream(filename));
                displayedFiles++;
            }
            catch (IOException ex)
            {
                System.err.println(filename + ": " + ex);
            }
            catch (Throwable t)
            {
                System.err.println("Unexpected exception while reading \"" +
                                   filename + "\":");
                t.printStackTrace(System.err);
            }
        }

        /* Exit if there is no file to display (none specified or only
         * files with problems). */
        if (displayedFiles == 0)
        {
            System.out.println("No POI filesystem(s) to display.");
            System.exit(0);
        }

        /* Make the tree UI element visible. */
        treeUI.setRootVisible(true);
        treeUI.setShowsRootHandles(true);
        ExtendableTreeCellRenderer etcr = new ExtendableTreeCellRenderer();
        etcr.register(DocumentDescriptor.class,
                      new DocumentDescriptorRenderer());
        etcr.register(PropertySetDescriptor.class,
                      new PropertySetDescriptorRenderer());
        treeUI.setCellRenderer(etcr);
        setSize(600, 450);
        setTitle("POI Browser 0.09");
        setVisible(true);