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());
}
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;
}
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 ?
}
}
}
}
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));
}
}
Aggregations