use of org.apache.poi.hpsf.SummaryInformation in project poi by apache.
the class AbstractWordConverter method processDocument.
public void processDocument(HWPFDocumentCore wordDocument) {
try {
final SummaryInformation summaryInformation = wordDocument.getSummaryInformation();
if (summaryInformation != null) {
processDocumentInformation(summaryInformation);
}
} catch (Exception exc) {
logger.log(POILogger.WARN, "Unable to process document summary information: ", exc, exc);
}
final Range docRange = wordDocument.getRange();
if (docRange.numSections() == 1) {
processSingleSection(wordDocument, docRange.getSection(0));
afterProcess();
return;
}
processDocumentPart(wordDocument, docRange);
afterProcess();
}
use of org.apache.poi.hpsf.SummaryInformation in project poi by apache.
the class ExcelToHtmlConverter method processWorkbook.
public void processWorkbook(HSSFWorkbook workbook) {
final SummaryInformation summaryInformation = workbook.getSummaryInformation();
if (summaryInformation != null) {
processDocumentInformation(summaryInformation);
}
if (isUseDivsToSpan()) {
// prepare CSS classes for later usage
this.cssClassContainerCell = htmlDocumentFacade.getOrCreateCssClass(cssClassPrefixCell, "padding:0;margin:0;align:left;vertical-align:top;");
this.cssClassContainerDiv = htmlDocumentFacade.getOrCreateCssClass(cssClassPrefixDiv, "position:relative;");
}
for (int s = 0; s < workbook.getNumberOfSheets(); s++) {
HSSFSheet sheet = workbook.getSheetAt(s);
processSheet(sheet);
}
htmlDocumentFacade.updateStylesheet();
}
use of org.apache.poi.hpsf.SummaryInformation in project poi by apache.
the class TestWriteWellKnown method write2ndFile.
/*
* Open <em>doc2</em> for reading and check summary information and
* document summary information. All properties written before must be
* found in the property streams of <em>doc2</em> and have the correct
* values.
*/
private static CustomProperties write2ndFile(File fileIn, File fileOut) throws Exception {
NPOIFSFileSystem poifs = new NPOIFSFileSystem(fileIn, false);
SummaryInformation si = getSummaryInformation(poifs);
DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs);
assertEquals(P_APPLICATION_NAME, si.getApplicationName());
assertEquals(P_AUTHOR, si.getAuthor());
assertEquals(P_CHAR_COUNT, si.getCharCount());
assertEquals(P_COMMENTS, si.getComments());
assertEquals(P_CREATE_DATE_TIME, si.getCreateDateTime());
assertEquals(P_EDIT_TIME, si.getEditTime());
assertEquals(P_KEYWORDS, si.getKeywords());
assertEquals(P_LAST_AUTHOR, si.getLastAuthor());
assertEquals(P_LAST_PRINTED, si.getLastPrinted());
assertEquals(P_LAST_SAVE_DATE_TIME, si.getLastSaveDateTime());
assertEquals(P_PAGE_COUNT, si.getPageCount());
assertEquals(P_REV_NUMBER, si.getRevNumber());
assertEquals(P_SECURITY, si.getSecurity());
assertEquals(P_SUBJECT, si.getSubject());
assertEquals(P_TEMPLATE, si.getTemplate());
// FIXME (byte array properties not yet implemented): assertEquals(P_THUMBNAIL, si.getThumbnail());
assertEquals(P_TITLE, si.getTitle());
assertEquals(P_WORD_COUNT, si.getWordCount());
assertEquals(P_BYTE_COUNT, dsi.getByteCount());
assertEquals(P_CATEGORY, dsi.getCategory());
assertEquals(P_COMPANY, dsi.getCompany());
// FIXME (byte array properties not yet implemented): assertEquals(P_, dsi.getDocparts());
// FIXME (byte array properties not yet implemented): assertEquals(P_, dsi.getHeadingPair());
assertEquals(P_HIDDEN_COUNT, dsi.getHiddenCount());
assertEquals(P_LINE_COUNT, dsi.getLineCount());
assertEquals(P_LINKS_DIRTY, dsi.getLinksDirty());
assertEquals(P_MANAGER, dsi.getManager());
assertEquals(P_MM_CLIP_COUNT, dsi.getMMClipCount());
assertEquals(P_NOTE_COUNT, dsi.getNoteCount());
assertEquals(P_PAR_COUNT, dsi.getParCount());
assertEquals(P_PRESENTATION_FORMAT, dsi.getPresentationFormat());
assertEquals(P_SCALE, dsi.getScale());
assertEquals(P_SLIDE_COUNT, dsi.getSlideCount());
final CustomProperties cps = dsi.getCustomProperties();
assertNotNull(cps);
assertNull(cps.get("No value available"));
assertEquals("Wert ä", cps.get("Schlüssel ä"));
assertEquals("Wert äö", cps.get("Schlüssel äö"));
assertEquals("Wert äöü", cps.get("Schlüssel äöü"));
assertEquals("Wert äöüÖ", cps.get("Schlüssel äöüÖ"));
assertEquals(POSITIVE_INTEGER, cps.get("positive_Integer"));
assertEquals(POSITIVE_LONG, cps.get("positive_Long"));
assertEquals(POSITIVE_DOUBLE, cps.get("positive_Double"));
assertEquals(NEGATIVE_INTEGER, cps.get("negative_Integer"));
assertEquals(NEGATIVE_LONG, cps.get("negative_Long"));
assertEquals(NEGATIVE_DOUBLE, cps.get("negative_Double"));
assertEquals(Boolean.TRUE, cps.get("Boolean"));
assertEquals(now, cps.get("Date"));
assertEquals(MAX_INTEGER, cps.get("max_Integer"));
assertEquals(MIN_INTEGER, cps.get("min_Integer"));
assertEquals(MAX_LONG, cps.get("max_Long"));
assertEquals(MIN_LONG, cps.get("min_Long"));
assertEquals(MAX_DOUBLE, cps.get("max_Double"));
assertEquals(MIN_DOUBLE, cps.get("min_Double"));
/* Remove all properties supported by HPSF from the summary
* information (e.g. author, edit date, application name) and from the
* document summary information (e.g. company, manager). */
si.removeApplicationName();
si.removeAuthor();
si.removeCharCount();
si.removeComments();
si.removeCreateDateTime();
si.removeEditTime();
si.removeKeywords();
si.removeLastAuthor();
si.removeLastPrinted();
si.removeLastSaveDateTime();
si.removePageCount();
si.removeRevNumber();
si.removeSecurity();
si.removeSubject();
si.removeTemplate();
si.removeThumbnail();
si.removeTitle();
si.removeWordCount();
dsi.removeByteCount();
dsi.removeCategory();
dsi.removeCompany();
dsi.removeCustomProperties();
dsi.removeDocparts();
dsi.removeHeadingPair();
dsi.removeHiddenCount();
dsi.removeLineCount();
dsi.removeLinksDirty();
dsi.removeManager();
dsi.removeMMClipCount();
dsi.removeNoteCount();
dsi.removeParCount();
dsi.removePresentationFormat();
dsi.removeScale();
dsi.removeSlideCount();
// Write the summary information stream and the document summary
// information stream to the POI filesystem.
si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
// Write the POI filesystem to a (temporary) file doc3 and close the latter.
FileOutputStream out = new FileOutputStream(fileOut);
poifs.writeFilesystem(out);
out.close();
poifs.close();
return cps;
}
use of org.apache.poi.hpsf.SummaryInformation 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.SummaryInformation in project poi by apache.
the class TestNPOIFSFileSystem method readWriteRead.
/**
* Read a file, write it and read it again.
* Then, alter+add some streams, write and read
*/
@Test
public void readWriteRead() throws Exception {
SummaryInformation sinf;
DocumentSummaryInformation dinf;
DirectoryEntry root, testDir;
for (NPOIFSFileSystem fs1 : get512and4kFileAndInput()) {
// Check we can find the entries we expect
root = fs1.getRoot();
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Tags"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
// Write out, re-load
NPOIFSFileSystem fs2 = writeOutAndReadBack(fs1);
fs1.close();
// Check they're still there
root = fs2.getRoot();
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Tags"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
// Check the contents of them - parse the summary block and check
sinf = (SummaryInformation) PropertySetFactory.create(new NDocumentInputStream((DocumentEntry) root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, sinf.getOSVersion());
dinf = (DocumentSummaryInformation) PropertySetFactory.create(new NDocumentInputStream((DocumentEntry) root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, dinf.getOSVersion());
// Add a test mini stream
testDir = root.createDirectory("Testing 123");
testDir.createDirectory("Testing 456");
testDir.createDirectory("Testing 789");
byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
testDir.createDocument("Mini", new ByteArrayInputStream(mini));
// Write out, re-load
NPOIFSFileSystem fs3 = writeOutAndReadBack(fs2);
fs2.close();
root = fs3.getRoot();
testDir = (DirectoryEntry) root.getEntry("Testing 123");
assertEquals(6, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Tags"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
// Check old and new are there
sinf = (SummaryInformation) PropertySetFactory.create(new NDocumentInputStream((DocumentEntry) root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, sinf.getOSVersion());
dinf = (DocumentSummaryInformation) PropertySetFactory.create(new NDocumentInputStream((DocumentEntry) root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, dinf.getOSVersion());
assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini"));
// Write out and read once more, just to be sure
NPOIFSFileSystem fs4 = writeOutAndReadBack(fs3);
fs3.close();
root = fs4.getRoot();
testDir = (DirectoryEntry) root.getEntry("Testing 123");
assertEquals(6, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Tags"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
sinf = (SummaryInformation) PropertySetFactory.create(new NDocumentInputStream((DocumentEntry) root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, sinf.getOSVersion());
dinf = (DocumentSummaryInformation) PropertySetFactory.create(new NDocumentInputStream((DocumentEntry) root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, dinf.getOSVersion());
assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini"));
// Add a full stream, delete a full stream
byte[] main4096 = new byte[4096];
main4096[0] = -10;
main4096[4095] = -11;
testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
root.getEntry("Tags").delete();
// Write out, re-load
NPOIFSFileSystem fs5 = writeOutAndReadBack(fs4);
fs4.close();
// Check it's all there
root = fs5.getRoot();
testDir = (DirectoryEntry) root.getEntry("Testing 123");
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
// Check old and new are there
sinf = (SummaryInformation) PropertySetFactory.create(new NDocumentInputStream((DocumentEntry) root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, sinf.getOSVersion());
dinf = (DocumentSummaryInformation) PropertySetFactory.create(new NDocumentInputStream((DocumentEntry) root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, dinf.getOSVersion());
assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini"));
assertContentsMatches(main4096, (DocumentEntry) testDir.getEntry("Normal4096"));
// Delete a directory, and add one more
testDir.getEntry("Testing 456").delete();
testDir.createDirectory("Testing ABC");
// Save
NPOIFSFileSystem fs6 = writeOutAndReadBack(fs5);
fs5.close();
// Check
root = fs6.getRoot();
testDir = (DirectoryEntry) root.getEntry("Testing 123");
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
assertEquals(4, testDir.getEntryCount());
assertThat(testDir.getEntryNames(), hasItem("Mini"));
assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
// Add another mini stream
byte[] mini2 = new byte[] { -42, 0, -1, -2, -3, -4, -42 };
testDir.createDocument("Mini2", new ByteArrayInputStream(mini2));
// Save, load, check
NPOIFSFileSystem fs7 = writeOutAndReadBack(fs6);
fs6.close();
root = fs7.getRoot();
testDir = (DirectoryEntry) root.getEntry("Testing 123");
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
assertEquals(5, testDir.getEntryCount());
assertThat(testDir.getEntryNames(), hasItem("Mini"));
assertThat(testDir.getEntryNames(), hasItem("Mini2"));
assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini"));
assertContentsMatches(mini2, (DocumentEntry) testDir.getEntry("Mini2"));
assertContentsMatches(main4096, (DocumentEntry) testDir.getEntry("Normal4096"));
// Delete a mini stream, add one more
testDir.getEntry("Mini").delete();
byte[] mini3 = new byte[] { 42, 0, 42, 0, 42, 0, 42 };
testDir.createDocument("Mini3", new ByteArrayInputStream(mini3));
// Save, load, check
NPOIFSFileSystem fs8 = writeOutAndReadBack(fs7);
fs7.close();
root = fs8.getRoot();
testDir = (DirectoryEntry) root.getEntry("Testing 123");
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
assertEquals(5, testDir.getEntryCount());
assertThat(testDir.getEntryNames(), hasItem("Mini2"));
assertThat(testDir.getEntryNames(), hasItem("Mini3"));
assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
assertContentsMatches(mini2, (DocumentEntry) testDir.getEntry("Mini2"));
assertContentsMatches(mini3, (DocumentEntry) testDir.getEntry("Mini3"));
assertContentsMatches(main4096, (DocumentEntry) testDir.getEntry("Normal4096"));
// Change some existing streams
NPOIFSDocument mini2Doc = new NPOIFSDocument((DocumentNode) testDir.getEntry("Mini2"));
mini2Doc.replaceContents(new ByteArrayInputStream(mini));
byte[] main4106 = new byte[4106];
main4106[0] = 41;
main4106[4105] = 42;
NPOIFSDocument mainDoc = new NPOIFSDocument((DocumentNode) testDir.getEntry("Normal4096"));
mainDoc.replaceContents(new ByteArrayInputStream(main4106));
// Re-check
NPOIFSFileSystem fs9 = writeOutAndReadBack(fs8);
fs8.close();
root = fs9.getRoot();
testDir = (DirectoryEntry) root.getEntry("Testing 123");
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("SummaryInformation"));
assertEquals(5, testDir.getEntryCount());
assertThat(testDir.getEntryNames(), hasItem("Mini2"));
assertThat(testDir.getEntryNames(), hasItem("Mini3"));
assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
assertContentsMatches(mini, (DocumentEntry) testDir.getEntry("Mini2"));
assertContentsMatches(mini3, (DocumentEntry) testDir.getEntry("Mini3"));
assertContentsMatches(main4106, (DocumentEntry) testDir.getEntry("Normal4096"));
// All done
fs9.close();
}
}
Aggregations