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");
}
}
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();
}
}
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;
}
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;
}
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);
}
}
Aggregations