Search in sources :

Example 1 with XMPMeta

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

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

the class TikaToXMPTest method convert_wrongGenericMetadata_notConverted.

@Test
public void convert_wrongGenericMetadata_notConverted() throws XMPException, TikaException {
    // unknown prefix
    tikaMetadata.set("unknown:key", "unknownPrefixValue");
    // not qualified key
    tikaMetadata.set("wrongKey", "wrongKeyValue");
    XMPMeta xmp = TikaToXMP.convert(tikaMetadata, null);
    // XMP is empty
    XMPIterator iter = xmp.iterator();
    assertFalse(iter.hasNext());
}
Also used : XMPIterator(com.adobe.xmp.XMPIterator) XMPMeta(com.adobe.xmp.XMPMeta) Test(org.junit.Test)

Example 3 with XMPMeta

use of com.adobe.xmp.XMPMeta 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 4 with XMPMeta

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

the class TikaToXMPTest method convert_OOXMLMetadataWithExtraMimetype_everythingConverted.

@Test
public void convert_OOXMLMetadataWithExtraMimetype_everythingConverted() throws XMPException, TikaException {
    setupOOXMLMetadata(tikaMetadata);
    XMPMeta xmp = TikaToXMP.convert(tikaMetadata, OOXML_MIMETYPE);
    checkOOXMLMetadata(xmp);
}
Also used : XMPMeta(com.adobe.xmp.XMPMeta) Test(org.junit.Test)

Example 5 with XMPMeta

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

Aggregations

XMPMeta (com.adobe.xmp.XMPMeta)7 Test (org.junit.Test)6 XMPProperty (com.adobe.xmp.properties.XMPProperty)3 XMPException (com.adobe.xmp.XMPException)1 XMPIterator (com.adobe.xmp.XMPIterator)1 TikaException (org.apache.tika.exception.TikaException)1