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

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

Introduction

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

Prototype

public long getType() 

Source Link

Document

Returns the property's type.

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 a  va2s.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: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  .java 2s .co  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:poi.poifs.poibrowser.PropertySetDescriptorRenderer.java

License:Apache License

/**
 * <p>Returns a string representation of a {@link Section}.</p>
 * @param s the section//from w  w  w  .j av  a 2 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();
}