Search in sources :

Example 1 with XMPProperty

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

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

the class TikaToXMPTest method convert_OOXMLMetadataWithoutMimetype_onlyGeneralMetadataconverted.

@Test
public void convert_OOXMLMetadataWithoutMimetype_onlyGeneralMetadataconverted() throws XMPException, TikaException {
    setupOOXMLMetadata(tikaMetadata);
    XMPMeta xmp = TikaToXMP.convert(tikaMetadata, null);
    // general metadata is converted
    // check simple property
    XMPProperty prop = xmp.getProperty(XMPConst.NS_DC, "language");
    assertNotNull(prop);
    assertEquals("language", prop.getValue());
    // check lang alt
    prop = xmp.getLocalizedText(XMPConst.NS_DC, "title", null, XMPConst.X_DEFAULT);
    assertNotNull(prop);
    assertEquals("title", prop.getValue());
    // OOXML one is not, the namespace has also not been registiered as the converter has not
    // been used
    XMPMetaFactory.getSchemaRegistry().registerNamespace(OfficeOpenXMLCore.NAMESPACE_URI, OfficeOpenXMLCore.PREFIX);
    prop = xmp.getProperty(OfficeOpenXMLCore.NAMESPACE_URI, "lastModifiedBy");
    assertNull(prop);
}
Also used : XMPMeta(com.adobe.xmp.XMPMeta) XMPProperty(com.adobe.xmp.properties.XMPProperty) Test(org.junit.Test)

Example 3 with XMPProperty

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

the class TikaToXMPTest method checkOOXMLMetadata.

private void checkOOXMLMetadata(XMPMeta xmp) throws XMPException {
    // check simple property
    XMPProperty prop = xmp.getProperty(XMPConst.NS_DC, "language");
    assertNotNull(prop);
    assertEquals("language", 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());
    // check OOXML specific simple property
    prop = xmp.getProperty(OfficeOpenXMLCore.NAMESPACE_URI, "lastModifiedBy");
    assertNotNull(prop);
    assertEquals("lastModifiedBy", prop.getValue());
}
Also used : XMPProperty(com.adobe.xmp.properties.XMPProperty)

Example 4 with XMPProperty

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

the class TikaToXMPTest method convert_genericMetadataAllQualified_allConverted.

@Test
public void convert_genericMetadataAllQualified_allConverted() throws XMPException, TikaException {
    // simple property
    tikaMetadata.set(TikaCoreProperties.FORMAT, GENERIC_MIMETYPE);
    // language alternative
    tikaMetadata.set(TikaCoreProperties.TITLE, "title");
    // array
    tikaMetadata.set(TikaCoreProperties.KEYWORDS, new String[] { "keyword1", "keyword2" });
    XMPMeta xmp = TikaToXMP.convert(tikaMetadata, null);
    // 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)

Example 5 with XMPProperty

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

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