Package org.apache.poi.hpsf

Examples of org.apache.poi.hpsf.SummaryInformation


   
    // All done
    return text.toString();
  }
  public String getSummaryInformationText() {
    SummaryInformation si = document.getSummaryInformation();
   
    // Just normal properties
    return getPropertiesText(si);
  }
View Full Code Here


    static class MyPOIFSReaderListener implements POIFSReaderListener
    {
        public void processPOIFSReaderEvent(final POIFSReaderEvent event)
        {
            SummaryInformation si = null;
            try
            {
                si = (SummaryInformation)
                    PropertySetFactory.create(event.getStream());
            }
            catch (Exception ex)
            {
                throw new RuntimeException
                    ("Property set stream \"" +
                     event.getPath() + event.getName() + "\": " + ex);
            }
            final String title = si.getTitle();
            if (title != null)
                System.out.println("Title: \"" + title + "\"");
            else
                System.out.println("Document has no title.");
        }
View Full Code Here

        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\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");

        /* 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

        p.add(text);

        if (ps instanceof SummaryInformation)
        {
            /* Use the convenience methods. */
            final SummaryInformation si = (SummaryInformation) ps;
            text.append("\n");
            text.append("\nTitle:               " + si.getTitle());
            text.append("\nSubject:             " + si.getSubject());
            text.append("\nAuthor:              " + si.getAuthor());
            text.append("\nKeywords:            " + si.getKeywords());
            text.append("\nComments:            " + si.getComments());
            text.append("\nTemplate:            " + si.getTemplate());
            text.append("\nLast Author:         " + si.getLastAuthor());
            text.append("\nRev. Number:         " + si.getRevNumber());
            text.append("\nEdit Time:           " + si.getEditTime());
            text.append("\nLast Printed:        " + si.getLastPrinted());
            text.append("\nCreate Date/Time:    " + si.getCreateDateTime());
            text.append("\nLast Save Date/Time: " + si.getLastSaveDateTime());
            text.append("\nPage Count:          " + si.getPageCount());
            text.append("\nWord Count:          " + si.getWordCount());
            text.append("\nChar Count:          " + si.getCharCount());
            // text.append("\nThumbnail:           " + si.getThumbnail());
            text.append("\nApplication Name:    " + si.getApplicationName());
            text.append("\nSecurity:            " + si.getSecurity());
        }

        if (selected)
            Util.invert(text);
        return p;
View Full Code Here

    // All done
    return text.toString();
  }
  public String getSummaryInformationText() {
    SummaryInformation si = document.getSummaryInformation();

    // Just normal properties
    return getPropertiesText(si);
  }
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 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

      DocumentEntry dsiEntry = (DocumentEntry) dir
          .getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
      DocumentInputStream dis = new DocumentInputStream(dsiEntry);
      PropertySet ps = new PropertySet(dis);
      dis.close();
      si = new SummaryInformation(ps);

    } catch (FileNotFoundException ex) {
      /*
       * There is no document summary information yet. We have to create a
       * new one.
View Full Code Here

      DocumentEntry dsiEntry = (DocumentEntry) dir
          .getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
      DocumentInputStream dis = new DocumentInputStream(dsiEntry);
      PropertySet ps = new PropertySet(dis);
      dis.close();
      si = new SummaryInformation(ps);

    } catch (FileNotFoundException ex) {
      /*
       * There is no document summary information yet. We have to create a
       * new one.
View Full Code Here

        HSSFWorkbook wb = new HSSFWorkbook(fs);

        //set POIFS properties after constructing HSSFWorkbook
        //(a piece of code that used to work up to POI 3.0.2)
        SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
        summary1.setTitle(title);
        //write the modified property back to POIFS
        fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
        fs.createDocument(summary1.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);

        //save the workbook and read the property
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wb.write(out);
        out.close();

        POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
        SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));

        //failing assertion
        assertEquals(title, summary2.getTitle());
    }
View Full Code Here

    public void testOK() throws Exception {
        InputStream is = HSSFTestDataSamples.openSampleFileStream("Simple.xls");
        POIFSFileSystem fs = new POIFSFileSystem(is);

        //set POIFS properties before constructing HSSFWorkbook
        SummaryInformation summary1 = (SummaryInformation)PropertySetFactory.create(fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
        summary1.setTitle(title);

        fs.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
        fs.createDocument(summary1.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);

        HSSFWorkbook wb = new HSSFWorkbook(fs);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wb.write(out);
        out.close();

        //read the property
        POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
        SummaryInformation summary2 = (SummaryInformation)PropertySetFactory.create(fs2.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
        assertEquals(title, summary2.getTitle());

    }
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.