Search in sources :

Example 16 with SummaryInformation

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

the class TestWriteWellKnown method write1stFile.

/*
     * Write all properties supported by HPSF to the summary information
     * (e.g. author, edit date, application name) and to the document
     * summary information (e.g. company, manager).
     */
private static CustomProperties write1stFile(File fileIn, File fileOut) throws Exception {
    /* Read a test document <em>doc1</em> into a POI filesystem. */
    NPOIFSFileSystem poifs = new NPOIFSFileSystem(fileIn, false);
    /*
         * Read the summary information stream and the document summary
         * information stream from the POI filesystem.
         *
         * Please note that the result consists of SummaryInformation and
         * DocumentSummaryInformation instances which are in memory only. To
         * make them permanent they have to be written to a POI filesystem
         * explicitly (overwriting the former contents). Then the POI filesystem
         * should be saved to a file.
         */
    SummaryInformation si = getSummaryInformation(poifs);
    DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs);
    si.setApplicationName(P_APPLICATION_NAME);
    si.setAuthor(P_AUTHOR);
    si.setCharCount(P_CHAR_COUNT);
    si.setComments(P_COMMENTS);
    si.setCreateDateTime(P_CREATE_DATE_TIME);
    si.setEditTime(P_EDIT_TIME);
    si.setKeywords(P_KEYWORDS);
    si.setLastAuthor(P_LAST_AUTHOR);
    si.setLastPrinted(P_LAST_PRINTED);
    si.setLastSaveDateTime(P_LAST_SAVE_DATE_TIME);
    si.setPageCount(P_PAGE_COUNT);
    si.setRevNumber(P_REV_NUMBER);
    si.setSecurity(P_SECURITY);
    si.setSubject(P_SUBJECT);
    si.setTemplate(P_TEMPLATE);
    // FIXME (byte array properties not yet implemented): si.setThumbnail(P_THUMBNAIL);
    si.setTitle(P_TITLE);
    si.setWordCount(P_WORD_COUNT);
    dsi.setByteCount(P_BYTE_COUNT);
    dsi.setCategory(P_CATEGORY);
    dsi.setCompany(P_COMPANY);
    // FIXME (byte array properties not yet implemented): dsi.setDocparts(P_DOCPARTS);
    // FIXME (byte array properties not yet implemented): dsi.setHeadingPair(P_HEADING_PAIR);
    dsi.setHiddenCount(P_HIDDEN_COUNT);
    dsi.setLineCount(P_LINE_COUNT);
    dsi.setLinksDirty(P_LINKS_DIRTY);
    dsi.setManager(P_MANAGER);
    dsi.setMMClipCount(P_MM_CLIP_COUNT);
    dsi.setNoteCount(P_NOTE_COUNT);
    dsi.setParCount(P_PAR_COUNT);
    dsi.setPresentationFormat(P_PRESENTATION_FORMAT);
    dsi.setScale(P_SCALE);
    dsi.setSlideCount(P_SLIDE_COUNT);
    CustomProperties cps = dsi.getCustomProperties();
    assertNull(cps);
    cps = new CustomProperties();
    cps.put("Schlüssel ä", "Wert ä");
    cps.put("Schlüssel äö", "Wert äö");
    cps.put("Schlüssel äöü", "Wert äöü");
    cps.put("Schlüssel äöüÖ", "Wert äöüÖ");
    cps.put("positive_Integer", POSITIVE_INTEGER);
    cps.put("positive_Long", POSITIVE_LONG);
    cps.put("positive_Double", POSITIVE_DOUBLE);
    cps.put("negative_Integer", NEGATIVE_INTEGER);
    cps.put("negative_Long", NEGATIVE_LONG);
    cps.put("negative_Double", NEGATIVE_DOUBLE);
    cps.put("Boolean", Boolean.TRUE);
    cps.put("Date", now);
    cps.put("max_Integer", MAX_INTEGER);
    cps.put("min_Integer", MIN_INTEGER);
    cps.put("max_Long", MAX_LONG);
    cps.put("min_Long", MIN_LONG);
    cps.put("max_Double", MAX_DOUBLE);
    cps.put("min_Double", MIN_DOUBLE);
    // Check the keys went in
    assertTrue(cps.containsKey("Schlüssel ä"));
    assertTrue(cps.containsKey("Boolean"));
    // Check the values went in
    assertEquals("Wert ä", cps.get("Schlüssel ä"));
    assertEquals(Boolean.TRUE, cps.get("Boolean"));
    assertTrue(cps.containsValue(Boolean.TRUE));
    assertTrue(cps.containsValue("Wert ä"));
    // Check that things that aren't in aren't in
    assertFalse(cps.containsKey("False Boolean"));
    assertFalse(cps.containsValue(Boolean.FALSE));
    // Save as our custom properties
    dsi.setCustomProperties(cps);
    /* 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 <em>doc2</em>
         * and close the latter. */
    OutputStream out = new FileOutputStream(fileOut);
    poifs.writeFilesystem(out);
    out.close();
    poifs.close();
    return cps;
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) CustomProperties(org.apache.poi.hpsf.CustomProperties)

