use of org.apache.xmpbox.schema.XMPSchema 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.schema.XMPSchema in project pdfbox by apache.
the class XmpSerializer method serialize.
public void serialize(XMPMetadata metadata, OutputStream os, boolean withXpacket) throws TransformerException {
Document doc = documentBuilder.newDocument();
// fill document
Element rdf = createRdfElement(doc, metadata, withXpacket);
for (XMPSchema schema : metadata.getAllSchemas()) {
rdf.appendChild(serializeSchema(doc, schema));
}
// save
save(doc, os, "UTF-8");
}
use of org.apache.xmpbox.schema.XMPSchema 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));
}
}
use of org.apache.xmpbox.schema.XMPSchema in project pdfbox by apache.
the class XMPMetaDataTest method init.
@Before
public void init() throws Exception {
metadata = XMPMetadata.createXMPMetadata();
String tmpNsURI = "http://www.test.org/schem/";
tmp = new XMPSchema(metadata, tmpNsURI, "test");
tmp.addQualifiedBagValue("BagContainer", "Value1");
tmp.addQualifiedBagValue("BagContainer", "Value2");
tmp.addQualifiedBagValue("BagContainer", "Value3");
tmp.addUnqualifiedSequenceValue("SeqContainer", "Value1");
tmp.addUnqualifiedSequenceValue("SeqContainer", "Value2");
tmp.addUnqualifiedSequenceValue("SeqContainer", "Value3");
tmp.addProperty(metadata.getTypeMapping().createText(null, "test", "simpleProperty", "YEP"));
tmp2 = new XMPSchema(metadata, "http://www.space.org/schem/", "space", "space");
tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace1");
tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace2");
tmp2.addUnqualifiedSequenceValue("SeqSpContainer", "ValueSpace3");
metadata.addSchema(tmp);
metadata.addSchema(tmp2);
// Check schema getting
Assert.assertEquals(tmp, metadata.getSchema(tmpNsURI));
Assert.assertNull(metadata.getSchema("THIS URI NOT EXISTS !"));
}
use of org.apache.xmpbox.schema.XMPSchema in project pdfbox by apache.
the class XMPMetadata method createAndAddDefaultSchema.
/**
* Create and add an unspecified schema.
*
* @param nsPrefix The prefix wanted for the schema
* @param nsURI The namespace URI wanted for the schema
* @return The schema added in order to work on it
*/
public XMPSchema createAndAddDefaultSchema(String nsPrefix, String nsURI) {
XMPSchema schem = new XMPSchema(this, nsURI, nsPrefix);
schem.setAboutAsSimple("");
addSchema(schem);
return schem;
}
Aggregations