Example usage for org.apache.poi.hpsf PropertySet getProperties

List of usage examples for org.apache.poi.hpsf PropertySet getProperties

Introduction

In this page you can find the example usage for org.apache.poi.hpsf PropertySet getProperties.

Prototype

public Property[] getProperties() throws NoSingleSectionException 

Source Link

Document

Convenience method returning the Property array contained in this property set.

Usage

From source file:org.ddt.listener.dsi.DocumentSummaryInfoListener.java

License:Apache License

public void processPOIFSReaderEvent(POIFSReaderEvent event) {
    log.log(Level.FINEST, "reading {0}{1}", new Object[] { event.getPath(), event.getName() });
    DocumentInputStream is = event.getStream();
    try {//from   w  w w  . j a v a2s  .  com
        PropertySet ps = PropertySetFactory.create(is);

        if (!(ps instanceof DocumentSummaryInformation))
            return;

        Property docparts = null;
        Property headings = null;
        for (Property prop : ps.getProperties()) {
            if (prop.getID() == PropertyIDMap.PID_HEADINGPAIR) // == 12
                headings = prop;
            else if (prop.getID() == PropertyIDMap.PID_DOCPARTS)
                docparts = prop;
        }

        if (docparts == null) {
            log.log(Level.FINE, "No DOCPARTS section");
            return;
        }

        if (headings == null)
            return;

        HeadingPairVector hdv = new HeadingPairVector((byte[]) headings.getValue(), 0);

        StringVector docpartsVector = new StringVector((byte[]) docparts.getValue(), 0, docparts.getType());

        HeadingPairProperty linkHeader = hdv.getHeadingPairByName("Links"); //*NOT* null terminated

        if (linkHeader == null) {
            log.log(Level.INFO, "No 'Links' header found.");
            return;
        } else {
            log.log(Level.FINEST, "Found {0} link parts", linkHeader.getPartsCount());
        }

        //need to iterate through all of the ones if there's more than one
        //docpart for the header.
        int part = linkHeader.getOffset();
        for (int i = 0; i < linkHeader.getPartsCount(); i++) {
            String url = docpartsVector.get(part).getValue();
            log.log(Level.FINEST, "adding {0} to list of links.", url);
            url = url.trim();
            Link l = new Link(3);
            l.addUnkownPath(url);
            this.add(l);
            part++;
        }

    } catch (NoPropertySetStreamException ex) {
        log.log(Level.INFO, "Not a PropertySetStream {0}{1}",
                new Object[] { event.getPath(), event.getName() });
    } catch (MarkUnsupportedException ex) {
        log.log(Level.INFO, "Couldn't create PropertySet: {0}", ex.getLocalizedMessage());
    } catch (UnsupportedEncodingException ex) {
        log.log(Level.INFO, null, ex);
    } catch (IOException ex) {
        log.log(Level.INFO, null, ex);
    } catch (HPSFException ex) {
        log.log(Level.WARNING, "Couldn't construct HeadingPair vector.", ex);
    } finally {
        is.close();
    }
}

From source file:org.opf_labs.aqua.OfficeAnalyser.java

License:Apache License

public static void dump(DirectoryEntry root) throws IOException {
    System.out.println(root.getName() + " : storage CLSID " + root.getStorageClsid());
    for (Iterator it = root.getEntries(); it.hasNext();) {
        Entry entry = (Entry) it.next();
        if (entry instanceof DocumentNode) {
            DocumentNode node = (DocumentNode) entry;
            System.out.println("Node name: " + node.getName());
            System.out.println("Node desc: " + node.getShortDescription());
            System.out.println("Node size: " + node.getSize());
            DocumentInputStream is = new DocumentInputStream(node);

            try {
                PropertySet ps = new PropertySet(is);
                if (ps.getSectionCount() != 0) {
                    for (Property p : ps.getProperties()) {
                        System.out.println("Prop: " + p.getID() + " " + p.getValue());
                    }//from w  w  w .j a v  a  2s .  co m
                }
            } catch (NoPropertySetStreamException e) {
                // TODO Auto-generated catch block
                //e.printStackTrace();
            } catch (MarkUnsupportedException e) {
                // TODO Auto-generated catch block
                //e.printStackTrace();
            }
            //byte[] bytes = new byte[node.getSize()];
            //is.read(bytes);
            //is.close();

            //FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
            //out.write(bytes);
            //out.close();
            //System.out.println("Node: "+new String(bytes).substring(0, 10));
        } else if (entry instanceof DirectoryEntry) {
            DirectoryEntry dir = (DirectoryEntry) entry;
            dump(dir);
        } else {
            System.err.println("Skipping unsupported POIFS entry: " + entry);
        }
    }
}

From source file:uk.bl.wa.tika.parser.ole2.OLE2Parser.java

License:Open Source License

public static void dump(DirectoryEntry root) throws IOException {
    System.out.println(root.getName() + " : storage CLSID " + root.getStorageClsid());
    for (Iterator it = root.getEntries(); it.hasNext();) {
        Entry entry = (Entry) it.next();
        if (entry instanceof DocumentNode) {
            DocumentNode node = (DocumentNode) entry;
            System.out.println("Node name: " + node.getName());
            System.out.println("Node desc: " + node.getShortDescription());
            System.out.println("Node size: " + node.getSize());
            DocumentInputStream is = new DocumentInputStream(node);

            try {
                PropertySet ps = new PropertySet(is);
                if (ps.getSectionCount() != 0) {
                    for (Property p : ps.getProperties()) {
                        System.out.println("Prop: " + p.getID() + " " + p.getValue());
                    }// w  w w.  ja  va 2s .co m
                }
            } catch (NoPropertySetStreamException e) {
                // TODO Auto-generated catch block
                //e.printStackTrace();
            }
            //byte[] bytes = new byte[node.getSize()];
            //is.read(bytes);
            //is.close();

            //FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
            //out.write(bytes);
            //out.close();
            //System.out.println("Node: "+new String(bytes).substring(0, 10));
        } else if (entry instanceof DirectoryEntry) {
            DirectoryEntry dir = (DirectoryEntry) entry;
            dump(dir);
        } else {
            System.err.println("Skipping unsupported POIFS entry: " + entry);
        }
    }
}