Example 17 with SummaryInformation

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

the class TestWriteWellKnown method getSummaryInformation.

private static SummaryInformation getSummaryInformation(NPOIFSFileSystem poifs) throws Exception {
    DocumentInputStream dis = poifs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME);
    PropertySet ps = new PropertySet(dis);
    SummaryInformation si = new SummaryInformation(ps);
    dis.close();
    return si;
}
Also used : SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) PropertySet(org.apache.poi.hpsf.PropertySet) DocumentInputStream(org.apache.poi.poifs.filesystem.DocumentInputStream)

Example 18 with SummaryInformation

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

the class TestWriteWellKnown method write3rdFile.

/*
     * Open {@code doc3} for reading and check summary information
     * and document summary information. All properties removed before must not
     * be found in the property streams of {@code doc3}.
     */
private static CustomProperties write3rdFile(File fileIn, File fileOut) throws Exception {
    NPOIFSFileSystem poifs = new NPOIFSFileSystem(fileIn, false);
    SummaryInformation si = getSummaryInformation(poifs);
    DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs);
    assertNull(si.getApplicationName());
    assertNull(si.getAuthor());
    assertEquals(0, si.getCharCount());
    assertTrue(si.wasNull());
    assertNull(si.getComments());
    assertNull(si.getCreateDateTime());
    assertEquals(0, si.getEditTime());
    assertTrue(si.wasNull());
    assertNull(si.getKeywords());
    assertNull(si.getLastAuthor());
    assertNull(si.getLastPrinted());
    assertNull(si.getLastSaveDateTime());
    assertEquals(0, si.getPageCount());
    assertTrue(si.wasNull());
    assertNull(si.getRevNumber());
    assertEquals(0, si.getSecurity());
    assertTrue(si.wasNull());
    assertNull(si.getSubject());
    assertNull(si.getTemplate());
    assertNull(si.getThumbnail());
    assertNull(si.getTitle());
    assertEquals(0, si.getWordCount());
    assertTrue(si.wasNull());
    assertEquals(0, dsi.getByteCount());
    assertTrue(dsi.wasNull());
    assertNull(dsi.getCategory());
    assertNull(dsi.getCustomProperties());
    // FIXME (byte array properties not yet implemented): assertNull(dsi.getDocparts());
    // FIXME (byte array properties not yet implemented): assertNull(dsi.getHeadingPair());
    assertEquals(0, dsi.getHiddenCount());
    assertTrue(dsi.wasNull());
    assertEquals(0, dsi.getLineCount());
    assertTrue(dsi.wasNull());
    assertFalse(dsi.getLinksDirty());
    assertTrue(dsi.wasNull());
    assertNull(dsi.getManager());
    assertEquals(0, dsi.getMMClipCount());
    assertTrue(dsi.wasNull());
    assertEquals(0, dsi.getNoteCount());
    assertTrue(dsi.wasNull());
    assertEquals(0, dsi.getParCount());
    assertTrue(dsi.wasNull());
    assertNull(dsi.getPresentationFormat());
    assertFalse(dsi.getScale());
    assertTrue(dsi.wasNull());
    assertEquals(0, dsi.getSlideCount());
    assertTrue(dsi.wasNull());
    poifs.close();
    return dsi.getCustomProperties();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation)

