Search in sources :

Example 1 with PDFAPropertyType

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

the class PdfaExtensionHelper method populatePDFAPropertyType.

private static void populatePDFAPropertyType(PDFAPropertyType property, TypeMapping tm, XMPSchemaFactory xsf) throws XmpParsingException {
    String pname = property.getName();
    String ptype = property.getValueType();
    String pdescription = property.getDescription();
    String pCategory = property.getCategory();
    // check all mandatory fields are OK
    if (pname == null || ptype == null || pdescription == null || pCategory == null) {
        // all fields are mandatory
        throw new XmpParsingException(ErrorType.RequiredProperty, "Missing field in property definition");
    }
    // check ptype existance
    PropertyType pt = transformValueType(tm, ptype);
    if (pt == null) {
        throw new XmpParsingException(ErrorType.NoValueType, "Unknown property value type : " + ptype);
    }
    if (pt.type() == null) {
        throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : " + ptype);
    } else if (pt.type().isSimple() || pt.type().isStructured() || pt.type() == Types.DefinedType) {
        xsf.getPropertyDefinition().addNewProperty(pname, pt);
    } else {
        throw new XmpParsingException(ErrorType.NoValueType, "Type not defined : " + ptype);
    }
}
Also used : PDFAPropertyType(org.apache.xmpbox.type.PDFAPropertyType) PropertyType(org.apache.xmpbox.type.PropertyType)

Example 2 with PDFAPropertyType

use of org.apache.xmpbox.type.PDFAPropertyType 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 ?
    }
}
Also used : PDFATypeType(org.apache.xmpbox.type.PDFATypeType) ArrayProperty(org.apache.xmpbox.type.ArrayProperty) AbstractField(org.apache.xmpbox.type.AbstractField) XMPSchemaFactory(org.apache.xmpbox.schema.XMPSchemaFactory) PDFAPropertyType(org.apache.xmpbox.type.PDFAPropertyType)

Aggregations

PDFAPropertyType (org.apache.xmpbox.type.PDFAPropertyType)2 XMPSchemaFactory (org.apache.xmpbox.schema.XMPSchemaFactory)1 AbstractField (org.apache.xmpbox.type.AbstractField)1 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)1 PDFATypeType (org.apache.xmpbox.type.PDFATypeType)1 PropertyType (org.apache.xmpbox.type.PropertyType)1