use of org.apache.xmpbox.type.AbstractSimpleProperty in project pdfbox by apache.
the class DomXmpParser method parseLiElement.
private AbstractField parseLiElement(XMPMetadata xmp, QName descriptor, Element liElement, Types type) throws XmpParsingException {
if (DomHelper.isParseTypeResource(liElement)) {
return parseLiDescription(xmp, descriptor, liElement);
}
// will find rdf:Description
Element liChild = DomHelper.getUniqueElementChild(liElement);
if (liChild != null) {
nsFinder.push(liChild);
return parseLiDescription(xmp, descriptor, liChild);
} else {
// no child
String text = liElement.getTextContent();
TypeMapping tm = xmp.getTypeMapping();
AbstractSimpleProperty sp = tm.instanciateSimpleProperty(descriptor.getNamespaceURI(), descriptor.getPrefix(), descriptor.getLocalPart(), text, type);
loadAttributes(sp, liElement);
return sp;
}
}
use of org.apache.xmpbox.type.AbstractSimpleProperty in project pdfbox by apache.
the class XmpSerializer method serializeFields.
public void serializeFields(Document doc, Element parent, List<AbstractField> fields, String resourceNS, String prefix, boolean wrapWithProperty) {
for (AbstractField field : fields) {
if (field instanceof AbstractSimpleProperty) {
AbstractSimpleProperty simple = (AbstractSimpleProperty) field;
String localPrefix;
if (prefix != null && !prefix.isEmpty()) {
localPrefix = prefix;
} else {
localPrefix = simple.getPrefix();
}
Element esimple = doc.createElement(localPrefix + ":" + simple.getPropertyName());
esimple.setTextContent(simple.getStringValue());
List<Attribute> attributes = simple.getAllAttributes();
for (Attribute attribute : attributes) {
esimple.setAttributeNS(attribute.getNamespace(), attribute.getName(), attribute.getValue());
}
parent.appendChild(esimple);
} else if (field instanceof ArrayProperty) {
ArrayProperty array = (ArrayProperty) field;
// property
Element asimple = doc.createElement(array.getPrefix() + ":" + array.getPropertyName());
parent.appendChild(asimple);
// attributes
fillElementWithAttributes(asimple, array);
// the array definition
Element econtainer = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + array.getArrayType());
asimple.appendChild(econtainer);
// for each element of the array
List<AbstractField> innerFields = array.getAllProperties();
serializeFields(doc, econtainer, innerFields, resourceNS, XmpConstants.DEFAULT_RDF_PREFIX, false);
} else if (field instanceof AbstractStructuredType) {
AbstractStructuredType structured = (AbstractStructuredType) field;
List<AbstractField> innerFields = structured.getAllProperties();
// property name attribute
Element listParent = parent;
if (wrapWithProperty) {
Element nstructured = doc.createElement(resourceNS + ":" + structured.getPropertyName());
parent.appendChild(nstructured);
listParent = nstructured;
}
// element li
Element estructured = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + XmpConstants.LIST_NAME);
listParent.appendChild(estructured);
if (parseTypeResourceForLi) {
estructured.setAttribute("rdf:parseType", "Resource");
// all properties
serializeFields(doc, estructured, innerFields, resourceNS, null, true);
} else {
// element description
Element econtainer = doc.createElement(XmpConstants.DEFAULT_RDF_PREFIX + ":" + "Description");
estructured.appendChild(econtainer);
// all properties
serializeFields(doc, econtainer, innerFields, resourceNS, null, true);
}
} else {
// XXX finish serialization classes
System.err.println(">> TODO >> " + field.getClass());
}
}
}
use of org.apache.xmpbox.type.AbstractSimpleProperty in project pdfbox by apache.
the class AbstractSchemaTester method internalTestPropertySetterSimple.
private void internalTestPropertySetterSimple() throws Exception {
if (cardinality != Cardinality.Simple) {
return;
}
XMPSchema schema = getSchema();
String setter = calculateSimpleSetter(fieldName) + "Property";
Object value = getJavaValue(type);
AbstractSimpleProperty asp = typeMapping.instanciateSimpleProperty(schema.getNamespace(), schema.getPrefix(), fieldName, value, type);
Method set = getSchemaClass().getMethod(setter, type.getImplementingClass());
set.invoke(schema, asp);
// check property set
AbstractSimpleProperty stored = (AbstractSimpleProperty) schema.getProperty(fieldName);
Assert.assertEquals(value, stored.getValue());
// check getter
String getter = calculateSimpleGetter(fieldName) + "Property";
Method get = getSchemaClass().getMethod(getter);
Object result = get.invoke(schema);
Assert.assertTrue(type.getImplementingClass().isAssignableFrom(result.getClass()));
Assert.assertEquals(asp, result);
}
use of org.apache.xmpbox.type.AbstractSimpleProperty in project pdfbox by apache.
the class AbstractSchemaTester method internalTestSettingValue.
private void internalTestSettingValue() throws Exception {
if (cardinality != Cardinality.Simple) {
return;
}
XMPSchema schema = getSchema();
// only test simple properties
Object value = getJavaValue(type);
AbstractSimpleProperty property = schema.instanciateSimple(fieldName, value);
schema.addProperty(property);
String qn = getPropertyQualifiedName(fieldName);
Assert.assertNotNull(schema.getProperty(fieldName));
// check other properties not modified
List<Field> fields = getXmpFields(getSchemaClass());
for (Field field : fields) {
// do not check the current name
String fqn = getPropertyQualifiedName(field.get(null).toString());
if (!fqn.equals(qn)) {
Assert.assertNull(schema.getProperty(fqn));
}
}
}
Aggregations