Search in sources :

Example 6 with XMPSchema

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 ?
            }
        }
    }
}
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 7 with XMPSchema

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");
}
Also used : XMPSchema(org.apache.xmpbox.schema.XMPSchema) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 8 with XMPSchema

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));
    }
}
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)

Example 9 with XMPSchema

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 !"));
}
Also used : XMPSchema(org.apache.xmpbox.schema.XMPSchema) Before(org.junit.Before)

Example 10 with XMPSchema

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;
}
Also used : XMPSchema(org.apache.xmpbox.schema.XMPSchema)

Aggregations

XMPSchema (org.apache.xmpbox.schema.XMPSchema)11 PropertyType (org.apache.xmpbox.type.PropertyType)3 Test (org.junit.Test)3 ComplexPropertyContainer (org.apache.xmpbox.type.ComplexPropertyContainer)2 StructuredType (org.apache.xmpbox.type.StructuredType)2 TypeMapping (org.apache.xmpbox.type.TypeMapping)2 Element (org.w3c.dom.Element)2 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 ValidationException (org.apache.pdfbox.preflight.exception.ValidationException)1 XMPMetadata (org.apache.xmpbox.XMPMetadata)1 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)1 PDFAExtensionSchema (org.apache.xmpbox.schema.PDFAExtensionSchema)1 XMPSchemaFactory (org.apache.xmpbox.schema.XMPSchemaFactory)1 AbstractField (org.apache.xmpbox.type.AbstractField)1 AbstractSimpleProperty (org.apache.xmpbox.type.AbstractSimpleProperty)1 AbstractStructuredType (org.apache.xmpbox.type.AbstractStructuredType)1 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)1