Search in sources :

Example 1 with XMPException

use of com.adobe.xmp.XMPException in project tika by apache.

the class XMPMetadata method set.

/**
     * Sets array properties. If the property already exists, it is overwritten. Only array
     * properties that use a registered prefix are stored in the XMP.
     *
     * @see org.apache.tika.metadata.Metadata#set(org.apache.tika.metadata.Property,
     *      java.lang.String[])
     */
@Override
public void set(Property property, String[] values) {
    checkKey(property.getName());
    if (!property.isMultiValuePermitted()) {
        throw new PropertyTypeException("Property is not of an array type");
    }
    String[] keyParts = splitKey(property.getName());
    String ns = registry.getNamespaceURI(keyParts[0]);
    if (ns != null) {
        try {
            int arrayType = tikaToXMPArrayType(property.getPrimaryProperty().getPropertyType());
            xmpData.setProperty(ns, keyParts[1], null, new PropertyOptions(arrayType));
            for (String value : values) {
                xmpData.appendArrayItem(ns, keyParts[1], value);
            }
        } catch (XMPException e) {
        // Ignore
        }
    }
}
Also used : PropertyOptions(com.adobe.xmp.options.PropertyOptions) PropertyTypeException(org.apache.tika.metadata.PropertyTypeException) XMPException(com.adobe.xmp.XMPException)

Example 2 with XMPException

use of com.adobe.xmp.XMPException in project tika by apache.

the class XMPMetadata method isMultiValued.

/**
     * Checks if the named property is an array.
     *
     * @see org.apache.tika.metadata.Metadata#isMultiValued(java.lang.String)
     */
@Override
public boolean isMultiValued(String name) {
    checkKey(name);
    String[] keyParts = splitKey(name);
    String ns = registry.getNamespaceURI(keyParts[0]);
    if (ns != null) {
        try {
            XMPProperty prop = xmpData.getProperty(ns, keyParts[1]);
            return prop.getOptions().isArray();
        } catch (XMPException e) {
        // Ignore
        }
    }
    return false;
}
Also used : XMPException(com.adobe.xmp.XMPException) XMPProperty(com.adobe.xmp.properties.XMPProperty)

Example 3 with XMPException

use of com.adobe.xmp.XMPException in project tika by apache.

the class XMPMetadata method getDate.

/**
     * @see org.apache.tika.xmp.XMPMetadata#get(java.lang.String)
     */
@Override
public Date getDate(Property property) {
    Date result = null;
    try {
        XMPDateTime xmpDate = XMPUtils.convertToDate(this.get(property.getName()));
        if (xmpDate != null) {
            Calendar cal = xmpDate.getCalendar();
            // TODO Timezone is currently lost
            // need another solution that preserves the timezone
            result = cal.getTime();
        }
    } catch (XMPException e) {
    // Ignore
    }
    return result;
}
Also used : Calendar(java.util.Calendar) XMPDateTime(com.adobe.xmp.XMPDateTime) XMPException(com.adobe.xmp.XMPException) Date(java.util.Date)

Example 4 with XMPException

use of com.adobe.xmp.XMPException in project tika by apache.

the class TikaToXMP method convert.

/**
     * Convert the given Tika metadata map to XMP object. If a mimetype is provided in the Metadata
     * map, a specific converter can be used, that converts all available metadata. If there is no
     * mimetype provided or no specific converter available a generic conversion is done which will
     * convert only those properties that are in known namespaces and are using the correct
     * prefixes.
     *
     * @param tikaMetadata
     *            the Metadata map from Tika
     * @param mimetype
     *            depicts the format's converter to use
     * @return XMP object
     * @throws TikaException
     */
public static XMPMeta convert(Metadata tikaMetadata, String mimetype) throws TikaException {
    if (tikaMetadata == null) {
        throw new IllegalArgumentException("Metadata parameter must not be null");
    }
    ITikaToXMPConverter converter = null;
    if (isConverterAvailable(mimetype)) {
        converter = getConverter(mimetype);
    } else {
        converter = new GenericConverter();
    }
    XMPMeta xmp = null;
    if (converter != null) {
        try {
            xmp = converter.process(tikaMetadata);
        } catch (XMPException e) {
            throw new TikaException("Tika metadata could not be converted to XMP", e);
        }
    } else {
        // empty packet
        xmp = XMPMetaFactory.create();
    }
    return xmp;
}
Also used : TikaException(org.apache.tika.exception.TikaException) XMPMeta(com.adobe.xmp.XMPMeta) XMPException(com.adobe.xmp.XMPException)

Example 5 with XMPException

use of com.adobe.xmp.XMPException in project tika by apache.

the class XMPMetadata method size.

/**
     * Returns the number of top-level namespaces
     */
@Override
public int size() {
    int size = 0;
    try {
        // Get an iterator for the XMP packet, starting at the top level schema nodes
        XMPIterator nsIter = xmpData.iterator(new IteratorOptions().setJustChildren(true).setOmitQualifiers(true));
        // iterate all top level namespaces
        while (nsIter.hasNext()) {
            nsIter.next();
            size++;
        }
    } catch (XMPException e) {
    // ignore
    }
    return size;
}
Also used : XMPIterator(com.adobe.xmp.XMPIterator) XMPException(com.adobe.xmp.XMPException) IteratorOptions(com.adobe.xmp.options.IteratorOptions)

Aggregations

XMPException (com.adobe.xmp.XMPException)7 XMPProperty (com.adobe.xmp.properties.XMPProperty)3 XMPDateTime (com.adobe.xmp.XMPDateTime)1 XMPIterator (com.adobe.xmp.XMPIterator)1 XMPMeta (com.adobe.xmp.XMPMeta)1 IteratorOptions (com.adobe.xmp.options.IteratorOptions)1 PropertyOptions (com.adobe.xmp.options.PropertyOptions)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 TikaException (org.apache.tika.exception.TikaException)1 PropertyTypeException (org.apache.tika.metadata.PropertyTypeException)1