Example usage for org.apache.poi.hpsf Property getValue

List of usage examples for org.apache.poi.hpsf Property getValue

Introduction

In this page you can find the example usage for org.apache.poi.hpsf Property getValue.

Prototype

public Object getValue() 

Source Link

Document

Returns the property's value.

Usage

From source file:com.villemos.ispace.aperture.enricher.MicrosoftPropertyReader.java

License:Open Source License

public void processPOIFSReaderEvent(final POIFSReaderEvent event) {
    PropertySet ps = null;/*from   w ww  .  j av a  2 s .  c o  m*/
    try {
        ps = PropertySetFactory.create(event.getStream());
    } catch (NoPropertySetStreamException ex) {
        LOG.debug("No property set stream: \"" + event.getPath() + event.getName() + "\"");
        return;
    } catch (Exception ex) {
        LOG.error("Exception while processing microsoft property set " + ex);
    }

    /* Print the name of the property set stream: */
    LOG.debug("Property set stream \"" + event.getPath() + event.getName() + "\":");

    /* Print the list of sections: */
    List<Section> sections = ps.getSections();
    int nr = 0;
    for (Section sec : sections) {
        String s = HexDump.dump(sec.getFormatID().getBytes(), 0L, 0);
        s = s.substring(0, s.length() - 1);
        /* Print the number of properties in this section. */
        int propertyCount = sec.getPropertyCount();
        /* Print the properties: */
        Property[] properties = sec.getProperties();
        for (int i2 = 0; i2 < properties.length; i2++) {
            /* Print a single property: */
            Property p = properties[i2];
            long id = p.getID();
            long type = p.getType();
            Object value = p.getValue();

            String propertyName = sec.getPIDString(id);

            if (msProperties.containsKey(propertyName) == false) {
                String valueStr = value.toString();
                if (valueStr.equals("") == false) {
                    msProperties.put(propertyName, valueStr);
                }
            }
        }
    }
}

From source file:net.sf.mpxj.mpp.SummaryInformation.java

License:Open Source License

/**
 * This method reads the contents of a property set and returns
 * a map relating property IDs and values together.
 *
 * @param ps property set//from  ww w. j av  a2 s  . co  m
 * @return map
 */
