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

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

Introduction

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

Prototype

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

Source Link

Document

Creates a SummaryInformation 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:com.oneis.graphics.ThumbnailFinder.java

License:Mozilla Public License

/**
 * Try and get a thumbnail from an old Microsoft Office document
 *///from   w w w  .  jav  a  2 s  .  com
private void findFromOldMSOffice() {
    try {
        File poiFilesystem = new File(inFilename);

        // Open the POI filesystem.
        InputStream is = new FileInputStream(poiFilesystem);
        POIFSFileSystem poifs = new POIFSFileSystem(is);
        is.close();

        // Read the summary information.
        DirectoryEntry dir = poifs.getRoot();
        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream dis = new DocumentInputStream(siEntry);
        PropertySet ps = new PropertySet(dis);
        dis.close();
        SummaryInformation si = new SummaryInformation(ps);
        if (si != null) {
            byte[] thumbnailData = si.getThumbnail();
            if (thumbnailData != null) {
                Thumbnail thumbnail = new Thumbnail(thumbnailData);
                byte[] wmf = thumbnail.getThumbnailAsWMF();
                // Got something!
                thumbnailDimensions = tryWMFFormat(new ByteArrayInputStream(wmf), outFilename, outFormat,
                        maxDimension);
            }
        }
    } catch (Exception e) {
        logIgnoredException("ThumbnailFinder Apache POI file reading failed", e);
    }
}

From source file:com.pnf.plugin.ole.parser.StreamReader.java

License:Apache License

private List<INode> readSummaryInfoStream(ByteBuffer stream) {
    List<INode> roots = new LinkedList<>();
    String propType = "Property";

    try {// ww w.  j  a v  a  2s. c  o m
        SummaryInformation sInfo = new SummaryInformation(new PropertySet(stream.array()));

        StreamEntry cInfo = new StreamEntry("Creation Information");
        cInfo.addChild(new StreamEntry("Application Name", propType, sInfo.getApplicationName()));
        cInfo.addChild(new StreamEntry("Creation", "Time",
                sInfo.getCreateDateTime() != null ? sInfo.getCreateDateTime().toString() : null));
        cInfo.addChild(new StreamEntry("Author", propType, sInfo.getAuthor()));
        cInfo.addChild(new StreamEntry("Last Author", propType, sInfo.getLastAuthor()));
        cInfo.addChild(new StreamEntry("Template", propType, sInfo.getTemplate()));
        roots.add(cInfo);

        propType = "Time";
        StreamEntry timeInfo = new StreamEntry("Times");
        timeInfo.addChild(new StreamEntry("Total Edit Time", propType, String.valueOf(sInfo.getEditTime())));
        timeInfo.addChild(new StreamEntry("Last Saved", propType,
                sInfo.getLastSaveDateTime() != null ? sInfo.getLastSaveDateTime().toString() : null));
        timeInfo.addChild(new StreamEntry("Last Printed", propType,
                sInfo.getLastPrinted() != null ? sInfo.getLastPrinted().toString() : null));
        roots.add(timeInfo);

        propType = "Misc";
        StreamEntry misc = new StreamEntry("Miscellaneous");
        misc.addChild(new StreamEntry("OS Version", "int", String.valueOf(sInfo.getOSVersion())));
        misc.addChild(new StreamEntry("Revision Number", "int", sInfo.getRevNumber()));
        misc.addChild(new StreamEntry("Page Count", "int", String.valueOf(sInfo.getPageCount())));
        misc.addChild(new StreamEntry("Word Count", "int", String.valueOf(sInfo.getWordCount())));

        int secVal = sInfo.getSecurity();
        String security = null;

        if (!sInfo.wasNull()) { // Set description according to POI documentation
            switch (secVal) {
            case 0:
                security = "No security";
                break;
            case 1:
                security = "Password protected";
                break;
            case 2:
                security = "Read-only recommended";
                break;
            case 4:
                security = "Read-only enforced";
                break;
            case 8:
                security = "Locked for annotations";
                break;
            default:
                break;
            }

            security += " (code " + secVal + ")";
        } else {
            security = "Field not set";
        }

        misc.addChild(new StreamEntry("Document Security", "int", security));
        misc.addChild(new StreamEntry("Subject", propType, sInfo.getSubject()));
        misc.addChild(new StreamEntry("Keywords", propType, sInfo.getKeywords()));
        roots.add(misc);
    } catch (Throwable t) {
        addMessage("Attempted to read " + SUMM_INFO + " stream but no property sets were found.", null,
                Message.CORRUPT);
    }

    return roots;
}

