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
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations