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