@SuppressWarnings("unchecked")
private HashMap<Integer, Object> getPropertyMap(PropertySet ps) {
    HashMap<Integer, Object> map = new HashMap<Integer, Object>();
    Property[] properties;
    Property property;
    List<Section> sections = ps.getSections();
    int index = 100;

    for (Section section : sections) {
        properties = section.getProperties();
        for (int loop = 0; loop < properties.length; loop++) {
            property = properties[loop];
            // the following causes an "unnecessary cast" warning in JDK1.4
            // this is in place to ensure compatibility with JDK1.5
            map.put(Integer.valueOf(index + (int) property.getID()), property.getValue());
            //System.out.println ("id="+(index+property.getID())+" value="+property.getValue());
        }
        index += 100;
    }
    return (map);
}

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 ww w  . ja va 2 s  .c o m*/
        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 main(String[] args) throws Exception {
    //import org.apache.poi.poifs.dev.POIFSDump;
    //POIFSDump.main(args);

    SMOutputDocument xmldoc = SMOutputFactory.createOutputDocument(
            SMOutputFactory.getGlobalXMLOutputFactory().createXMLStreamWriter(System.out, "UTF-8"), "1.1",
            "UTF-8", true);

    xmldoc.setIndentation("\n ", 1, 2); // for unix linefeed, 2 spaces per level

    SMOutputElement xmlroot = xmldoc.addElement("properties");

    // Loop through arguments:
    for (int i = 0; i < args.length; i++) {
        SMOutputElement xd = xmlroot.addElement("document");
        xd.addAttribute("href", args[i]);
        HWPFDocument doc = new HWPFDocument(new FileInputStream(args[i]));

        // SummaryInformation
        SMOutputElement sie = xd.addElement("SummaryInformation");
        sie.addElement("ApplicationName").addCharacters(doc.getSummaryInformation().getApplicationName());
        sie.addElement("OSVersion").addCharacters("" + doc.getSummaryInformation().getOSVersion());
        sie.addElement("Author").addCharacters("" + doc.getSummaryInformation().getAuthor());
        sie.addElement("CharCount").addCharacters("" + doc.getSummaryInformation().getCharCount());
        sie.addElement("Comments").addCharacters("" + doc.getSummaryInformation().getComments());
        sie.addElement("EditTime").addCharacters("" + doc.getSummaryInformation().getEditTime());
        sie.addElement("Format").addCharacters("" + doc.getSummaryInformation().getFormat());
        sie.addElement("Keywords").addCharacters("" + doc.getSummaryInformation().getKeywords());
        sie.addElement("LastAuthor").addCharacters("" + doc.getSummaryInformation().getLastAuthor());
        sie.addElement("PageCount").addCharacters("" + doc.getSummaryInformation().getPageCount());
        sie.addElement("RevNumber").addCharacters("" + doc.getSummaryInformation().getRevNumber());
        sie.addElement("SectionCount").addCharacters("" + doc.getSummaryInformation().getSectionCount());
        sie.addElement("Security").addCharacters("" + doc.getSummaryInformation().getSecurity());
        sie.addElement("Subject").addCharacters("" + doc.getSummaryInformation().getSubject());
        sie.addElement("Template").addCharacters("" + doc.getSummaryInformation().getTemplate());
        sie.addElement("Title").addCharacters("" + doc.getSummaryInformation().getTitle());
        sie.addElement("WordCount").addCharacters("" + doc.getSummaryInformation().getWordCount());
        sie.addElement("CreatedDateTime").addCharacters("" + doc.getSummaryInformation().getCreateDateTime());
        sie.addElement("LastPrinted").addCharacters("" + doc.getSummaryInformation().getLastPrinted());
        sie.addElement("LastSaveDateTime")
                .addCharacters("" + doc.getSummaryInformation().getLastSaveDateTime());
        sie.addElement("Thumbnail").addCharacters("" + doc.getSummaryInformation().getThumbnail());

        // TextTable
        SMOutputElement tte = xd.addElement("TextTable");
        for (TextPiece tp : doc.getTextTable().getTextPieces()) {
            SMOutputElement tpe = tte.addElement("TextPiece");
            tpe.addAttribute("isUnicode", "" + tp.getPieceDescriptor().isUnicode());
            tpe.addCharacters(tp.getStringBuilder().toString());
        }/*from   w w w  . jav a2s. com*/

        // DocumentSummaryInformation
        SMOutputElement dsie = xd.addElement("DocumentSummaryInformation");
        dsie.addElement("ParCount").addCharacters("" + doc.getDocumentSummaryInformation().getParCount());
        dsie.addElement("ByteCount").addCharacters("" + doc.getDocumentSummaryInformation().getByteCount());
        dsie.addElement("HiddenCount").addCharacters("" + doc.getDocumentSummaryInformation().getHiddenCount());
        dsie.addElement("LineCount").addCharacters("" + doc.getDocumentSummaryInformation().getLineCount());
        dsie.addElement("MMClipCount").addCharacters("" + doc.getDocumentSummaryInformation().getMMClipCount());
        dsie.addElement("NoteCount").addCharacters("" + doc.getDocumentSummaryInformation().getNoteCount());
        dsie.addElement("SectionCount")
                .addCharacters("" + doc.getDocumentSummaryInformation().getSectionCount());
        dsie.addElement("SlideCount").addCharacters("" + doc.getDocumentSummaryInformation().getSlideCount());
        dsie.addElement("Format").addCharacters("" + doc.getDocumentSummaryInformation().getFormat());
        dsie.addElement("PresentationFormat")
                .addCharacters("" + doc.getDocumentSummaryInformation().getPresentationFormat());
        dsie.addElement("Company").addCharacters("" + doc.getDocumentSummaryInformation().getCompany());
        dsie.addElement("Category").addCharacters("" + doc.getDocumentSummaryInformation().getCategory());
        // Sections
        for (Object os : doc.getDocumentSummaryInformation().getSections()) {
            Section s = (Section) os;
            SMOutputElement se = dsie.addElement("Section");
            se.addElement("FormatID").addCharacters("" + s.getFormatID());
            se.addElement("CodePage").addCharacters("" + s.getCodepage());
            se.addElement("PropertyCount").addCharacters("" + s.getPropertyCount());
            for (Property sp : s.getProperties()) {
                SMOutputElement pe = se.addElement("Property");
                pe.addAttribute("class", sp.getValue().getClass().getCanonicalName());
                pe.addCharacters(sp.getValue().toString());
            }
        }
        SMOutputElement fte = xd.addElement("FontTable");
        for (Ffn f : doc.getFontTable().getFontNames()) {
            SMOutputElement fe = fte.addElement("Font");
            fe.addElement("MainFontName").addCharacters(f.getMainFontName());
            try {
                fe.addElement("AltFontName").addCharacters(f.getAltFontName());
            } catch (Exception e) {
                // Seems to fail, and no safe test found as yet.
            }
            fe.addElement("Size").addCharacters("" + f.getSize());
            fe.addElement("Weight").addCharacters("" + f.getWeight());
        }
        SMOutputElement pte = xd.addElement("PicturesTable");
        for (Picture p : doc.getPicturesTable().getAllPictures()) {
            SMOutputElement pe = pte.addElement("Picture");
            pe.addElement("MimeType").addCharacters(p.getMimeType());
            pe.addElement("Width").addCharacters("" + p.getWidth());
            pe.addElement("Height").addCharacters("" + p.getHeight());
            pe.addElement("HorizontalScalingFactor").addCharacters("" + p.getHorizontalScalingFactor());
            pe.addElement("VerticalScalingFactor").addCharacters("" + p.getVerticalScalingFactor());
            pe.addElement("Content").addCharacters("" + p.getContent());
        }
        //parseCompObj( new File(args[i]) );

        // This
        //System.out.println("Dumping " + args[i]);
        FileInputStream is = new FileInputStream(args[i]);
        POIFSFileSystem fs = new POIFSFileSystem(is);
        is.close();

        DirectoryEntry root = fs.getRoot();

        //dump(root);

        xmldoc.closeRoot(); // important, flushes, closes output

    }
}

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 ww  w  .ja 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:poi.poifs.poibrowser.PropertySetDescriptorRenderer.java

