Package org.apache.poi.hpsf

Examples of org.apache.poi.hpsf.SummaryInformation


        POIFSFileSystem poifs = new POIFSFileSystem(is);
        is.close();

        /* Read the summary information. */
        DirectoryEntry dir = poifs.getRoot();
        SummaryInformation si;
        try
        {
            DocumentEntry siEntry = (DocumentEntry)
                dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
            DocumentInputStream dis = new DocumentInputStream(siEntry);
            PropertySet ps = new PropertySet(dis);
            dis.close();
            si = new SummaryInformation(ps);
        }
        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
        {
            DocumentEntry dsiEntry = (DocumentEntry)
                dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
            DocumentInputStream dis = new DocumentInputStream(dsiEntry);
            PropertySet ps = new PropertySet(dis);
            dis.close();
            dsi = new DocumentSummaryInformation(ps);
        }
        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", new Boolean(true));
        customProperties.put("Sample Date", new Date());

        /* Read a custom property. */
        Object value = customProperties.get("Sample Number");

        /* 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 never write directly to the origin
         * file! In case of a writing error everything would be lost. */
 
View Full Code Here


            throws IOException, TikaException {
        try {
            PropertySet properties =
                new PropertySet(new DocumentInputStream(entry));
            if (properties.isSummaryInformation()) {
                parse(new SummaryInformation(properties), metadata);
            }
            if (properties.isDocumentSummaryInformation()) {
                parse(new DocumentSummaryInformation(properties), metadata);
            }
        } catch (NoPropertySetStreamException e) {
View Full Code Here

     * @exception IOException if an I/O exception occurs
     * @exception HPSFException if any HPSF exception occurs
     */
    public void testSectionMethods() throws IOException, HPSFException
    {
        final SummaryInformation si = (SummaryInformation)
            PropertySetFactory.create(new ByteArrayInputStream
                (poiFiles[0].getBytes()));
        final List sections = si.getSections();
        final Section s = (Section) sections.get(0);
        Assert.assertTrue(org.apache.poi.hpsf.Util.equal
            (s.getFormatID().getBytes(), SectionIDMap.SUMMARY_INFORMATION_ID));
        Assert.assertNotNull(s.getProperties());
        Assert.assertEquals(17, s.getPropertyCount());
View Full Code Here

            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

            throws IOException, TikaException {
        try {
            PropertySet properties =
                new PropertySet(new DocumentInputStream(entry));
            if (properties.isSummaryInformation()) {
                parse(new SummaryInformation(properties), metadata);
            }
            if (properties.isDocumentSummaryInformation()) {
                parse(new DocumentSummaryInformation(properties), metadata);
            }
        } catch (NoPropertySetStreamException e) {
View Full Code Here

   * Writes out the standard Documment Information Properties (HPSF)
   * @param outFS the POIFSFileSystem to write the properties into
   * @param writtenEntries a list of POIFS entries to add the property names too
   */
  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

   * Writes out the standard Documment Information Properties (HPSF)
   * @param outFS the POIFSFileSystem to write the properties into
   * @param writtenEntries a list of POIFS entries to add the property names too
   */
  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

      if (!event.getName().startsWith(SummaryInformation.DEFAULT_STREAM_NAME)) {
        return;
      }
     
      try {
        SummaryInformation si = (SummaryInformation)
                                  PropertySetFactory.create(event.getStream());
        setProperty(DublinCore.TITLE, si.getTitle());
        setProperty(Office.APPLICATION_NAME, si.getApplicationName());
        setProperty(Office.AUTHOR, si.getAuthor());
        setProperty(Office.CHARACTER_COUNT, si.getCharCount());
        setProperty(Office.COMMENTS, si.getComments());
        setProperty(DublinCore.DATE, si.getCreateDateTime());
//        setProperty(Office.EDIT_TIME, si.getEditTime());
        setProperty(HttpHeaders.LAST_MODIFIED, si.getLastSaveDateTime());
        setProperty(Office.KEYWORDS, si.getKeywords());
        setProperty(Office.LAST_AUTHOR, si.getLastAuthor());
        setProperty(Office.LAST_PRINTED, si.getLastPrinted());
        setProperty(Office.LAST_SAVED, si.getLastSaveDateTime());
        setProperty(Office.PAGE_COUNT, si.getPageCount());
        setProperty(Office.REVISION_NUMBER, si.getRevNumber());
        setProperty(DublinCore.RIGHTS, si.getSecurity());
        setProperty(DublinCore.SUBJECT, si.getSubject());
        setProperty(Office.TEMPLATE, si.getTemplate());
        setProperty(Office.WORD_COUNT, si.getWordCount());
      } catch (Exception ex) {
      }
      propertiesBroker.setProperties(metadata);
    }
View Full Code Here

         assertEquals(doc.getSize(), inp.read(contents));
        
         // Now try to build the property set
         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());
      }
   }
View Full Code Here

    public void testPropertySetMethods() throws IOException, HPSFException
    {
        byte[] b = poiFiles[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());
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hpsf.SummaryInformation

Copyright © 2018 www.massapicom. 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.