Search in sources :

Example 1 with ResourceRef

use of org.apache.jempbox.xmp.ResourceRef in project tika by apache.

the class JempboxExtractor method extractXMPMM.

/**
     * Extracts Media Management metadata from XMP.
     *
     * Silently swallows exceptions.
     * @param xmp
     * @param metadata
     */
public static void extractXMPMM(XMPMetadata xmp, Metadata metadata) {
    if (xmp == null) {
        return;
    }
    XMPSchemaMediaManagement mmSchema = null;
    try {
        mmSchema = xmp.getMediaManagementSchema();
    } catch (IOException e) {
        //swallow
        return;
    }
    if (mmSchema != null) {
        addMetadata(metadata, XMPMM.DOCUMENTID, mmSchema.getDocumentID());
        //not currently supported by JempBox...
        //          metadata.set(XMPMM.INSTANCEID, mmSchema.getInstanceID());
        ResourceRef derivedFrom = mmSchema.getDerivedFrom();
        if (derivedFrom != null) {
            try {
                addMetadata(metadata, XMPMM.DERIVED_FROM_DOCUMENTID, derivedFrom.getDocumentID());
            } catch (NullPointerException e) {
            }
            try {
                addMetadata(metadata, XMPMM.DERIVED_FROM_INSTANCEID, derivedFrom.getInstanceID());
            } catch (NullPointerException e) {
            }
        //TODO: not yet supported by XMPBox...extract OriginalDocumentID
        //in DerivedFrom section
        }
        if (mmSchema.getHistory() != null) {
            int eventsAdded = 0;
            for (ResourceEvent stevt : mmSchema.getHistory()) {
                if (eventsAdded >= MAX_EVENT_HISTORY_IN_XMPMM) {
                    break;
                }
                String instanceId = null;
                String action = null;
                Calendar when = null;
                String softwareAgent = null;
                try {
                    instanceId = stevt.getInstanceID();
                    action = stevt.getAction();
                    when = stevt.getWhen();
                    softwareAgent = stevt.getSoftwareAgent();
                //instanceid can throw npe; getWhen can throw IOException
                } catch (NullPointerException | IOException e) {
                //swallow
                }
                if (instanceId != null && instanceId.trim().length() > 0) {
                    //for absent data elements, pass in empty strings so
                    //that parallel arrays will have matching offsets
                    //for absent data
                    action = (action == null) ? "" : action;
                    String dateString = (when == null) ? "" : DateUtils.formatDate(when);
                    softwareAgent = (softwareAgent == null) ? "" : softwareAgent;
                    metadata.add(XMPMM.HISTORY_EVENT_INSTANCEID, instanceId);
                    metadata.add(XMPMM.HISTORY_ACTION, action);
                    metadata.add(XMPMM.HISTORY_WHEN, dateString);
                    metadata.add(XMPMM.HISTORY_SOFTWARE_AGENT, softwareAgent);
                    eventsAdded++;
                }
            }
        }
    }
}
Also used : Calendar(java.util.Calendar) ResourceEvent(org.apache.jempbox.xmp.ResourceEvent) ResourceRef(org.apache.jempbox.xmp.ResourceRef) IOException(java.io.IOException) XMPSchemaMediaManagement(org.apache.jempbox.xmp.XMPSchemaMediaManagement)

Aggregations

IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 ResourceEvent (org.apache.jempbox.xmp.ResourceEvent)1 ResourceRef (org.apache.jempbox.xmp.ResourceRef)1 XMPSchemaMediaManagement (org.apache.jempbox.xmp.XMPSchemaMediaManagement)1