Example usage for org.apache.poi.hpsf DocumentSummaryInformation DocumentSummaryInformation

List of usage examples for org.apache.poi.hpsf DocumentSummaryInformation DocumentSummaryInformation

Introduction

In this page you can find the example usage for org.apache.poi.hpsf DocumentSummaryInformation DocumentSummaryInformation.

Prototype

public DocumentSummaryInformation(final InputStream stream) throws NoPropertySetStreamException,
        MarkUnsupportedException, IOException, UnsupportedEncodingException 

Source Link

Document

Creates a DocumentSummaryInformation instance from an InputStream in the Horrible Property Set Format.

The constructor reads the first few bytes from the stream and determines whether it is really a property set stream.

Usage

From source file:edu.ku.brc.specify.tasks.subpane.wb.ConfigureXLS.java

License:Open Source License

/**
 * @param poifs/*from w  w  w . j  av a2s . co m*/
 * @returns the DocumentSummaryInformation for poifs, or null if no DocumentSummaryInformation is found.
 */
protected DocumentSummaryInformation getDocSummary(final POIFSFileSystem poifs) {
    DirectoryEntry dir = poifs.getRoot();
    DocumentSummaryInformation result = null;
    try {
        DocumentEntry dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream dis = new DocumentInputStream(dsiEntry);
        PropertySet ps = new PropertySet(dis);
        dis.close();
        result = new DocumentSummaryInformation(ps);
    } catch (FileNotFoundException ex) {
        // There is no document summary information. 
        result = null;
    }
    /*
     * just returning null if anything weird happens. If there is a problem with the xls file,
     * something else will probably blow up later. 
    */
    catch (IOException ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex);
        log.debug(ex);
        result = null;
    } catch (NoPropertySetStreamException ex) {
        //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex);
        log.debug(ex);
        result = null;
    } catch (MarkUnsupportedException ex) {
        //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex);
        log.debug(ex);
        result = null;
    } catch (UnexpectedPropertySetTypeException ex) {
        //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex);
        log.debug(ex);
        result = null;
    } catch (IllegalPropertySetDataException ex) {
        //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ConfigureXLS.class, ex);
        log.debug(ex);
        result = null;
    }
    return result;
}

From source file:mj.ocraptor.extraction.tika.parser.microsoft.SummaryExtractor.java

License:Apache License

private void parseSummaryEntryIfExists(DirectoryNode root, String entryName) throws IOException, TikaException {
    try {//from w  w  w . j  ava 2s .  c  o  m
        DocumentEntry entry = (DocumentEntry) root.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) {
        // entry does not exist, just skip it
    } catch (NoPropertySetStreamException e) {
        // no property stream, just skip it
    } catch (UnexpectedPropertySetTypeException e) {
        throw new TikaException("Unexpected HPSF document", e);
    } catch (MarkUnsupportedException e) {
        throw new TikaException("Invalid DocumentInputStream", e);
    } catch (Exception e) {
        LOGGER.warn("Ignoring unexpected exception while parsing summary entry " + entryName, e);
    }
}

From source file:org.apache.tika.parser.microsoft.SummaryExtractor.java

License:Apache License

private void parseSummaryEntryIfExists(DirectoryNode root, String entryName) throws IOException, TikaException {
    try {//from  w  ww  .j  a  v a 2s. c om
        DocumentEntry entry = (DocumentEntry) root.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) {
        // entry does not exist, just skip it
    } catch (NoPropertySetStreamException e) {
        // no property stream, just skip it
    } catch (UnexpectedPropertySetTypeException e) {
        throw new TikaException("Unexpected HPSF document", e);
    } catch (MarkUnsupportedException e) {
        throw new TikaException("Invalid DocumentInputStream", e);
    } catch (Exception e) {
        logger.warn("Ignoring unexpected exception while parsing summary entry " + entryName, e);
    }
}

From source file:org.redpill.alfresco.module.metadatawriter.services.msoffice.impl.POIFSFacadeImpl.java

License:Open Source License

private DocumentSummaryInformation getDocumentSummaryInformation() throws ContentFacade.ContentException {
    if (null == dsi) {
        try {/*from  w  ww .j a  va 2  s.co  m*/
            final PropertySet ps = createPropertySet(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
            dsi = new DocumentSummaryInformation(ps);
        } catch (FileNotFoundException fnf) {
            logger.debug("Document summary information does not exist in file, createing new!");
            dsi = PropertySetFactory.newDocumentSummaryInformation();
        } catch (UnexpectedPropertySetTypeException e) {
            throw new ContentException("Document summary information property set has invalid type", e);
        }
    }

    return dsi;

}

From source file:poi.hpsf.examples.ModifyDocumentSummaryInformation.java

License:Apache License

/**
 * <p>Main method - see class description.</p>
 *
 * @param args The command-line parameters.
 * @throws java.io.IOException/*from w  ww  .jav  a 2 s  .c  o  m*/
 * @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 poiFilesystem = new File(args[0]);

    /* Open the POI filesystem. */
    InputStream is = new FileInputStream(poiFilesystem);
    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. */
    OutputStream out = new FileOutputStream(poiFilesystem);
    poifs.writeFilesystem(out);
    out.close();
}