use of org.apache.tika.metadata.PropertyTypeException 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 org.apache.tika.metadata.PropertyTypeException in project tika by apache.
the class AccessCheckerTest method testCantAddMultiplesToMetadata.
@Test
public void testCantAddMultiplesToMetadata() {
Metadata m = new Metadata();
boolean ex = false;
m.add(AccessPermissions.EXTRACT_CONTENT, "true");
try {
m.add(AccessPermissions.EXTRACT_CONTENT, "false");
} catch (PropertyTypeException e) {
ex = true;
}
assertTrue("can't add multiple values", ex);
m = new Metadata();
ex = false;
m.add(AccessPermissions.EXTRACT_FOR_ACCESSIBILITY, "true");
try {
m.add(AccessPermissions.EXTRACT_FOR_ACCESSIBILITY, "false");
} catch (PropertyTypeException e) {
ex = true;
}
assertTrue("can't add multiple values", ex);
}
use of org.apache.tika.metadata.PropertyTypeException in project tika by apache.
the class XMPMetadata method setAll.
/**
* It will set all simple and array properties that have QName keys in registered namespaces.
*
* @see org.apache.tika.metadata.Metadata#setAll(java.util.Properties)
*/
@Override
public void setAll(Properties properties) {
@SuppressWarnings("unchecked") Enumeration<String> names = (Enumeration<String>) properties.propertyNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
Property property = Property.get(name);
if (property == null) {
throw new PropertyTypeException("Unknown property: " + name);
}
String value = properties.getProperty(name);
if (property.isMultiValuePermitted()) {
this.set(property, new String[] { value });
} else {
this.set(property, value);
}
}
}
Aggregations