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;
}