Search in sources :

Example 11 with TypeMapping

use of org.apache.xmpbox.type.TypeMapping 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 ?
            }
        }
    }
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) AbstractField(org.apache.xmpbox.type.AbstractField) XMPSchema(org.apache.xmpbox.schema.XMPSchema) PDFAExtensionSchema(org.apache.xmpbox.schema.PDFAExtensionSchema) TypeMapping(org.apache.xmpbox.type.TypeMapping) PDFASchemaType(org.apache.xmpbox.type.PDFASchemaType) StructuredType(org.apache.xmpbox.type.StructuredType) AbstractStructuredType(org.apache.xmpbox.type.AbstractStructuredType) DefinedStructuredType(org.apache.xmpbox.type.DefinedStructuredType)

Example 12 with TypeMapping

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

the class TestExifXmp method testGenerate.

@Test
public void testGenerate() throws Exception {
    XMPMetadata metadata = XMPMetadata.createXMPMetadata();
    TypeMapping tmapping = metadata.getTypeMapping();
    ExifSchema exif = new ExifSchema(metadata);
    metadata.addSchema(exif);
    OECFType oecf = new OECFType(metadata);
    oecf.addProperty(tmapping.createInteger(oecf.getNamespace(), oecf.getPrefix(), OECFType.COLUMNS, 14));
    oecf.setPropertyName(ExifSchema.OECF);
    exif.addProperty(oecf);
    XmpSerializer serializer = new XmpSerializer();
    serializer.serialize(metadata, new ByteArrayOutputStream(), false);
}
Also used : OECFType(org.apache.xmpbox.type.OECFType) XmpSerializer(org.apache.xmpbox.xml.XmpSerializer) XMPMetadata(org.apache.xmpbox.XMPMetadata) TypeMapping(org.apache.xmpbox.type.TypeMapping) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

TypeMapping (org.apache.xmpbox.type.TypeMapping)12 AbstractField (org.apache.xmpbox.type.AbstractField)5 Element (org.w3c.dom.Element)5 AbstractSimpleProperty (org.apache.xmpbox.type.AbstractSimpleProperty)4 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)4 PropertyType (org.apache.xmpbox.type.PropertyType)3 Test (org.junit.Test)3 XMPMetadata (org.apache.xmpbox.XMPMetadata)2 XMPSchema (org.apache.xmpbox.schema.XMPSchema)2 AbstractStructuredType (org.apache.xmpbox.type.AbstractStructuredType)2 BadFieldValueException (org.apache.xmpbox.type.BadFieldValueException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 PDFAExtensionSchema (org.apache.xmpbox.schema.PDFAExtensionSchema)1 XMPSchemaFactory (org.apache.xmpbox.schema.XMPSchemaFactory)1 XmpSchemaException (org.apache.xmpbox.schema.XmpSchemaException)1