Example usage for org.apache.poi.openxml4j.util Nullable getValue

List of usage examples for org.apache.poi.openxml4j.util Nullable getValue

Introduction

In this page you can find the example usage for org.apache.poi.openxml4j.util Nullable getValue.

Prototype

public E getValue() 

Source Link

Document

Get the store value if any.

Usage

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

License:Apache License

private <T> void addProperty(Metadata metadata, Property property, Nullable<T> nullableValue) {
    T value = nullableValue.getValue();
    if (value != null) {
        if (value instanceof Date) {
            metadata.set(property, (Date) value);
        } else if (value instanceof String) {
            metadata.set(property, (String) value);
        } else if (value instanceof Integer) {
            metadata.set(property, (Integer) value);
        } else if (value instanceof Double) {
            metadata.set(property, (Double) value);
        }// w w  w . j a  v a  2s  .c o  m
    }
}

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

License:Apache License

private void addProperty(Metadata metadata, String name, Nullable<?> value) {
    if (value.getValue() != null) {
        addProperty(metadata, name, value.getValue().toString());
    }/*from  w w w  .j  a va 2s. com*/
}

From source file:org.apache.tika.parser.microsoft.ooxml.MetadataExtractor.java

License:Apache License

private void addMultiProperty(Metadata metadata, Property property, Nullable<String> value) {
    if (value == null) {
        return;/*from   www  .  java2 s . c o m*/
    }
    SummaryExtractor.addMulti(metadata, property, value.getValue());
}

From source file:org.exoplatform.services.document.impl.POIPropertiesReader.java

License:Open Source License

/**
 * Metadata extraction from ooxml documents (MS 2007 office file formats)
 * /*from w w  w .j  av  a  2s  .com*/
 * @param document
 * @return
 * @throws IOException
 * @throws DocumentReadException
 */
public Properties readDCProperties(POIXMLDocument document) throws IOException, DocumentReadException {

    POIXMLPropertiesTextExtractor extractor = new POIXMLPropertiesTextExtractor(document);

    CoreProperties coreProperties = extractor.getCoreProperties();

    Nullable<String> lastModifiedBy = coreProperties.getUnderlyingProperties().getLastModifiedByProperty();

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    df.setTimeZone(TimeZone.getDefault());

    if (lastModifiedBy != null && lastModifiedBy.getValue() != null && lastModifiedBy.getValue().length() > 0) {
        props.put(DCMetaData.CONTRIBUTOR, lastModifiedBy.getValue());
    }
    if (coreProperties.getDescription() != null && coreProperties.getDescription().length() > 0) {
        props.put(DCMetaData.DESCRIPTION, coreProperties.getDescription());
    }
    if (coreProperties.getCreated() != null) {
        try {
            Date d = df.parse(coreProperties.getUnderlyingProperties().getCreatedPropertyString());
            props.put(DCMetaData.DATE, d);
        } catch (ParseException e) {
            throw new DocumentReadException("Incorrect creation date: " + e.getMessage(), e);
        }
    }
    if (coreProperties.getCreator() != null && coreProperties.getCreator().length() > 0) {
        props.put(DCMetaData.CREATOR, coreProperties.getCreator());
    }
    if (coreProperties.getSubject() != null && coreProperties.getSubject().length() > 0) {
        props.put(DCMetaData.SUBJECT, coreProperties.getSubject());
    }
    if (coreProperties.getModified() != null) {
        try {
            Date d = df.parse(coreProperties.getUnderlyingProperties().getModifiedPropertyString());
            props.put(DCMetaData.DATE, d);
        } catch (ParseException e) {
            throw new DocumentReadException("Incorrect modification date: " + e.getMessage(), e);
        }
    }
    if (coreProperties.getSubject() != null && coreProperties.getSubject().length() > 0) {
        props.put(DCMetaData.SUBJECT, coreProperties.getSubject());
    }
    if (coreProperties.getTitle() != null && coreProperties.getTitle().length() > 0) {
        props.put(DCMetaData.TITLE, coreProperties.getTitle());
    }

    return props;
}