use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.
the class DomXmpParser method manageArray.
private void manageArray(XMPMetadata xmp, Element property, PropertyType type, ComplexPropertyContainer container) throws XmpParsingException {
TypeMapping tm = xmp.getTypeMapping();
String prefix = property.getPrefix();
String name = property.getLocalName();
String namespace = property.getNamespaceURI();
Element bagOrSeq = DomHelper.getUniqueElementChild(property);
// ensure this is the good type of array
if (bagOrSeq == null) {
// not an array
String whatFound = "nothing";
if (property.getFirstChild() != null) {
whatFound = property.getFirstChild().getClass().getName();
}
throw new XmpParsingException(ErrorType.Format, "Invalid array definition, expecting " + type.card() + " and found " + whatFound + " [prefix=" + prefix + "; name=" + name + "]");
}
if (!bagOrSeq.getLocalName().equals(type.card().name())) {
// not the good array type
throw new XmpParsingException(ErrorType.Format, "Invalid array type, expecting " + type.card() + " and found " + bagOrSeq.getLocalName() + " [prefix=" + prefix + "; name=" + name + "]");
}
ArrayProperty array = tm.createArrayProperty(namespace, prefix, name, type.card());
container.addProperty(array);
List<Element> lis = DomHelper.getElementChildren(bagOrSeq);
for (Element element : lis) {
QName propertyQName = new QName(element.getLocalName());
AbstractField ast = parseLiElement(xmp, propertyQName, element, type.type());
if (ast != null) {
array.addProperty(ast);
}
}
}
use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.
the class PdfaExtensionHelper method populateSchemaMapping.
public static void populateSchemaMapping(XMPMetadata meta) throws XmpParsingException {
List<XMPSchema> schems = meta.getAllSchemas();
TypeMapping tm = meta.getTypeMapping();
StructuredType stPdfaExt = PDFAExtensionSchema.class.getAnnotation(StructuredType.class);
for (XMPSchema xmpSchema : schems) {
if (xmpSchema.getNamespace().equals(stPdfaExt.namespace())) {
// ensure the prefix is the preferred one (cannot use other definition)
if (!xmpSchema.getPrefix().equals(stPdfaExt.preferedPrefix())) {
throw new XmpParsingException(ErrorType.InvalidPrefix, "Found invalid prefix for PDF/A extension, found '" + xmpSchema.getPrefix() + "', should be '" + stPdfaExt.preferedPrefix() + "'");
}
// create schema and types
PDFAExtensionSchema pes = (PDFAExtensionSchema) xmpSchema;
ArrayProperty sp = pes.getSchemasProperty();
for (AbstractField af : sp.getAllProperties()) {
if (af instanceof PDFASchemaType) {
populatePDFASchemaType(meta, (PDFASchemaType) af, tm);
}
// TODO unmanaged ?
}
}
}
}
use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.
the class PdfaExtensionHelper method populatePDFASchemaType.
private static void populatePDFASchemaType(XMPMetadata meta, PDFASchemaType st, TypeMapping tm) throws XmpParsingException {
String namespaceUri = st.getNamespaceURI().trim();
String prefix = st.getPrefixValue();
ArrayProperty properties = st.getProperty();
ArrayProperty valueTypes = st.getValueType();
XMPSchemaFactory xsf = tm.getSchemaFactory(namespaceUri);
// retrieve namespaces
if (xsf == null) {
// create namespace with no field
tm.addNewNameSpace(namespaceUri, prefix);
xsf = tm.getSchemaFactory(namespaceUri);
}
// populate value type
if (valueTypes != null) {
for (AbstractField af2 : valueTypes.getAllProperties()) {
if (af2 instanceof PDFATypeType) {
populatePDFAType(meta, (PDFATypeType) af2, tm);
}
}
}
// populate properties
if (properties == null) {
throw new XmpParsingException(ErrorType.RequiredProperty, "Missing pdfaSchema:property in type definition");
}
for (AbstractField af2 : properties.getAllProperties()) {
if (af2 instanceof PDFAPropertyType) {
populatePDFAPropertyType((PDFAPropertyType) af2, tm, xsf);
}
// TODO unmanaged ?
}
}
use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.
the class XmpSerializer method serializeSchema.
protected Element serializeSchema(Document doc, XMPSchema schema) {
// prepare schema
Element selem = doc.createElementNS(XmpConstants.RDF_NAMESPACE, "rdf:Description");
selem.setAttributeNS(XmpConstants.RDF_NAMESPACE, "rdf:about", schema.getAboutValue());
selem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + schema.getPrefix(), schema.getNamespace());
// the other attributes
fillElementWithAttributes(selem, schema);
// the content
List<AbstractField> fields = schema.getAllProperties();
serializeFields(doc, selem, fields, schema.getPrefix(), null, true);
// return created schema
return selem;
}
use of org.apache.xmpbox.type.AbstractField in project pdfbox by apache.
the class XmpSerializer method normalizeAttributes.
/**
* Normalize the list of attributes.
*
* Attributes which match a schema property are serialized as child elements
* so only return the ones which do not match a schema property
*
* @param property the property that needs to be inspected
* @return the list of attributed for serializing
*/
private List<Attribute> normalizeAttributes(AbstractComplexProperty property) {
List<Attribute> attributes = property.getAllAttributes();
List<Attribute> toSerialize = new ArrayList<>();
List<AbstractField> fields = property.getAllProperties();
for (Attribute attribute : attributes) {
boolean matchesField = false;
for (AbstractField field : fields) {
if (attribute.getName().compareTo(field.getPropertyName()) == 0) {
matchesField = true;
break;
}
}
if (!matchesField) {
toSerialize.add(attribute);
}
}
return toSerialize;
}
Aggregations