use of org.apache.xmpbox.type.AbstractField 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.AbstractField in project pdfbox by apache.
the class XMPSchema method getUnqualifiedSequenceDateValueList.
/**
* Get all the date values in a sequence property.
*
* @param seqName
* The name of the sequence property, it must include the namespace prefix, e.g. "pdf:Keywords".
*
* @return A read-only list of java.util.Calendar objects or null if the property does not exist.
*/
public List<Calendar> getUnqualifiedSequenceDateValueList(String seqName) {
List<Calendar> retval = null;
ArrayProperty seq = (ArrayProperty) getAbstractProperty(seqName);
if (seq != null) {
retval = new ArrayList<>();
for (AbstractField child : seq.getContainer().getAllProperties()) {
if (child instanceof DateType) {
retval.add(((DateType) child).getValue());
}
}
}
return retval;
}
use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.
the class XMPSchema method reorganizeAltOrder.
/**
* Method used to place the 'x-default' value in first in Language alternatives as said in xmp spec
*
* @param alt
* The property to reorganize
*/
public void reorganizeAltOrder(ComplexPropertyContainer alt) {
Iterator<AbstractField> it = alt.getAllProperties().iterator();
AbstractField xdefault = null;
boolean xdefaultFound = false;
// If alternatives contains x-default in first value
if (it.hasNext() && it.next().getAttribute(XmpConstants.LANG_NAME).getValue().equals(XmpConstants.X_DEFAULT)) {
return;
}
// Find the xdefault definition
while (it.hasNext() && !xdefaultFound) {
xdefault = it.next();
if (xdefault.getAttribute(XmpConstants.LANG_NAME).getValue().equals(XmpConstants.X_DEFAULT)) {
alt.removeProperty(xdefault);
xdefaultFound = true;
}
}
if (xdefaultFound) {
it = alt.getAllProperties().iterator();
List<AbstractField> reordered = new ArrayList<>();
List<AbstractField> toDelete = new ArrayList<>();
reordered.add(xdefault);
while (it.hasNext()) {
AbstractField tmp = it.next();
reordered.add(tmp);
toDelete.add(tmp);
}
for (AbstractField aToDelete : toDelete) {
alt.removeProperty(aToDelete);
}
it = reordered.iterator();
while (it.hasNext()) {
alt.addProperty(it.next());
}
}
}
Aggregations