Example 19 with SummaryInformation

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

the class TestHPSFBugs method test54233.

/**
    * Some files seem to want the length and data to be on a 4-byte boundary,
    * and without that you'll hit an ArrayIndexOutOfBoundsException after
    * reading junk
    */
@Test
public void test54233() throws IOException, NoPropertySetStreamException, MarkUnsupportedException {
    InputStream is = _samples.openResourceAsStream("TestNon4ByteBoundary.doc");
    NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
    is.close();
    SummaryInformation si = (SummaryInformation) PropertySetFactory.create(fs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
    DocumentSummaryInformation dsi = (DocumentSummaryInformation) PropertySetFactory.create(fs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
    // Test
    assertEquals("Microsoft Word 10.0", si.getApplicationName());
    assertEquals("", si.getTitle());
    assertEquals("", si.getAuthor());
    assertEquals("Cour de Justice", dsi.getCompany());
    // Write out and read back, should still be valid
    POIDocument doc = new HPSFPropertiesOnlyDocument(fs);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doc.write(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    doc = new HPSFPropertiesOnlyDocument(new NPOIFSFileSystem(bais));
    // Check properties are still there
    assertEquals("Microsoft Word 10.0", si.getApplicationName());
    assertEquals("", si.getTitle());
    assertEquals("", si.getAuthor());
    assertEquals("Cour de Justice", dsi.getCompany());
    doc.close();
    fs.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) POIDocument(org.apache.poi.POIDocument) HPSFPropertiesOnlyDocument(org.apache.poi.hpsf.HPSFPropertiesOnlyDocument) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 20 with SummaryInformation

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

the class TestHPSFBugs method test56138.

/**
    * CodePage Strings can be zero length
    */
@Test
public void test56138() throws IOException, NoPropertySetStreamException {
    InputStream is = _samples.openResourceAsStream("TestZeroLengthCodePage.mpp");
    NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
    is.close();
    SummaryInformation si = (SummaryInformation) PropertySetFactory.create(fs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
    DocumentSummaryInformation dsi = (DocumentSummaryInformation) PropertySetFactory.create(fs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
    // Test
    assertEquals("MSProject", si.getApplicationName());
    assertEquals("project1", si.getTitle());
    assertEquals("Jon Iles", si.getAuthor());
    assertEquals("", dsi.getCompany());
    assertEquals(2, dsi.getSectionCount());
    fs.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SummaryInformation(org.apache.poi.hpsf.SummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) DocumentSummaryInformation(org.apache.poi.hpsf.DocumentSummaryInformation) Test(org.junit.Test)

Aggregations

SummaryInformation (org.apache.poi.hpsf.SummaryInformation)22 DocumentSummaryInformation (org.apache.poi.hpsf.DocumentSummaryInformation)17 Test (org.junit.Test)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)7 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)7 PropertySet (org.apache.poi.hpsf.PropertySet)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 CustomProperties (org.apache.poi.hpsf.CustomProperties)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 FileNotFoundException (java.io.FileNotFoundException)2 OutputStream (java.io.OutputStream)2 Date (java.util.Date)2 HPSFPropertiesOnlyDocument (org.apache.poi.hpsf.HPSFPropertiesOnlyDocument)2 DirectoryEntry (org.apache.poi.poifs.filesystem.DirectoryEntry)2 DocumentInputStream (org.apache.poi.poifs.filesystem.DocumentInputStream)2 Color (java.awt.Color)1 Font (java.awt.Font)1