From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java

License:Open Source License

public static String getSummaryData(String filename, String key) {
    String value = null;/*from ww  w  .  j a  va2s  .  co m*/
    FileInputStream stream = null;
    try {
        stream = new FileInputStream(new File(filename));
        POIFSFileSystem poifs = null;
        try {
            poifs = new POIFSFileSystem(stream);
        } catch (Exception e) {
            stream.close();
            return getPOISummaryData(filename, key);
        }
        DirectoryEntry dir = poifs.getRoot();
        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        if (siEntry != null) {
            DocumentInputStream dis = new DocumentInputStream(siEntry);
            PropertySet ps = new PropertySet(dis);
            SummaryInformation si = new SummaryInformation(ps);

            if (key.compareTo(SUMMARY_DATA_AUTHOR) == 0) {
                value = si.getAuthor();
            } else if (key.compareTo(SUMMARY_DATA_KEYWORDS) == 0) {
                value = si.getKeywords();
            } else if (key.compareTo(SUMMARY_DATA_TITLE) == 0) {
                value = si.getTitle();
            } else if (key.compareTo(SUMMARY_DATA_SUBJECT) == 0) {
                value = si.getSubject();
            }
        }
    } catch (Exception ex) {
        ex.getStackTrace();
    } finally {
        try {
            stream.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return value;
}

From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java

License:Open Source License

public static String getAuthor(File file) {
    String author = null;//  w ww .  jav a 2 s . co  m
    try {
        FileInputStream stream = new FileInputStream(file);
        POIFSFileSystem poifs = null;
        try {
            poifs = new POIFSFileSystem(stream);
        } catch (Exception e) {
            stream.close();
            return getCreator(file);
        }
        DirectoryEntry dir = null;
        try {
            dir = poifs.getRoot();
        } catch (Exception ex) {
            System.out.println("DirectoryEntry is NULL???");
            return null;
        }
        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        if (siEntry != null) {
            DocumentInputStream dis = new DocumentInputStream(siEntry);
            PropertySet ps = new PropertySet(dis);
            SummaryInformation si = new SummaryInformation(ps);
            author = si.getAuthor();
        }
        stream.close();
    } catch (Exception ex) {
        ex.getStackTrace();
    }
    return author;
}

From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java

License:Open Source License

public static void setAuthor(String filename, String author) {
    try {//from   www.ja va  2 s .  com
        FileInputStream stream = new FileInputStream(new File(filename));
        POIFSFileSystem poifs = new POIFSFileSystem(stream);
        DirectoryEntry dir = poifs.getRoot();

        System.out.println("SummaryInformation.DEFAULT_STREAM_NAME: " + SummaryInformation.DEFAULT_STREAM_NAME);

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

        System.out.println("SummaryInformation setAuthor: " + author);

        si.setAuthor(author);

        OutputStream outStream = null;
        outStream = new FileOutputStream(new File(filename));
        byte[] buffer = new byte[1024];
        int length;

        while ((length = stream.read(buffer)) > 0) {
            outStream.write(buffer, 0, length);
        }
        outStream.close();
        stream.close();

    } catch (Exception ex) {
        ex.getStackTrace();
    }
}

From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java

License:Open Source License

public static void setAuthor(File file, String author) {
    try {/*from  www .ja  va 2s  .  c om*/
        FileInputStream stream = new FileInputStream(file);
        POIFSFileSystem poifs = null;
        try {
            poifs = new POIFSFileSystem(stream);
        } catch (Exception e) {
            stream.close();
            setCreator(file, author);
            return;
        }
        DirectoryEntry dir = poifs.getRoot();
        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        if (siEntry != null) {
            DocumentInputStream dis = new DocumentInputStream(siEntry);
            PropertySet ps = new PropertySet(dis);
            SummaryInformation si = new SummaryInformation(ps);
            si.setAuthor(author);
        }
        stream.close();
    } catch (Exception ex) {
        ex.getStackTrace();
    }
}

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 {/*w w w. j ava 2  s .com*/
        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:net.sf.mpxj.mpp.ProjectPropertiesReader.java

License:Open Source License

/**
 * The main entry point for processing project properties.
 * /*from   ww w .ja v  a2s.  c  o  m*/
 * @param file parent project file
 * @param props properties data
 * @param rootDir Root of the POI file system.
 */
public void process(ProjectFile file, Props props, DirectoryEntry rootDir) throws MPXJException {
    try {
        //MPPUtility.fileDump("c:\\temp\\props.txt", props.toString().getBytes());
        ProjectProperties ph = file.getProjectProperties();
        ph.setStartDate(props.getTimestamp(Props.PROJECT_START_DATE));
        ph.setFinishDate(props.getTimestamp(Props.PROJECT_FINISH_DATE));
        ph.setScheduleFrom(ScheduleFrom.getInstance(1 - props.getShort(Props.SCHEDULE_FROM)));
        ph.setDefaultCalendarName(props.getUnicodeString(Props.DEFAULT_CALENDAR_NAME));
        ph.setDefaultStartTime(props.getTime(Props.START_TIME));
        ph.setDefaultEndTime(props.getTime(Props.END_TIME));
        ph.setStatusDate(props.getTimestamp(Props.STATUS_DATE));
        ph.setHyperlinkBase(props.getUnicodeString(Props.HYPERLINK_BASE));

        //ph.setDefaultDurationIsFixed();
        ph.setDefaultDurationUnits(MPPUtility.getDurationTimeUnits(props.getShort(Props.DURATION_UNITS)));
        ph.setMinutesPerDay(Integer.valueOf(props.getInt(Props.MINUTES_PER_DAY)));
        ph.setMinutesPerWeek(Integer.valueOf(props.getInt(Props.MINUTES_PER_WEEK)));
        ph.setDefaultOvertimeRate(new Rate(props.getDouble(Props.OVERTIME_RATE), TimeUnit.HOURS));
        ph.setDefaultStandardRate(new Rate(props.getDouble(Props.STANDARD_RATE), TimeUnit.HOURS));
        ph.setDefaultWorkUnits(MPPUtility.getWorkTimeUnits(props.getShort(Props.WORK_UNITS)));
        ph.setSplitInProgressTasks(props.getBoolean(Props.SPLIT_TASKS));
        ph.setUpdatingTaskStatusUpdatesResourceStatus(props.getBoolean(Props.TASK_UPDATES_RESOURCE));

        ph.setCurrencyDigits(Integer.valueOf(props.getShort(Props.CURRENCY_DIGITS)));
        ph.setCurrencySymbol(props.getUnicodeString(Props.CURRENCY_SYMBOL));
        ph.setCurrencyCode(props.getUnicodeString(Props.CURRENCY_CODE));
        //ph.setDecimalSeparator();
        ph.setSymbolPosition(MPPUtility.getSymbolPosition(props.getShort(Props.CURRENCY_PLACEMENT)));
        //ph.setThousandsSeparator();
        ph.setWeekStartDay(Day.getInstance(props.getShort(Props.WEEK_START_DAY) + 1));
        ph.setFiscalYearStartMonth(Integer.valueOf(props.getShort(Props.FISCAL_YEAR_START_MONTH)));
        ph.setFiscalYearStart(props.getShort(Props.FISCAL_YEAR_START) == 1);
        ph.setDaysPerMonth(Integer.valueOf(props.getShort(Props.DAYS_PER_MONTH)));
        ph.setEditableActualCosts(props.getBoolean(Props.EDITABLE_ACTUAL_COSTS));
        ph.setHonorConstraints(!props.getBoolean(Props.HONOR_CONSTRAINTS));

        PropertySet ps = new PropertySet(new DocumentInputStream(
                ((DocumentEntry) rootDir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME))));
        SummaryInformation summaryInformation = new SummaryInformation(ps);
        ph.setProjectTitle(summaryInformation.getTitle());
        ph.setSubject(summaryInformation.getSubject());
        ph.setAuthor(summaryInformation.getAuthor());
        ph.setKeywords(summaryInformation.getKeywords());
        ph.setComments(summaryInformation.getComments());
        ph.setTemplate(summaryInformation.getTemplate());
        ph.setLastAuthor(summaryInformation.getLastAuthor());
        ph.setRevision(NumberHelper.parseInteger(summaryInformation.getRevNumber()));
        ph.setCreationDate(summaryInformation.getCreateDateTime());
        ph.setLastSaved(summaryInformation.getLastSaveDateTime());
        ph.setShortApplicationName(summaryInformation.getApplicationName());
        ph.setEditingTime(Integer.valueOf((int) summaryInformation.getEditTime()));
        ph.setLastPrinted(summaryInformation.getLastPrinted());

        ps = new PropertySet(new DocumentInputStream(
                ((DocumentEntry) rootDir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME))));
        ExtendedDocumentSummaryInformation documentSummaryInformation = new ExtendedDocumentSummaryInformation(
                ps);
        ph.setCategory(documentSummaryInformation.getCategory());
        ph.setPresentationFormat(documentSummaryInformation.getPresentationFormat());
        ph.setManager(documentSummaryInformation.getManager());
        ph.setCompany(documentSummaryInformation.getCompany());
        ph.setContentType(documentSummaryInformation.getContentType());
        ph.setContentStatus(documentSummaryInformation.getContentStatus());
        ph.setLanguage(documentSummaryInformation.getLanguage());
        ph.setDocumentVersion(documentSummaryInformation.getDocumentVersion());

        Map<String, Object> customPropertiesMap = new HashMap<String, Object>();
        CustomProperties customProperties = documentSummaryInformation.getCustomProperties();
        if (customProperties != null) {
            for (CustomProperty property : customProperties.values()) {
                customPropertiesMap.put(property.getName(), property.getValue());
            }
        }
        ph.setCustomProperties(customPropertiesMap);

        ph.setCalculateMultipleCriticalPaths(props.getBoolean(Props.CALCULATE_MULTIPLE_CRITICAL_PATHS));

        ph.setBaselineDate(props.getTimestamp(Props.BASELINE_DATE));
        ph.setBaselineDate(1, props.getTimestamp(Props.BASELINE1_DATE));
        ph.setBaselineDate(2, props.getTimestamp(Props.BASELINE2_DATE));
        ph.setBaselineDate(3, props.getTimestamp(Props.BASELINE3_DATE));
        ph.setBaselineDate(4, props.getTimestamp(Props.BASELINE4_DATE));
        ph.setBaselineDate(5, props.getTimestamp(Props.BASELINE5_DATE));
        ph.setBaselineDate(6, props.getTimestamp(Props.BASELINE6_DATE));
        ph.setBaselineDate(7, props.getTimestamp(Props.BASELINE7_DATE));
        ph.setBaselineDate(8, props.getTimestamp(Props.BASELINE8_DATE));
        ph.setBaselineDate(9, props.getTimestamp(Props.BASELINE9_DATE));
        ph.setBaselineDate(10, props.getTimestamp(Props.BASELINE10_DATE));
    }

    catch (Exception ex) {
        throw new MPXJException(MPXJException.READ_ERROR, ex);
    }
}

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

License:Apache License

private void parseSummaryEntryIfExists(DirectoryNode root, String entryName) throws IOException, TikaException {
    try {/*  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.knime.ext.textprocessing.nodes.source.parser.word.WordDocumentParser.java

License:Open Source License

private Document parseInternal(final InputStream is) throws Exception {
    m_currentDoc = new DocumentBuilder(m_tokenizerName);
    m_currentDoc.setDocumentFile(new File(m_docPath));
    m_currentDoc.setDocumentType(m_type);
    m_currentDoc.addDocumentCategory(m_category);
    m_currentDoc.addDocumentSource(m_source);

    POIFSFileSystem poifs = null;/*from  ww  w . j  a va2s.  com*/
    HWPFDocument hdoc = null;
    XWPFDocument hdoc2 = null;
    WordExtractor extractor = null;

    try {
        // doc files
        if (m_docPath.endsWith(".doc")) {
            // copy content of input stream into byte array since content have to be red twice unfortunately.
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            final byte[] buf = new byte[1024];
            int i = 0;
            while ((i = is.read(buf)) >= 0) {
                baos.write(buf, 0, i);
            }
            final byte[] content = baos.toByteArray();

            // open stream with copied content to read text
            InputStream copiedInput = new ByteArrayInputStream(content);
            hdoc = new HWPFDocument(copiedInput);
            extractor = new WordExtractor(hdoc);
            for (String p : extractor.getParagraphText()) {
                p = p.trim();
                if (!onlyWhitepscaes(p)) {
                    m_currentDoc.addParagraph(p);
                }
            }

            // open stream again with copied content to read meta info
            copiedInput = new ByteArrayInputStream(content);
            poifs = new POIFSFileSystem(copiedInput);
            final DirectoryEntry dir = poifs.getRoot();
            final DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
            final PropertySet ps = new PropertySet(new DocumentInputStream(siEntry));

            final SummaryInformation si = new SummaryInformation(ps);

            setAuthor(si.getAuthor());
            setPublicationDate(si.getCreateDateTime());

            // docx files
        } else if (m_docPath.endsWith(".docx") || m_docPath.endsWith(".docm")) {
            hdoc2 = new XWPFDocument(is);
            final List<XWPFParagraph> paragraphs = hdoc2.getParagraphs();
            for (final XWPFParagraph paragraph : paragraphs) {
                final String text = paragraph.getText();
                if (!onlyWhitepscaes(text)) {
                    m_currentDoc.addParagraph(text);
                }
            }

            setAuthor(hdoc2.getProperties().getCoreProperties().getCreator());
            setPublicationDate(hdoc2.getProperties().getCoreProperties().getCreated());
        }

        m_currentDoc.createNewSection(SectionAnnotation.CHAPTER);

        // find title
        String title = null;

        if (m_filenameAsTitle) {
            title = m_docPath.trim();
        } else {
            final List<Section> sections = m_currentDoc.getSections();
            if (sections.size() > 0) {
                try {
                    title = sections.get(0).getParagraphs().get(0).getSentences().get(0).getText().trim();
                } catch (IndexOutOfBoundsException e) {
                    LOGGER.debug("Parsed word document " + m_docPath + " is empty.");
                    title = "";
                }
            }
        }
        if (!checkTitle(title)) {
            title = m_docPath.toString();
        }
        m_currentDoc.addTitle(title);

        return m_currentDoc.createDocument();
    } finally {
        is.close();
        if (poifs != null) {
            poifs.close();
        }
        if (hdoc != null) {
            hdoc.close();
        }
        if (hdoc2 != null) {
            hdoc2.close();
        }
        if (extractor != null) {
            extractor.close();
        }
    }
}