Search in sources :

Example 6 with AbstractField

use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.

the class XMPSchema method setSpecifiedSimpleTypeProperty.

private void setSpecifiedSimpleTypeProperty(Types type, String qualifiedName, Object propertyValue) {
    if (propertyValue == null) {
        // Search in properties to erase
        for (AbstractField child : getContainer().getAllProperties()) {
            if (child.getPropertyName().equals(qualifiedName)) {
                getContainer().removeProperty(child);
                return;
            }
        }
    } else {
        AbstractSimpleProperty specifiedTypeProperty;
        try {
            TypeMapping tm = getMetadata().getTypeMapping();
            specifiedTypeProperty = tm.instanciateSimpleProperty(null, getPrefix(), qualifiedName, propertyValue, type);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to create property with the specified type given in parameters", e);
        }
        // Search in properties to erase
        for (AbstractField child : getAllProperties()) {
            if (child.getPropertyName().equals(qualifiedName)) {
                removeProperty(child);
                addProperty(specifiedTypeProperty);
                return;
            }
        }
        addProperty(specifiedTypeProperty);
    }
}
Also used : AbstractField(org.apache.xmpbox.type.AbstractField) AbstractSimpleProperty(org.apache.xmpbox.type.AbstractSimpleProperty) TypeMapping(org.apache.xmpbox.type.TypeMapping) IOException(java.io.IOException) BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException)

Example 7 with AbstractField

use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.

the class XMPSchema method setSpecifiedSimpleTypeProperty.

/**
 * Add a SimpleProperty to this schema
 *
 * @param prop
 *            The Property to add
 */
private void setSpecifiedSimpleTypeProperty(AbstractSimpleProperty prop) {
    // Search in properties to erase
    for (AbstractField child : getAllProperties()) {
        if (child.getPropertyName().equals(prop.getPropertyName())) {
            removeProperty(child);
            addProperty(prop);
            return;
        }
    }
    addProperty(prop);
}
Also used : AbstractField(org.apache.xmpbox.type.AbstractField)

Example 8 with AbstractField

use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.

the class XMPSchema method mergeComplexProperty.

private boolean mergeComplexProperty(Iterator<AbstractField> itNewValues, ArrayProperty arrayProperty) {
    while (itNewValues.hasNext()) {
        TextType tmpNewValue = (TextType) itNewValues.next();
        for (AbstractField abstractField : arrayProperty.getContainer().getAllProperties()) {
            TextType tmpOldValue = (TextType) abstractField;
            if (tmpOldValue.getStringValue().equals(tmpNewValue.getStringValue())) {
                return true;
            }
        }
        arrayProperty.getContainer().addProperty(tmpNewValue);
    }
    return false;
}
Also used : AbstractField(org.apache.xmpbox.type.AbstractField) TextType(org.apache.xmpbox.type.TextType)

Example 9 with AbstractField

use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.

the class XMPSchema method getUnqualifiedLanguagePropertyLanguagesValue.

/**
 * Get a list of all languages that are currently defined for a specific
 * property.
 *
 * @param name The name of the property, it must include the namespace
 * prefix, e.g. "pdf:Keywords".
 *
 * @return A list of all languages, this will return an non-null empty list
 * if none have been defined, and null if the property doesn't exist.
 */
public List<String> getUnqualifiedLanguagePropertyLanguagesValue(String name) {
    AbstractField property = getAbstractProperty(name);
    if (property != null) {
        if (property instanceof ArrayProperty) {
            List<String> retval = new ArrayList<>();
            ArrayProperty arrayProp = (ArrayProperty) property;
            for (AbstractField child : arrayProp.getContainer().getAllProperties()) {
                Attribute text = child.getAttribute(XmpConstants.LANG_NAME);
                if (text != null) {
                    retval.add(text.getValue());
                } else {
                    retval.add(XmpConstants.X_DEFAULT);
                }
            }
            return retval;
        } else {
            throw new IllegalArgumentException("The property '" + name + "' is not of Lang Alt type");
        }
    }
    // no property with that name
    return null;
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) AbstractField(org.apache.xmpbox.type.AbstractField) Attribute(org.apache.xmpbox.type.Attribute) ArrayList(java.util.ArrayList)

Example 10 with AbstractField

use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.

the class XMPSchemaTest method testArrayList.

@Test
public void testArrayList() throws Exception {
    XMPMetadata meta = XMPMetadata.createXMPMetadata();
    ArrayProperty newSeq = meta.getTypeMapping().createArrayProperty(null, "nsSchem", "seqType", Cardinality.Seq);
    TypeMapping tm = meta.getTypeMapping();
    TextType li1 = tm.createText(null, "rdf", "li", "valeur1");
    TextType li2 = tm.createText(null, "rdf", "li", "valeur2");
    newSeq.getContainer().addProperty(li1);
    newSeq.getContainer().addProperty(li2);
    schem.addProperty(newSeq);
    List<AbstractField> list = schem.getUnqualifiedArrayList("seqType");
    Assert.assertTrue(list.contains(li1));
    Assert.assertTrue(list.contains(li2));
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) AbstractField(org.apache.xmpbox.type.AbstractField) XMPMetadata(org.apache.xmpbox.XMPMetadata) TypeMapping(org.apache.xmpbox.type.TypeMapping) TextType(org.apache.xmpbox.type.TextType) Test(org.junit.Test)

Aggregations

AbstractField (org.apache.xmpbox.type.AbstractField)18 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)11 ArrayList (java.util.ArrayList)5 Attribute (org.apache.xmpbox.type.Attribute)5 TextType (org.apache.xmpbox.type.TextType)5 TypeMapping (org.apache.xmpbox.type.TypeMapping)5 Element (org.w3c.dom.Element)4 AbstractSimpleProperty (org.apache.xmpbox.type.AbstractSimpleProperty)3 AbstractStructuredType (org.apache.xmpbox.type.AbstractStructuredType)3 List (java.util.List)2 DefinedStructuredType (org.apache.xmpbox.type.DefinedStructuredType)2 PDFAPropertyType (org.apache.xmpbox.type.PDFAPropertyType)2 PropertiesDescription (org.apache.xmpbox.type.PropertiesDescription)2 PropertyType (org.apache.xmpbox.type.PropertyType)2 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1 XMPMetadata (org.apache.xmpbox.XMPMetadata)1