Examples of SummaryInformation


Examples of org.apache.poi.hpsf.SummaryInformation

    public void processDocument( HWPFDocumentCore wordDocument )
    {
        try
        {
            final SummaryInformation summaryInformation = wordDocument
                    .getSummaryInformation();
            if ( summaryInformation != null )
            {
                processDocumentInformation( summaryInformation );
            }
View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

         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();
        
        
View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

    * 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 = null;
       DocumentSummaryInformation dinf = null;
       DirectoryEntry root = null, testDir = null;
      
       for(NPOIFSFileSystem fs : get512and4kFileAndInput()) {
           // Check we can find the entries we expect
           root = fs.getRoot();
           assertEquals(5, root.getEntryCount());
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
           assertThat(root.getEntryNames(), hasItem("Image"));
           assertThat(root.getEntryNames(), hasItem("Tags"));
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));

          
           // Write out, re-load
           fs = writeOutAndReadBack(fs);
          
           // Check they're still there
           root = fs.getRoot();
           assertEquals(5, root.getEntryCount());
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
           assertThat(root.getEntryNames(), hasItem("Image"));
           assertThat(root.getEntryNames(), hasItem("Tags"));
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
          
          
           // 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
           fs = writeOutAndReadBack(fs);
          
           root = fs.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("\u0005DocumentSummaryInformation"));
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));

          
           // 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
           fs = writeOutAndReadBack(fs);
          
           root = fs.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("\u0005DocumentSummaryInformation"));
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));

           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
           fs = writeOutAndReadBack(fs);

           // Check it's all there
           root = fs.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("\u0005DocumentSummaryInformation"));
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));

          
           // 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());

View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

        flow.appendChild( titleBlock2 );
    }

    public void processWorkbook( HSSFWorkbook workbook )
    {
        final SummaryInformation summaryInformation = workbook
                .getSummaryInformation();
        if ( summaryInformation != null )
        {
            processDocumentInformation( summaryInformation );
        }
View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

     *
     * @throws IOException if an error when writing to the
     *      {@link POIFSFileSystem} occurs
     */
    protected void writeProperties(POIFSFileSystem 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);
            }
View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

        /* 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\u00fcssel 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 */
 
View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

        htmlBody.appendChild( h2 );
    }

    public void processWorkbook( HSSFWorkbook workbook )
    {
        final SummaryInformation summaryInformation = workbook
                .getSummaryInformation();
        if ( summaryInformation != null )
        {
            processDocumentInformation( summaryInformation );
        }
View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

       DocumentInputStream dis;
       POIFSFileSystem fs =
               new POIFSFileSystem(_samples.openResourceAsStream("TestNon4ByteBoundary.doc"));
      
       dis = fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME);
       SummaryInformation si = (SummaryInformation)PropertySetFactory.create(dis);
      
       dis = fs.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
       DocumentSummaryInformation dsi = (DocumentSummaryInformation)PropertySetFactory.create(dis);
     
       // 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 POIFSFileSystem(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());
   }
View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

       DocumentInputStream dis;
       POIFSFileSystem fs =
               new POIFSFileSystem(_samples.openResourceAsStream("TestZeroLengthCodePage.mpp"));
      
       dis = fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME);
       SummaryInformation si = (SummaryInformation)PropertySetFactory.create(dis);
      
       dis = fs.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
       DocumentSummaryInformation dsi = (DocumentSummaryInformation)PropertySetFactory.create(dis);
      
       // Test
       assertEquals("MSProject", si.getApplicationName());
       assertEquals("project1", si.getTitle());
       assertEquals("Jon Iles", si.getAuthor());
      
       assertEquals("", dsi.getCompany());
       assertEquals(2, dsi.getSectionCount());
   }
View Full Code Here

Examples of org.apache.poi.hpsf.SummaryInformation

            DocumentEntry entry =
                (DocumentEntry) filesystem.getRoot().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) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.