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