Search in sources :

Example 6 with PropertySet

use of org.apache.poi.hpsf.PropertySet in project poi by apache.

the class POIDocument method writePropertySet.

/**
     * Writes out a given ProperySet
     * @param name the (POIFS Level) name of the property to write
     * @param set the PropertySet to write out 
     * @param outFS the NPOIFSFileSystem to write the property into
     * 
     * @throws IOException if an error when writing to the 
     *      {@link NPOIFSFileSystem} occurs
     */
protected void writePropertySet(String name, PropertySet set, NPOIFSFileSystem outFS) throws IOException {
    try {
        PropertySet mSet = new PropertySet(set);
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        mSet.write(bOut);
        byte[] data = bOut.toByteArray();
        ByteArrayInputStream bIn = new ByteArrayInputStream(data);
        // Create or Update the Property Set stream in the POIFS
        outFS.createOrUpdateDocument(bIn, name);
        logger.log(POILogger.INFO, "Wrote property set " + name + " of size " + data.length);
    } catch (org.apache.poi.hpsf.WritingNotSupportedException wnse) {
        logger.log(POILogger.ERROR, "Couldn't write property set with name " + name + " as not supported by HPSF yet");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PropertySet(org.apache.poi.hpsf.PropertySet) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with PropertySet

use of org.apache.poi.hpsf.PropertySet in project poi by apache.

the class TestNPOIFSFileSystem method getDocumentEntry.

/**
    * Tests that we can get the correct contents for
    *  a document in the filesystem 
    */
@Test
public void getDocumentEntry() throws Exception {
    for (NPOIFSFileSystem fs : get512and4kFileAndInput()) {
        DirectoryEntry root = fs.getRoot();
        Entry si = root.getEntry("SummaryInformation");
        assertEquals(true, si.isDocumentEntry());
        DocumentNode doc = (DocumentNode) si;
        // Check we can read it
        assertContentsMatches(null, doc);
        // Now try to build the property set
        DocumentInputStream inp = new NDocumentInputStream(doc);
        PropertySet ps = PropertySetFactory.create(inp);
        SummaryInformation inf = (SummaryInformation) ps;
        // Check some bits in it
        assertEquals(null, inf.getApplicationName());
        assertEquals(null, inf.getAuthor());
        assertEquals(null, inf.getSubject());
        assertEquals(131333, inf.getOSVersion());
        // Finish with this one
        inp.close();
        // Try the other summary information
        si = root.getEntry("DocumentSummaryInformation");
        assertEquals(true, si.isDocumentEntry());
        doc = (DocumentNode) si;
        assertContentsMatches(null, doc);
        inp = new NDocumentInputStream(doc);
        ps = PropertySetFactory.create(inp);
        DocumentSummaryInformation dinf = (DocumentSummaryInformation) ps;
        assertEquals(131333, dinf.getOSVersion());
        fs.close();
    }
}
Also used : SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) PropertySet(org.apache.poi.hpsf.PropertySet) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) Test(org.junit.Test)

Example 8 with PropertySet

use of org.apache.poi.hpsf.PropertySet in project poi by apache.

the class PropertySetDescriptorRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(final JTree tree, final Object value, final boolean selectedCell, final boolean expanded, final boolean leaf, final int row, final boolean hasCellFocus) {
    final PropertySetDescriptor d = (PropertySetDescriptor) ((DefaultMutableTreeNode) value).getUserObject();
    final PropertySet ps = d.getPropertySet();
    final JPanel p = new JPanel();
    final JTextArea text = new JTextArea();
    text.setBackground(new Color(200, 255, 200));
    text.setFont(new Font("Monospaced", Font.PLAIN, 10));
    text.append(renderAsString(d));
    text.append("\nByte order: ");
    text.append(HexDump.toHex((short) ps.getByteOrder()));
    text.append("\nFormat: ");
    text.append(HexDump.toHex((short) ps.getFormat()));
    text.append("\nOS version: ");
    text.append(HexDump.toHex(ps.getOSVersion()));
    text.append("\nClass ID: ");
    text.append(HexDump.toHex(ps.getClassID().getBytes()));
    text.append("\nSection count: " + ps.getSectionCount());
    text.append(sectionsToString(ps.getSections()));
    p.add(text);
    if (ps instanceof SummaryInformation) {
        /* Use the convenience methods. */
        final SummaryInformation si = (SummaryInformation) ps;
        text.append("\n");
        text.append("\nTitle:               " + si.getTitle());
        text.append("\nSubject:             " + si.getSubject());
        text.append("\nAuthor:              " + si.getAuthor());
        text.append("\nKeywords:            " + si.getKeywords());
        text.append("\nComments:            " + si.getComments());
        text.append("\nTemplate:            " + si.getTemplate());
        text.append("\nLast Author:         " + si.getLastAuthor());
        text.append("\nRev. Number:         " + si.getRevNumber());
        text.append("\nEdit Time:           " + si.getEditTime());
        text.append("\nLast Printed:        " + si.getLastPrinted());
        text.append("\nCreate Date/Time:    " + si.getCreateDateTime());
        text.append("\nLast Save Date/Time: " + si.getLastSaveDateTime());
        text.append("\nPage Count:          " + si.getPageCount());
        text.append("\nWord Count:          " + si.getWordCount());
        text.append("\nChar Count:          " + si.getCharCount());
        // text.append("\nThumbnail:           " + si.getThumbnail());
        text.append("\nApplication Name:    " + si.getApplicationName());
        text.append("\nSecurity:            " + si.getSecurity());
    }
    if (selectedCell)
        Util.invert(text);
    return p;
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) Color(java.awt.Color) PropertySet(org.apache.poi.hpsf.PropertySet) Font(java.awt.Font)

