Search in sources :

Example 1 with XMPSchemaFactory

use of org.apache.xmpbox.schema.XMPSchemaFactory in project pdfbox by apache.

the class TestValidatePermitedMetadata method checkExistence.

@Test
public void checkExistence() throws Exception {
    // ensure schema exists
    XMPMetadata xmpmd = new XMPMetadata();
    TypeMapping mapping = new TypeMapping(xmpmd);
    XMPSchemaFactory factory = mapping.getSchemaFactory(namespace);
    assertNotNull("Schema not existing: " + namespace, factory);
    // ensure preferred is as expected
    XMPSchema schema = factory.createXMPSchema(xmpmd, "aa");
    assertEquals(preferred, schema.getPreferedPrefix());
    // ensure field is defined
    boolean found = false;
    Class<?> clz = schema.getClass();
    for (Field dfield : clz.getDeclaredFields()) {
        PropertyType ptype = dfield.getAnnotation(PropertyType.class);
        if (ptype != null) {
            // is a field definition
            if (String.class.equals(dfield.getType())) {
                String value = (String) dfield.get(clz);
                if (fieldname.equals(value)) {
                    // found the field defining
                    found = true;
                    break;
                }
            } else {
                // All field declaration are string
                throw new IllegalArgumentException("Should be a string : " + dfield.getName());
            }
        }
    }
    String msg = String.format("Did not find field definition for '%s' in %s (%s)", fieldname, clz.getSimpleName(), namespace);
    assertTrue(msg, found);
}
Also used : Field(java.lang.reflect.Field) XMPSchemaFactory(org.apache.xmpbox.schema.XMPSchemaFactory) XMPSchema(org.apache.xmpbox.schema.XMPSchema) TypeMapping(org.apache.xmpbox.type.TypeMapping) PropertyType(org.apache.xmpbox.type.PropertyType) Test(org.junit.Test)

Example 2 with XMPSchemaFactory

use of org.apache.xmpbox.schema.XMPSchemaFactory 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)

Example 3 with XMPSchemaFactory

use of org.apache.xmpbox.schema.XMPSchemaFactory in project pdfbox by apache.

the class TypeMapping method addNameSpace.

private void addNameSpace(Class<? extends XMPSchema> classSchem) {
    StructuredType st = classSchem.getAnnotation(StructuredType.class);
    String ns = st.namespace();
    schemaMap.put(ns, new XMPSchemaFactory(ns, classSchem, initializePropMapping(classSchem)));
}
Also used : XMPSchemaFactory(org.apache.xmpbox.schema.XMPSchemaFactory)

Example 4 with XMPSchemaFactory

use of org.apache.xmpbox.schema.XMPSchemaFactory in project pdfbox by apache.

the class TypeMapping method addNewNameSpace.

public void addNewNameSpace(String ns, String prefered) {
    PropertiesDescription mapping = new PropertiesDescription();
    schemaMap.put(ns, new XMPSchemaFactory(ns, XMPSchema.class, mapping));
}
Also used : XMPSchemaFactory(org.apache.xmpbox.schema.XMPSchemaFactory) XMPSchema(org.apache.xmpbox.schema.XMPSchema)

Aggregations

XMPSchemaFactory (org.apache.xmpbox.schema.XMPSchemaFactory)4 XMPSchema (org.apache.xmpbox.schema.XMPSchema)2 Field (java.lang.reflect.Field)1 AbstractField (org.apache.xmpbox.type.AbstractField)1 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)1 PDFAPropertyType (org.apache.xmpbox.type.PDFAPropertyType)1 PDFATypeType (org.apache.xmpbox.type.PDFATypeType)1 PropertyType (org.apache.xmpbox.type.PropertyType)1 TypeMapping (org.apache.xmpbox.type.TypeMapping)1 Test (org.junit.Test)1