Search in sources :

Example 1 with PropertyTypeException

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
        }
    }
}
Also used : PropertyOptions(com.adobe.xmp.options.PropertyOptions) PropertyTypeException(org.apache.tika.metadata.PropertyTypeException) XMPException(com.adobe.xmp.XMPException)

Example 2 with PropertyTypeException

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);
}
Also used : Metadata(org.apache.tika.metadata.Metadata) PropertyTypeException(org.apache.tika.metadata.PropertyTypeException) Test(org.junit.Test)

Example 3 with PropertyTypeException

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);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) PropertyTypeException(org.apache.tika.metadata.PropertyTypeException) XMPProperty(com.adobe.xmp.properties.XMPProperty) Property(org.apache.tika.metadata.Property)

Aggregations

PropertyTypeException (org.apache.tika.metadata.PropertyTypeException)3 XMPException (com.adobe.xmp.XMPException)1 PropertyOptions (com.adobe.xmp.options.PropertyOptions)1 XMPProperty (com.adobe.xmp.properties.XMPProperty)1 Enumeration (java.util.Enumeration)1 Metadata (org.apache.tika.metadata.Metadata)1 Property (org.apache.tika.metadata.Property)1 Test (org.junit.Test)1