use of org.apache.poi.hpsf.SummaryInformation in project poi by apache.
the class HPSFFileHandler method handleFile.
@Override
public void handleFile(InputStream stream, String path) throws Exception {
Assume.assumeFalse(EXCLUDES_HANDLE_FILE.contains(path));
POIFSFileSystem poifs = new POIFSFileSystem(stream);
HPSFPropertiesOnlyDocument hpsf = new HPSFPropertiesOnlyDocument(poifs);
DocumentSummaryInformation dsi = hpsf.getDocumentSummaryInformation();
SummaryInformation si = hpsf.getSummaryInformation();
boolean hasDSI = hasPropertyStream(poifs, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
boolean hasSI = hasPropertyStream(poifs, SummaryInformation.DEFAULT_STREAM_NAME);
assertEquals(hasDSI, dsi != null);
assertEquals(hasSI, si != null);
handlePOIDocument(hpsf);
}
use of org.apache.poi.hpsf.SummaryInformation in project poi by apache.
the class POIDocument method writeProperties.
/**
* Writes out the standard Document Information Properties (HPSF)
* @param outFS the NPOIFSFileSystem to write the properties into
* @param writtenEntries a list of POIFS entries to add the property names too
*
* @throws IOException if an error when writing to the
* {@link NPOIFSFileSystem} occurs
*/
protected void writeProperties(NPOIFSFileSystem outFS, List<String> writtenEntries) throws IOException {
SummaryInformation si = getSummaryInformation();
if (si != null) {
writePropertySet(SummaryInformation.DEFAULT_STREAM_NAME, si, outFS);
if (writtenEntries != null) {
writtenEntries.add(SummaryInformation.DEFAULT_STREAM_NAME);
}
}
DocumentSummaryInformation dsi = getDocumentSummaryInformation();
if (dsi != null) {
writePropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME, dsi, outFS);
if (writtenEntries != null) {
writtenEntries.add(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
}
}
}
use of org.apache.poi.hpsf.SummaryInformation in project poi by apache.
the class ModifyDocumentSummaryInformation method main.
/**
* <p>Main method - see class description.</p>
*
* @param args The command-line parameters.
* @throws IOException
* @throws MarkUnsupportedException
* @throws NoPropertySetStreamException
* @throws UnexpectedPropertySetTypeException
* @throws WritingNotSupportedException
*/
public static void main(final String[] args) throws IOException, NoPropertySetStreamException, MarkUnsupportedException, UnexpectedPropertySetTypeException, WritingNotSupportedException {
/* Read the name of the POI filesystem to modify from the command line.
* For brevity to boundary check is performed on the command-line
* arguments. */
File summaryFile = new File(args[0]);
/* Open the POI filesystem. */
NPOIFSFileSystem poifs = new NPOIFSFileSystem(summaryFile, false);
/* Read the summary information. */
DirectoryEntry dir = poifs.getRoot();
SummaryInformation si;
try {
si = (SummaryInformation) PropertySetFactory.create(dir, SummaryInformation.DEFAULT_STREAM_NAME);
} catch (FileNotFoundException ex) {
// There is no summary information yet. We have to create a new one
si = PropertySetFactory.newSummaryInformation();
}
/* Change the author to "Rainer Klute". Any former author value will
* be lost. If there has been no author yet, it will be created. */
si.setAuthor("Rainer Klute");
System.out.println("Author changed to " + si.getAuthor() + ".");
/* Handling the document summary information is analogous to handling
* the summary information. An additional feature, however, are the
* custom properties. */
/* Read the document summary information. */
DocumentSummaryInformation dsi;
try {
dsi = (DocumentSummaryInformation) PropertySetFactory.create(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
} catch (FileNotFoundException ex) {
/* There is no document summary information yet. We have to create a
* new one. */
dsi = PropertySetFactory.newDocumentSummaryInformation();
}
/* Change the category to "POI example". Any former category value will
* be lost. If there has been no category yet, it will be created. */
dsi.setCategory("POI example");
System.out.println("Category changed to " + dsi.getCategory() + ".");
/* Read the custom properties. If there are no custom properties yet,
* the application has to create a new CustomProperties object. It will
* serve as a container for custom properties. */
CustomProperties customProperties = dsi.getCustomProperties();
if (customProperties == null)
customProperties = new CustomProperties();
/* Insert some custom properties into the container. */
customProperties.put("Key 1", "Value 1");
customProperties.put("Schlüssel 2", "Wert 2");
customProperties.put("Sample Number", new Integer(12345));
customProperties.put("Sample Boolean", Boolean.TRUE);
customProperties.put("Sample Date", new Date());
/* Read a custom property. */
Object value = customProperties.get("Sample Number");
System.out.println("Custom Sample Number is now " + value);
/* Write the custom properties back to the document summary
* information. */
dsi.setCustomProperties(customProperties);
/* Write the summary information and the document summary information
* to the POI filesystem. */
si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME);
dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME);
/* Write the POI filesystem back to the original file. Please note that
* in production code you should take care when write directly to the
* origin, to make sure you don't loose things on error */
poifs.writeFilesystem();
poifs.close();
}
use of org.apache.poi.hpsf.SummaryInformation in project poi by apache.
the class TestBasic method testSectionMethods.
/**
* <p>Tests the {@link Section} methods. The test file has two
* property sets: the first one is a {@link SummaryInformation},
* the second one is a {@link DocumentSummaryInformation}.</p>
*
* @exception IOException if an I/O exception occurs
* @exception HPSFException if any HPSF exception occurs
*/
@Test
public void testSectionMethods() throws IOException, HPSFException {
InputStream is = new ByteArrayInputStream(poiFiles.get(0).getBytes());
final SummaryInformation si = (SummaryInformation) PropertySetFactory.create(is);
final List<Section> sections = si.getSections();
final Section s = sections.get(0);
assertEquals(s.getFormatID(), SectionIDMap.SUMMARY_INFORMATION_ID);
assertNotNull(s.getProperties());
assertEquals(17, s.getPropertyCount());
assertEquals("Titel", s.getProperty(2));
assertEquals(1764, s.getSize());
}
use of org.apache.poi.hpsf.SummaryInformation in project poi by apache.
the class TestEmptyProperties method testPropertySetMethods.
/**
* <p>Tests the {@link PropertySet} methods. The test file has two
* property sets: the first one is a {@link SummaryInformation},
* the second one is a {@link DocumentSummaryInformation}.</p>
*
* @exception IOException if an I/O exception occurs
* @exception HPSFException if an HPSF operation fails
*/
@Test
public void testPropertySetMethods() throws IOException, HPSFException {
byte[] b = poiFiles.get(1).getBytes();
PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(b));
SummaryInformation s = (SummaryInformation) ps;
assertNull(s.getTitle());
assertNull(s.getSubject());
assertNotNull(s.getAuthor());
assertNull(s.getKeywords());
assertNull(s.getComments());
assertNotNull(s.getTemplate());
assertNotNull(s.getLastAuthor());
assertNotNull(s.getRevNumber());
assertEquals(s.getEditTime(), 0);
assertNull(s.getLastPrinted());
assertNull(s.getCreateDateTime());
assertNull(s.getLastSaveDateTime());
assertEquals(s.getPageCount(), 0);
assertEquals(s.getWordCount(), 0);
assertEquals(s.getCharCount(), 0);
assertNull(s.getThumbnail());
assertNull(s.getApplicationName());
}
Aggregations