Example usage for org.apache.poi.poifs.filesystem DirectoryNode getEntries

List of usage examples for org.apache.poi.poifs.filesystem DirectoryNode getEntries

Introduction

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

Prototype


public Iterator<Entry> getEntries() 

Source Link

Document

get an iterator of the Entry instances contained directly in this instance (in other words, children only; no grandchildren etc.)

Usage

From source file:FeatureExtraction.FeatureExtractorDocStreamPaths.java

private static void GetStreamsPaths(DirectoryNode dir, String parentPath, Map<String, Integer> streamPaths) {
    // run over all directory chidlrens
    for (Iterator<Entry> entryIter = dir.getEntries(); entryIter.hasNext();) {
        Entry entry = entryIter.next();//from w w  w .  j  a  va2  s .c o m
        String entryName = entry.getName();

        // Some entry names starts with binary value that are not printable - remove it
        if (entryName.charAt(0) < 10) {
            entryName = entryName.substring(1);
        }

        // Recursively search for directory (storage) children
        if (entry instanceof DirectoryNode) {
            GetStreamsPaths((DirectoryNode) entry, parentPath + "\\" + entryName, streamPaths);
        } else {
            // Add stream path to set of paths
            String filePath = parentPath + "\\" + entryName;
            AddStreamPath(filePath, streamPaths);
        }
    }
}

From source file:org.docx4j.openpackaging.parts.WordprocessingML.OleObjectBinaryPart.java

License:Apache License

/**
 * Adapted from org.apache.poi.poifs.dev.POIFSLister
 * @param dir//from  ww w .j  av a 2s  .c om
 * @param indent
 * @param withSizes
 * @throws IOException 
 * 
 */
private void displayDirectory(DirectoryNode dir, OutputStream os, String indent, boolean withSizes)
        throws IOException {
    System.out.println(indent + dir.getName() + " -");
    String newIndent = indent + "  ";

    boolean hadChildren = false;
    for (Iterator<Entry> it = dir.getEntries(); it.hasNext();) {
        hadChildren = true;
        Entry entry = it.next();
        if (entry instanceof DirectoryNode) {
            displayDirectory((DirectoryNode) entry, os, newIndent, withSizes);
        } else {
            DocumentNode doc = (DocumentNode) entry;
            String name = doc.getName();
            String size = "";
            if (name.charAt(0) < 10) {
                String altname = "(0x0" + (int) name.charAt(0) + ")" + name.substring(1);
                name = name.substring(1) + " <" + altname + ">";
            }
            if (withSizes) {
                size = " [" + doc.getSize() + " / 0x" + Integer.toHexString(doc.getSize()) + "]";
            }
            os.write((newIndent + name + size + "\n").getBytes());
        }
    }
    if (!hadChildren) {
        os.write((newIndent + "(no children)").getBytes());
    }
}

From source file:poi.hssf.usermodel.examples.EmeddedObjects.java

License:Apache License

public static void main(String[] args) throws Exception {
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0]));
    HSSFWorkbook workbook = new HSSFWorkbook(fs);
    for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
        //the OLE2 Class Name of the object
        String oleName = obj.getOLE2ClassName();
        if (oleName.equals("Worksheet")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, fs, false);
            //System.out.println(entry.getName() + ": " + embeddedWorkbook.getNumberOfSheets());
        } else if (oleName.equals("Document")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            HWPFDocument embeddedWordDocument = new HWPFDocument(dn);
            //System.out.println(entry.getName() + ": " + embeddedWordDocument.getRange().text());
        } else if (oleName.equals("Presentation")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            SlideShow embeddedPowerPointDocument = new SlideShow(new HSLFSlideShow(dn));
            //System.out.println(entry.getName() + ": " + embeddedPowerPointDocument.getSlides().length);
        } else {/*w  ww  . j  a  va  2 s .c o m*/
            if (obj.hasDirectoryEntry()) {
                // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is
                DirectoryNode dn = (DirectoryNode) obj.getDirectory();
                for (Iterator entries = dn.getEntries(); entries.hasNext();) {
                    Entry entry = (Entry) entries.next();
                    //System.out.println(oleName + "." + entry.getName());
                }
            } else {
                // There is no DirectoryEntry
                // Recover the object's data from the HSSFObjectData instance.
                byte[] objectData = obj.getObjectData();
            }
        }
    }
}