Search in sources :

Example 6 with XMPException

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

the class XMPMetadata method get.

/**
     * Returns the value of a simple property or the first one of an array. The given name must
     * contain a namespace prefix of a registered namespace.
     *
     * @see org.apache.tika.metadata.Metadata#get(java.lang.String)
     */
@Override
public String get(String name) {
    checkKey(name);
    String value = null;
    String[] keyParts = splitKey(name);
    String ns = registry.getNamespaceURI(keyParts[0]);
    if (ns != null) {
        try {
            XMPProperty prop = xmpData.getProperty(ns, keyParts[1]);
            if (prop != null && prop.getOptions().isSimple()) {
                value = prop.getValue();
            } else if (prop != null && prop.getOptions().isArray()) {
                prop = xmpData.getArrayItem(ns, keyParts[1], 1);
                value = prop.getValue();
            }
        // in all other cases, null is returned
        } catch (XMPException e) {
        // Ignore
        }
    }
    return value;
}
Also used : XMPException(com.adobe.xmp.XMPException) XMPProperty(com.adobe.xmp.properties.XMPProperty)

Example 7 with XMPException

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

the class XMPMetadata method getValues.

/**
     * Returns the value of a simple property or all if the property is an array and the elements
     * are of simple type. The given name must contain a namespace prefix of a registered namespace.
     *
     * @see org.apache.tika.metadata.Metadata#getValues(java.lang.String)
     */
@Override
public String[] getValues(String name) {
    checkKey(name);
    String[] value = null;
    String[] keyParts = splitKey(name);
    String ns = registry.getNamespaceURI(keyParts[0]);
    if (ns != null) {
        try {
            XMPProperty prop = xmpData.getProperty(ns, keyParts[1]);
            if (prop != null && prop.getOptions().isSimple()) {
                value = new String[1];
                value[0] = prop.getValue();
            } else if (prop != null && prop.getOptions().isArray()) {
                int size = xmpData.countArrayItems(ns, keyParts[1]);
                value = new String[size];
                boolean onlySimpleChildren = true;
                for (int i = 0; i < size && onlySimpleChildren; i++) {
                    prop = xmpData.getArrayItem(ns, keyParts[1], i + 1);
                    if (prop.getOptions().isSimple()) {
                        value[i] = prop.getValue();
                    } else {
                        onlySimpleChildren = false;
                    }
                }
                if (!onlySimpleChildren) {
                    value = null;
                }
            }
        // in all other cases, null is returned
        } catch (XMPException e) {
        // Ignore
        }
    }
    return value;
}
Also used : XMPException(com.adobe.xmp.XMPException) XMPProperty(com.adobe.xmp.properties.XMPProperty)

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