Search in sources :

Example 1 with StructuredType

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

the class BasicJobTicketSchemaTest method testAddWithDefaultPrefix.

@Test
public void testAddWithDefaultPrefix() throws Exception {
    XMPBasicJobTicketSchema basic = metadata.createAndAddBasicJobTicketSchema();
    basic.addJob("zeid2", "zename2", "zeurl2");
    // serializer.serialize(metadata, System.out, true);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    serializer.serialize(metadata, bos, true);
    XMPMetadata rxmp = builder.parse(bos.toByteArray());
    XMPBasicJobTicketSchema jt = rxmp.getBasicJobTicketSchema();
    Assert.assertNotNull(jt);
    Assert.assertEquals(1, jt.getJobs().size());
    StructuredType stjob = JobType.class.getAnnotation(StructuredType.class);
    JobType job = jt.getJobs().get(0);
    Assert.assertEquals("zeid2", job.getId());
    Assert.assertEquals("zename2", job.getName());
    Assert.assertEquals("zeurl2", job.getUrl());
// Assert.assertEquals("Invalid namespace",stjob.namespace(),
// job.getNamespace());
// Assert.assertEquals(stjob.preferedPrefix(), job.getPrefix());
}
Also used : JobType(org.apache.xmpbox.type.JobType) XMPMetadata(org.apache.xmpbox.XMPMetadata) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StructuredType(org.apache.xmpbox.type.StructuredType) Test(org.junit.Test)

Example 2 with StructuredType

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

the class PDFAIdentificationValidation method validatePDFAIdentifer.

/**
 * Check if PDFAIdentification is valid
 *
 * @param metadata the XMP MetaData.
 * @return the list of validation errors.
 * @throws ValidationException
 */
public List<ValidationError> validatePDFAIdentifer(XMPMetadata metadata) throws ValidationException {
    List<ValidationError> ve = new ArrayList<>();
    PDFAIdentificationSchema id = metadata.getPDFIdentificationSchema();
    if (id == null) {
        ve.add(new ValidationError(ERROR_METADATA_PDFA_ID_MISSING, "PDF/A identification schema " + PDFAIdentificationSchema.class.getAnnotation(StructuredType.class).namespace() + " is missing"));
        return ve;
    }
    // According to the PDF/A specification, the prefix must be pdfaid for this schema.
    StructuredType stBasic = XMPBasicSchema.class.getAnnotation(StructuredType.class);
    StructuredType stPdfaIdent = PDFAIdentificationSchema.class.getAnnotation(StructuredType.class);
    if (!id.getPrefix().equals(stPdfaIdent.preferedPrefix())) {
        if (metadata.getSchema(stPdfaIdent.preferedPrefix(), stBasic.namespace()) == null) {
            ve.add(unexpectedPrefixFoundError(id.getPrefix(), stPdfaIdent.preferedPrefix(), PDFAIdentificationSchema.class.getName()));
        } else {
            id = (PDFAIdentificationSchema) metadata.getSchema(stPdfaIdent.preferedPrefix(), stPdfaIdent.namespace());
        }
    }
    checkConformanceLevel(ve, id.getConformance());
    checkPartNumber(ve, id.getPart() == null ? -1 : id.getPart());
    return ve;
}
Also used : PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema) ArrayList(java.util.ArrayList) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) StructuredType(org.apache.xmpbox.type.StructuredType)

Example 3 with StructuredType

use of org.apache.xmpbox.type.StructuredType 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 4 with StructuredType

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

the class DoubleSameTypeSchemaTest method testDoubleDublinCore.

@Test
public void testDoubleDublinCore() throws Exception {
    DublinCoreSchema dc1 = metadata.createAndAddDublinCoreSchema();
    String ownPrefix = "test";
    DublinCoreSchema dc2 = new DublinCoreSchema(metadata, ownPrefix);
    metadata.addSchema(dc2);
    List<String> creators = new ArrayList<>();
    creators.add("creator1");
    creators.add("creator2");
    String format = "application/pdf";
    dc1.setFormat(format);
    dc1.addCreator(creators.get(0));
    dc1.addCreator(creators.get(1));
    String coverage = "Coverage";
    dc2.setCoverage(coverage);
    dc2.addCreator(creators.get(0));
    dc2.addCreator(creators.get(1));
    StructuredType stDub = DublinCoreSchema.class.getAnnotation(StructuredType.class);
    // We can't use metadata.getDublinCoreSchema() due to specification of
    // XMPBox (see Javadoc of XMPMetadata)
    Assert.assertEquals(format, ((DublinCoreSchema) metadata.getSchema(stDub.preferedPrefix(), stDub.namespace())).getFormat());
    Assert.assertEquals(coverage, ((DublinCoreSchema) metadata.getSchema(ownPrefix, stDub.namespace())).getCoverage());
    List<XMPSchema> schems = metadata.getAllSchemas();
    DublinCoreSchema dc;
    for (XMPSchema xmpSchema : schems) {
        dc = (DublinCoreSchema) xmpSchema;
        Assert.assertTrue(dc.getCreators().containsAll(creators));
    }
}
Also used : XMPSchema(org.apache.xmpbox.schema.XMPSchema) ArrayList(java.util.ArrayList) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) StructuredType(org.apache.xmpbox.type.StructuredType) Test(org.junit.Test)

Aggregations

StructuredType (org.apache.xmpbox.type.StructuredType)4 ArrayList (java.util.ArrayList)2 XMPSchema (org.apache.xmpbox.schema.XMPSchema)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1 XMPMetadata (org.apache.xmpbox.XMPMetadata)1 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)1 PDFAExtensionSchema (org.apache.xmpbox.schema.PDFAExtensionSchema)1 PDFAIdentificationSchema (org.apache.xmpbox.schema.PDFAIdentificationSchema)1 AbstractField (org.apache.xmpbox.type.AbstractField)1 AbstractStructuredType (org.apache.xmpbox.type.AbstractStructuredType)1 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)1 DefinedStructuredType (org.apache.xmpbox.type.DefinedStructuredType)1 JobType (org.apache.xmpbox.type.JobType)1 PDFASchemaType (org.apache.xmpbox.type.PDFASchemaType)1 TypeMapping (org.apache.xmpbox.type.TypeMapping)1