Search in sources :

Example 6 with PropertyType

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

the class DomXmpParser method parseDescriptionRootAttr.

private void parseDescriptionRootAttr(XMPMetadata xmp, Element description, Attr attr, TypeMapping tm) throws XmpSchemaException, XmpParsingException {
    String namespace = attr.getNamespaceURI();
    XMPSchema schema = xmp.getSchema(namespace);
    if (schema == null && tm.getSchemaFactory(namespace) != null) {
        schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, attr.getPrefix());
        loadAttributes(schema, description);
    }
    // Only process when a schema was successfully found
    if (schema != null) {
        ComplexPropertyContainer container = schema.getContainer();
        PropertyType type = checkPropertyDefinition(xmp, new QName(attr.getNamespaceURI(), attr.getLocalName()));
        // Default to text if no type is found
        if (type == null) {
            type = TypeMapping.createPropertyType(Types.Text, Cardinality.Simple);
        }
        try {
            AbstractSimpleProperty sp = tm.instanciateSimpleProperty(namespace, schema.getPrefix(), attr.getLocalName(), attr.getValue(), type.type());
            container.addProperty(sp);
        } catch (IllegalArgumentException e) {
            throw new XmpParsingException(ErrorType.Format, e.getMessage() + " in " + schema.getPrefix() + ":" + attr.getLocalName(), e);
        }
    }
}
Also used : XMPSchema(org.apache.xmpbox.schema.XMPSchema) QName(javax.xml.namespace.QName) AbstractSimpleProperty(org.apache.xmpbox.type.AbstractSimpleProperty) ComplexPropertyContainer(org.apache.xmpbox.type.ComplexPropertyContainer) PropertyType(org.apache.xmpbox.type.PropertyType)

Example 7 with PropertyType

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

the class DomXmpParser method parseChildrenAsProperties.

private void parseChildrenAsProperties(XMPMetadata xmp, List<Element> properties, TypeMapping tm, Element description) throws XmpParsingException, XmpSchemaException {
    // parse children elements as properties
    for (Element property : properties) {
        String namespace = property.getNamespaceURI();
        PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property));
        // create the container
        if (!tm.isDefinedSchema(namespace)) {
            throw new XmpParsingException(ErrorType.NoSchema, "This namespace is not a schema or a structured type : " + namespace);
        }
        XMPSchema schema = xmp.getSchema(namespace);
        if (schema == null) {
            schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, property.getPrefix());
            loadAttributes(schema, description);
        }
        ComplexPropertyContainer container = schema.getContainer();
        // create property
        createProperty(xmp, property, type, container);
    }
}
Also used : XMPSchema(org.apache.xmpbox.schema.XMPSchema) Element(org.w3c.dom.Element) ComplexPropertyContainer(org.apache.xmpbox.type.ComplexPropertyContainer) PropertyType(org.apache.xmpbox.type.PropertyType)

Aggregations

PropertyType (org.apache.xmpbox.type.PropertyType)7 XMPSchema (org.apache.xmpbox.schema.XMPSchema)3 ComplexPropertyContainer (org.apache.xmpbox.type.ComplexPropertyContainer)3 TypeMapping (org.apache.xmpbox.type.TypeMapping)3 Element (org.w3c.dom.Element)3 AbstractField (org.apache.xmpbox.type.AbstractField)2 AbstractSimpleProperty (org.apache.xmpbox.type.AbstractSimpleProperty)2 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)2 PDFAPropertyType (org.apache.xmpbox.type.PDFAPropertyType)2 PropertiesDescription (org.apache.xmpbox.type.PropertiesDescription)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 XMPSchemaFactory (org.apache.xmpbox.schema.XMPSchemaFactory)1 AbstractStructuredType (org.apache.xmpbox.type.AbstractStructuredType)1 DefinedStructuredType (org.apache.xmpbox.type.DefinedStructuredType)1 PDFAFieldType (org.apache.xmpbox.type.PDFAFieldType)1 Types (org.apache.xmpbox.type.Types)1