Search in sources :

Example 6 with XMPProperty

use of com.adobe.xmp.properties.XMPProperty 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)

Example 7 with XMPProperty

use of com.adobe.xmp.properties.XMPProperty in project tika by apache.

the class XMPMetadataTest method process_genericConversion_ok.

// --- TESTS ---
@Test
public void process_genericConversion_ok() throws TikaException, XMPException {
    xmpMeta.process(tikaMetadata, GENERIC_MIMETYPE);
    XMPMeta xmp = xmpMeta.getXMPData();
    // check simple property
    XMPProperty prop = xmp.getProperty(XMPConst.NS_DC, "format");
    assertNotNull(prop);
    assertEquals(GENERIC_MIMETYPE, prop.getValue());
    // check lang alt
    prop = xmp.getLocalizedText(XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT);
    assertNotNull(prop);
    assertEquals("title", prop.getValue());
    // check array
    prop = xmp.getArrayItem(XMPConst.NS_DC, "subject", 1);
    assertNotNull(prop);
    assertEquals("keyword1", prop.getValue());
    prop = xmp.getArrayItem(XMPConst.NS_DC, "subject", 2);
    assertNotNull(prop);
    assertEquals("keyword2", prop.getValue());
}
Also used : XMPMeta(com.adobe.xmp.XMPMeta) XMPProperty(com.adobe.xmp.properties.XMPProperty) Test(org.junit.Test)

Aggregations

XMPProperty (com.adobe.xmp.properties.XMPProperty)7 XMPException (com.adobe.xmp.XMPException)3 XMPMeta (com.adobe.xmp.XMPMeta)3 Test (org.junit.Test)3