List of usage examples for org.apache.poi.openxml4j.opc PackageProperties getSubjectProperty
Optional<String> getSubjectProperty();
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;//from w ww . j av a2 s . c om 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 {/* ww w . java 2 s .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;// w w w . j a v a 2 s.c o 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); } }