Example usage for org.apache.poi.openxml4j.opc PackageProperties getCreatorProperty

List of usage examples for org.apache.poi.openxml4j.opc PackageProperties getCreatorProperty

Introduction

In this page you can find the example usage for org.apache.poi.openxml4j.opc PackageProperties getCreatorProperty.

Prototype

Optional<String> getCreatorProperty();

Source Link

Document

Get the entity primarily responsible for making the content of the resource.

Usage

From source file:net.sourceforge.docfetcher.model.parse.MSOffice2007Parser.java

License:Open Source License

private static ParseResult doParse(File file, PackageAccess access) throws ParseException {
    OPCPackage pkg = null;//w  w  w  . j  ava2 s.c o  m
    try {
        pkg = OPCPackage.open(file.getPath(), access);
        String contents = extractText(pkg);

        // Open properties
        PackageProperties props = pkg.getPackageProperties();

        // Get author(s)
        String author = null;
        String defaultAuthor = props.getCreatorProperty().getValue();
        String lastAuthor = props.getLastModifiedByProperty().getValue();
        if (defaultAuthor == null) {
            if (lastAuthor != null)
                author = lastAuthor;
        } else if (lastAuthor == null) {
            author = defaultAuthor;
        } else {
            if (defaultAuthor.equals(lastAuthor))
                author = defaultAuthor;
            else
                author = defaultAuthor + ", " + lastAuthor; //$NON-NLS-1$
        }

        // Get other metadata
        String description = props.getDescriptionProperty().getValue();
        String keywords = props.getKeywordsProperty().getValue();
        String subject = props.getSubjectProperty().getValue();
        String title = props.getTitleProperty().getValue();

        return new ParseResult(contents).setTitle(title).addAuthor(author).addMiscMetadata(description)
                .addMiscMetadata(keywords).addMiscMetadata(subject);
    } catch (Exception e) {
        throw new ParseException(e);
    } finally {
        Closeables.closeQuietly(pkg);
    }
}

From source file:net.sourceforge.docfetcher.parse.MSOffice2007Parser.java

License:Open Source License

public Document parse(File file) throws ParseException {
    try {//from ww w  .  j a  va2s  .co m
        // Extract contents
        POITextExtractor ef = ExtractorFactory.createExtractor(file);
        StringBuffer contents = new StringBuffer(ef.getText());

        // Open up properties
        OPCPackage pkg = OPCPackage.open(file.getAbsolutePath(), PackageAccess.READ);
        PackageProperties props = pkg.getPackageProperties();

        // Get author(s)
        String author = null;
        String defaultAuthor = props.getCreatorProperty().getValue();
        String lastAuthor = props.getLastModifiedByProperty().getValue();
        if (defaultAuthor == null) {
            if (lastAuthor != null)
                author = lastAuthor;
        } else if (lastAuthor == null) {
            author = defaultAuthor;
        } else {
            if (defaultAuthor.equals(lastAuthor))
                author = defaultAuthor;
            else
                author = defaultAuthor + ", " + lastAuthor; //$NON-NLS-1$
        }

        // Get other metadata
        String description = props.getDescriptionProperty().getValue();
        String keywords = props.getKeywordsProperty().getValue();
        String subject = props.getSubjectProperty().getValue();
        String title = props.getTitleProperty().getValue();

        // Append metadata to contents
        String[] metaData = new String[] { author, description, keywords, subject, title };
        for (String field : metaData)
            if (field != null)
                contents.append(" ").append(field); //$NON-NLS-1$
        return new Document(file, title, contents).addAuthor(author);
    } catch (Exception e) {
        throw new ParseException(file, Msg.file_not_readable.value());
    }
}

From source file:net.sourceforge.vaticanfetcher.model.parse.MSOffice2007Parser.java

License:Open Source License

@Override
protected ParseResult parse(File file, ParseContext context) throws ParseException {
    OPCPackage pkg = null;//from w w  w  .  ja  v  a  2  s  . co m
    try {
        pkg = OPCPackage.open(file.getPath(), PackageAccess.READ);
        String contents = extractText(pkg);

        // Open properties
        PackageProperties props = pkg.getPackageProperties();

        // Get author(s)
        String author = null;
        String defaultAuthor = props.getCreatorProperty().getValue();
        String lastAuthor = props.getLastModifiedByProperty().getValue();
        if (defaultAuthor == null) {
            if (lastAuthor != null)
                author = lastAuthor;
        } else if (lastAuthor == null) {
            author = defaultAuthor;
        } else {
            if (defaultAuthor.equals(lastAuthor))
                author = defaultAuthor;
            else
                author = defaultAuthor + ", " + lastAuthor; //$NON-NLS-1$
        }

        // Get other metadata
        String description = props.getDescriptionProperty().getValue();
        String keywords = props.getKeywordsProperty().getValue();
        String subject = props.getSubjectProperty().getValue();
        String title = props.getTitleProperty().getValue();

        return new ParseResult(contents).setTitle(title).addAuthor(author).addMiscMetadata(description)
                .addMiscMetadata(keywords).addMiscMetadata(subject);
    } catch (Exception e) {
        throw new ParseException(e);
    } finally {
        Closeables.closeQuietly(pkg);
    }
}