Example 9 with PropertySet

use of org.apache.poi.hpsf.PropertySet in project poi by apache.

the class POIDocument method readProperties.

/**
     * Find, and create objects for, the standard
     *  Document Information Properties (HPSF).
     * If a given property set is missing or corrupt,
     *  it will remain null;
     */
protected void readProperties() {
    PropertySet ps;
    // DocumentSummaryInformation
    ps = getPropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
    if (ps instanceof DocumentSummaryInformation) {
        dsInf = (DocumentSummaryInformation) ps;
    } else if (ps != null) {
        logger.log(POILogger.WARN, "DocumentSummaryInformation property set came back with wrong class - ", ps.getClass());
    } else {
        logger.log(POILogger.WARN, "DocumentSummaryInformation property set came back as null");
    }
    // SummaryInformation
    ps = getPropertySet(SummaryInformation.DEFAULT_STREAM_NAME);
    if (ps instanceof SummaryInformation) {
        sInf = (SummaryInformation) ps;
    } else if (ps != null) {
        logger.log(POILogger.WARN, "SummaryInformation property set came back with wrong class - ", ps.getClass());
    } else {
        logger.log(POILogger.WARN, "SummaryInformation property set came back as null");
    }
    // Mark the fact that we've now loaded up the properties
    initialized = true;
}
Also used : SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) PropertySet(org.apache.poi.hpsf.PropertySet) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation)

Example 10 with PropertySet

use of org.apache.poi.hpsf.PropertySet in project tika by apache.

the class SummaryExtractor method parseSummaryEntryIfExists.

private void parseSummaryEntryIfExists(DirectoryNode root, String entryName) throws IOException, TikaException {
    try {
        DocumentEntry entry = (DocumentEntry) root.getEntry(entryName);
        PropertySet properties = new PropertySet(new DocumentInputStream(entry));
        if (properties.isSummaryInformation()) {
            parse(new SummaryInformation(properties));
        }
        if (properties.isDocumentSummaryInformation()) {
            parse(new DocumentSummaryInformation(properties));
        }
    } catch (FileNotFoundException e) {
    // entry does not exist, just skip it
    } catch (NoPropertySetStreamException e) {
    // no property stream, just skip it
    } catch (UnexpectedPropertySetTypeException e) {
        throw new TikaException("Unexpected HPSF document", e);
    } catch (MarkUnsupportedException e) {
        throw new TikaException("Invalid DocumentInputStream", e);
    } catch (Exception e) {
        LOG.warn("Ignoring unexpected exception while parsing summary entry {}", entryName, e);
    }
}
Also used : TikaException(org.apache.tika.exception.TikaException) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) DocumentEntry(org.apache.poi.poifs.filesystem.DocumentEntry) FileNotFoundException(java.io.FileNotFoundException) PropertySet(org.apache.poi.hpsf.PropertySet) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) NoPropertySetStreamException(org.apache.poi.hpsf.NoPropertySetStreamException) DocumentInputStream(org.apache.poi.poifs.filesystem.DocumentInputStream) UnexpectedPropertySetTypeException(org.apache.poi.hpsf.UnexpectedPropertySetTypeException) MarkUnsupportedException(org.apache.poi.hpsf.MarkUnsupportedException) NoPropertySetStreamException(org.apache.poi.hpsf.NoPropertySetStreamException) UnexpectedPropertySetTypeException(org.apache.poi.hpsf.UnexpectedPropertySetTypeException) TikaException(org.apache.tika.exception.TikaException) MarkUnsupportedException(org.apache.poi.hpsf.MarkUnsupportedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

PropertySet (org.apache.poi.hpsf.PropertySet)17 Test (org.junit.Test)10 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DocumentSummaryInformation (org.apache.poi.hpsf.DocumentSummaryInformation)6 SummaryInformation (org.apache.poi.hpsf.SummaryInformation)6 MutablePropertySet (org.apache.poi.hpsf.MutablePropertySet)5 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)5 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)5 MutableSection (org.apache.poi.hpsf.MutableSection)4 Section (org.apache.poi.hpsf.Section)4 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 NoPropertySetStreamException (org.apache.poi.hpsf.NoPropertySetStreamException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2