2008-08-12 20:58:31 +00:00
|
|
|
/* ====================================================================
|
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
==================================================================== */
|
|
|
|
|
|
2009-08-22 05:50:32 +00:00
|
|
|
package org.apache.poi;
|
2008-08-12 20:58:31 +00:00
|
|
|
|
2009-01-29 12:44:31 +00:00
|
|
|
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
|
2008-08-12 20:58:31 +00:00
|
|
|
import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
|
|
|
|
|
|
2010-06-04 12:02:36 +00:00
|
|
|
import java.util.Date;
|
2010-06-22 13:59:44 +00:00
|
|
|
import java.util.List;
|
2010-06-04 12:02:36 +00:00
|
|
|
|
2008-08-12 20:58:31 +00:00
|
|
|
/**
|
|
|
|
|
* A {@link POITextExtractor} for returning the textual
|
|
|
|
|
* content of the OOXML file properties, eg author
|
2009-08-22 05:50:32 +00:00
|
|
|
* and title.
|
2008-08-12 20:58:31 +00:00
|
|
|
*/
|
|
|
|
|
public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor {
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new POIXMLPropertiesTextExtractor for the
|
|
|
|
|
* given open document.
|
|
|
|
|
*/
|
|
|
|
|
public POIXMLPropertiesTextExtractor(POIXMLDocument doc) {
|
|
|
|
|
super(doc);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new POIXMLPropertiesTextExtractor, for the
|
|
|
|
|
* same file that another TextExtractor is already
|
|
|
|
|
* working on.
|
|
|
|
|
*/
|
|
|
|
|
public POIXMLPropertiesTextExtractor(POIXMLTextExtractor otherExtractor) {
|
2009-08-22 05:50:32 +00:00
|
|
|
super(otherExtractor.getDocument());
|
2008-08-12 20:58:31 +00:00
|
|
|
}
|
2010-06-04 12:02:36 +00:00
|
|
|
|
|
|
|
|
private void appendIfPresent(StringBuffer text, String thing, boolean value) {
|
|
|
|
|
appendIfPresent(text, thing, Boolean.toString(value));
|
|
|
|
|
}
|
|
|
|
|
private void appendIfPresent(StringBuffer text, String thing, int value) {
|
|
|
|
|
appendIfPresent(text, thing, Integer.toString(value));
|
|
|
|
|
}
|
|
|
|
|
private void appendIfPresent(StringBuffer text, String thing, Date value) {
|
|
|
|
|
if(value == null) { return; }
|
|
|
|
|
appendIfPresent(text, thing, value.toString());
|
|
|
|
|
}
|
|
|
|
|
private void appendIfPresent(StringBuffer text, String thing, String value) {
|
|
|
|
|
if(value == null) { return; }
|
|
|
|
|
text.append(thing);
|
|
|
|
|
text.append(" = ");
|
|
|
|
|
text.append(value);
|
|
|
|
|
text.append("\n");
|
|
|
|
|
}
|
2009-08-22 05:50:32 +00:00
|
|
|
|
2008-08-12 20:58:31 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the core document properties, eg author
|
|
|
|
|
*/
|
2009-08-21 06:08:31 +00:00
|
|
|
public String getCorePropertiesText() {
|
2008-08-12 20:58:31 +00:00
|
|
|
StringBuffer text = new StringBuffer();
|
|
|
|
|
PackagePropertiesPart props =
|
2009-08-22 05:50:32 +00:00
|
|
|
getDocument().getProperties().getCoreProperties().getUnderlyingProperties();
|
|
|
|
|
|
2010-06-04 12:02:36 +00:00
|
|
|
appendIfPresent(text, "Category", props.getCategoryProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Category", props.getCategoryProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "ContentStatus", props.getContentStatusProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "ContentType", props.getContentTypeProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Created", props.getCreatedProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "CreatedString", props.getCreatedPropertyString());
|
|
|
|
|
appendIfPresent(text, "Creator", props.getCreatorProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Description", props.getDescriptionProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Identifier", props.getIdentifierProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Keywords", props.getKeywordsProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Language", props.getLanguageProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "LastModifiedBy", props.getLastModifiedByProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "LastPrinted", props.getLastPrintedProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "LastPrintedString", props.getLastPrintedPropertyString());
|
|
|
|
|
appendIfPresent(text, "Modified", props.getModifiedProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "ModifiedString", props.getModifiedPropertyString());
|
|
|
|
|
appendIfPresent(text, "Revision", props.getRevisionProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Subject", props.getSubjectProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Title", props.getTitleProperty().getValue());
|
|
|
|
|
appendIfPresent(text, "Version", props.getVersionProperty().getValue());
|
2008-08-12 20:58:31 +00:00
|
|
|
|
|
|
|
|
return text.toString();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Returns the extended document properties, eg
|
|
|
|
|
* application
|
|
|
|
|
*/
|
2009-08-21 06:08:31 +00:00
|
|
|
public String getExtendedPropertiesText() {
|
2008-08-12 20:58:31 +00:00
|
|
|
StringBuffer text = new StringBuffer();
|
|
|
|
|
org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties
|
2009-08-22 05:50:32 +00:00
|
|
|
props = getDocument().getProperties().getExtendedProperties().getUnderlyingProperties();
|
2008-08-12 20:58:31 +00:00
|
|
|
|
2010-06-04 12:02:36 +00:00
|
|
|
appendIfPresent(text, "Application", props.getApplication());
|
|
|
|
|
appendIfPresent(text, "AppVersion", props.getAppVersion());
|
|
|
|
|
appendIfPresent(text, "Characters", props.getCharacters());
|
|
|
|
|
appendIfPresent(text, "CharactersWithSpaces", props.getCharactersWithSpaces());
|
|
|
|
|
appendIfPresent(text, "Company", props.getCompany());
|
|
|
|
|
appendIfPresent(text, "HyperlinkBase", props.getHyperlinkBase());
|
|
|
|
|
appendIfPresent(text, "HyperlinksChanged", props.getHyperlinksChanged());
|
|
|
|
|
appendIfPresent(text, "Lines", props.getLines());
|
|
|
|
|
appendIfPresent(text, "LinksUpToDate", props.getLinksUpToDate());
|
|
|
|
|
appendIfPresent(text, "Manager", props.getManager());
|
|
|
|
|
appendIfPresent(text, "Pages", props.getPages());
|
|
|
|
|
appendIfPresent(text, "Paragraphs", props.getParagraphs());
|
|
|
|
|
appendIfPresent(text, "PresentationFormat", props.getPresentationFormat());
|
|
|
|
|
appendIfPresent(text, "Template", props.getTemplate());
|
|
|
|
|
appendIfPresent(text, "TotalTime", props.getTotalTime());
|
2009-08-22 05:50:32 +00:00
|
|
|
|
2008-08-12 20:58:31 +00:00
|
|
|
return text.toString();
|
|
|
|
|
}
|
|
|
|
|
/**
|
2009-08-22 05:50:32 +00:00
|
|
|
* Returns the custom document properties, if
|
2008-08-12 20:58:31 +00:00
|
|
|
* there are any
|
|
|
|
|
*/
|
2009-08-21 06:08:31 +00:00
|
|
|
public String getCustomPropertiesText() {
|
2008-08-12 20:58:31 +00:00
|
|
|
StringBuffer text = new StringBuffer();
|
|
|
|
|
org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties
|
2009-08-22 05:50:32 +00:00
|
|
|
props = getDocument().getProperties().getCustomProperties().getUnderlyingProperties();
|
|
|
|
|
|
2010-06-22 13:59:44 +00:00
|
|
|
List<CTProperty> properties = props.getPropertyList();
|
|
|
|
|
for(int i = 0; i<properties.size(); i++) {
|
2008-08-12 20:58:31 +00:00
|
|
|
// TODO - finish off
|
|
|
|
|
String val = "(not implemented!)";
|
2009-08-22 05:50:32 +00:00
|
|
|
|
2008-08-12 20:58:31 +00:00
|
|
|
text.append(
|
2010-06-22 13:59:44 +00:00
|
|
|
properties.get(i).getName() +
|
2008-08-12 20:58:31 +00:00
|
|
|
" = " + val + "\n"
|
|
|
|
|
);
|
|
|
|
|
}
|
2009-08-22 05:50:32 +00:00
|
|
|
|
2008-08-12 20:58:31 +00:00
|
|
|
return text.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getText() {
|
|
|
|
|
try {
|
2009-08-22 05:50:32 +00:00
|
|
|
return
|
|
|
|
|
getCorePropertiesText() +
|
2008-08-12 20:58:31 +00:00
|
|
|
getExtendedPropertiesText() +
|
|
|
|
|
getCustomPropertiesText();
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-06 19:09:02 +00:00
|
|
|
public POIXMLPropertiesTextExtractor getMetadataTextExtractor() {
|
2008-08-12 20:58:31 +00:00
|
|
|
throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!");
|
|
|
|
|
}
|
|
|
|
|
}
|