License:Apache License

/**
 * <p>Returns a string representation of a {@link Section}.</p>
 * @param s the section/*from   www .  j  av a2 s  .c  o  m*/
 * @param name the section's name
 * @return a string representation of the {@link Section}
 */
protected String toString(final Section s, final String name) {
    final StringBuffer b = new StringBuffer();
    b.append("\n" + name + " Format ID: ");
    b.append(Codec.hexEncode(s.getFormatID()));
    b.append("\n" + name + " Offset: " + s.getOffset());
    b.append("\n" + name + " Section size: " + s.getSize());
    b.append("\n" + name + " Property count: " + s.getPropertyCount());

    final Property[] properties = s.getProperties();
    for (int i = 0; i < properties.length; i++) {
        final Property p = properties[i];
        final long id = p.getID();
        final long type = p.getType();
        final Object value = p.getValue();
        b.append('\n');
        b.append(name);
        b.append(", Name: ");
        b.append(id);
        b.append(" (");
        b.append(s.getPIDString(id));
        b.append("), Type: ");
        b.append(type);
        b.append(", Value: ");
        if (value instanceof byte[]) {
            byte[] b2 = (byte[]) value;
            b.append("0x" + Codec.hexEncode(b2, 0, 4));
            b.append(' ');
            b.append("0x" + Codec.hexEncode(b2, 4, b2.length - 4));
        } else if (value != null)
            b.append(value.toString());
        else
            b.append("null");
    }
    return b.toString();
}

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

License:Open Source License

@Override
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
        throws IOException, SAXException, TikaException {

    HWPFDocument doc = new HWPFDocument(stream);
    System.out.println("ApplicationName: " + doc.getSummaryInformation().getApplicationName());
    System.out.println("OSVersion: " + doc.getSummaryInformation().getOSVersion());
    System.out.println("# paragraphs: " + doc.getDocumentSummaryInformation().getParCount());
    System.out.println("# bytes: " + doc.getDocumentSummaryInformation().getByteCount());
    System.out.println("# hidden: " + doc.getDocumentSummaryInformation().getHiddenCount());
    System.out.println("# lines: " + doc.getDocumentSummaryInformation().getLineCount());
    System.out.println("# mmclips: " + doc.getDocumentSummaryInformation().getMMClipCount());
    System.out.println("# notes: " + doc.getDocumentSummaryInformation().getNoteCount());
    System.out.println("# sections: " + doc.getDocumentSummaryInformation().getSectionCount());
    System.out.println("# slides: " + doc.getDocumentSummaryInformation().getSlideCount());
    System.out.println("format: " + doc.getDocumentSummaryInformation().getFormat());
    for (TextPiece tp : doc.getTextTable().getTextPieces()) {
        System.out.println("TP: " + tp.getStringBuffer().substring(0, 100));
        System.out.println("TP: " + tp.getPieceDescriptor().isUnicode());
    }/*from w  w  w.  j a v  a 2s .  c o  m*/
    for (Object os : doc.getDocumentSummaryInformation().getSections()) {
        Section s = (Section) os;
        System.out.println("ss# fid: " + s.getFormatID());
        System.out.println("ss# codepage: " + s.getCodepage());
        System.out.println("ss# # properties: " + s.getPropertyCount());
        for (Property sp : s.getProperties()) {
            System.out.println(
                    "ss# property: " + sp.getValue().getClass().getCanonicalName() + " " + sp.getValue());
        }
    }
    for (Ffn f : doc.getFontTable().getFontNames()) {
        System.out.println("Font: " + f.getMainFontName() + ", " + f.getSize() + ", " + f.getWeight());
    }
    parseCompObj(stream);

    // This
    POIFSFileSystem fs = new POIFSFileSystem(stream);

    DirectoryEntry root = fs.getRoot();

    dump(root);

}

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());
                    }//from w w w  . j  a  va2  s  .  com
                }
            } 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);
        }
    }
}