Search in sources :

Example 16 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class XMPMetaDataTest method testPDFBOX3257.

/**
 * Test whether the bug reported in PDFBOX-3257 and PDFBOX-3258 has been fixed: setting
 * CreateDate twice must not insert two elements, and fixing this must not interfere with the
 * handling of lists.
 *
 * @throws IOException
 * @throws XmpParsingException
 */
@Test
public void testPDFBOX3257() throws IOException, XmpParsingException {
    // taken from file test-landscape2.pdf
    String xmpmeta = "<?xpacket id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n" + "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.0-c316 44.253921, Sun Oct 01 2006 17:14:39\">\n" + "   <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" + "      <rdf:Description rdf:about=\"\"\n" + "            xmlns:xap=\"http://ns.adobe.com/xap/1.0/\">\n" + "         <xap:CreatorTool>Acrobat PDFMaker 8.1 for Word</xap:CreatorTool>\n" + "         <xap:ModifyDate>2008-11-12T15:29:43+01:00</xap:ModifyDate>\n" + "         <xap:CreateDate>2008-11-12T15:29:40+01:00</xap:CreateDate>\n" + "         <xap:MetadataDate>2008-11-12T15:29:43+01:00</xap:MetadataDate>\n" + "      </rdf:Description>\n" + "      <rdf:Description rdf:about=\"\"\n" + "            xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">\n" + "         <pdf:Producer>Acrobat Distiller 8.1.0 (Windows)</pdf:Producer>\n" + "      </rdf:Description>\n" + "      <rdf:Description rdf:about=\"\"\n" + "            xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n" + "         <dc:format>application/pdf</dc:format>\n" + "         <dc:creator>\n" + "            <rdf:Seq>\n" + "               <rdf:li>R002325</rdf:li>\n" + "            </rdf:Seq>\n" + "         </dc:creator>\n" + "         <dc:subject>\n" + "            <rdf:Bag>\n" + "               <rdf:li>one</rdf:li>\n" + "               <rdf:li>two</rdf:li>\n" + "               <rdf:li>three</rdf:li>\n" + "               <rdf:li>four</rdf:li>\n" + "            </rdf:Bag>\n" + "         </dc:subject>\n" + "         <dc:title>\n" + "            <rdf:Alt>\n" + "               <rdf:li xml:lang=\"x-default\"> </rdf:li>\n" + "            </rdf:Alt>\n" + "         </dc:title>\n" + "      </rdf:Description>\n" + "      <rdf:Description rdf:about=\"\"\n" + "            xmlns:xapMM=\"http://ns.adobe.com/xap/1.0/mm/\">\n" + "         <xapMM:DocumentID>uuid:31ae92cf-9a27-45e0-9371-0d2741e25919</xapMM:DocumentID>\n" + "         <xapMM:InstanceID>uuid:2c7eb5da-9210-4666-8cef-e02ef6631c5e</xapMM:InstanceID>\n" + "      </rdf:Description>\n" + "   </rdf:RDF>\n" + "</x:xmpmeta>\n" + "<?xpacket end=\"w\"?>";
    DomXmpParser xmpParser = new DomXmpParser();
    xmpParser.setStrictParsing(false);
    // IOUtils.copy(meta.createInputStream(),System.out);
    XMPMetadata xmp = xmpParser.parse(xmpmeta.getBytes());
    XMPBasicSchema basicSchema = xmp.getXMPBasicSchema();
    Calendar createDate1 = basicSchema.getCreateDate();
    basicSchema.setCreateDate(new GregorianCalendar());
    Calendar createDate2 = basicSchema.getCreateDate();
    Assert.assertFalse("CreateDate has not been set", createDate1.equals(createDate2));
    // check that bugfix does not interfere with lists of properties with same name
    DublinCoreSchema dublinCoreSchema = xmp.getDublinCoreSchema();
    List<String> subjects = dublinCoreSchema.getSubjects();
    Assert.assertEquals(4, subjects.size());
}
Also used : DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) GregorianCalendar(java.util.GregorianCalendar) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) Test(org.junit.Test)

Example 17 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class DeserializationTest method testWihtAttributesAsProperties.

@Test
public void testWihtAttributesAsProperties() throws Exception {
    InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/attr_as_props.xml");
    DomXmpParser xdb = new DomXmpParser();
    XMPMetadata meta = xdb.parse(fis);
    AdobePDFSchema pdf = meta.getAdobePDFSchema();
    Assert.assertEquals("GPL Ghostscript 8.64", pdf.getProducer());
    DublinCoreSchema dc = meta.getDublinCoreSchema();
    Assert.assertEquals("application/pdf", dc.getFormat());
    XMPBasicSchema basic = meta.getXMPBasicSchema();
    Assert.assertNotNull(basic.getCreateDate());
}
Also used : XMPMetadata(org.apache.xmpbox.XMPMetadata) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) AdobePDFSchema(org.apache.xmpbox.schema.AdobePDFSchema) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) Test(org.junit.Test)

Example 18 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class DeserializationTest method testSpaceTextValues.

@Test
public void testSpaceTextValues() throws Exception {
    // check values with spaces at start or end
    // in this case, the value should not be trimmed
    InputStream is = DomXmpParser.class.getResourceAsStream("/validxmp/only_space_fields.xmp");
    DomXmpParser xdb = new DomXmpParser();
    XMPMetadata meta = xdb.parse(is);
    // check producer
    Assert.assertEquals(" ", meta.getAdobePDFSchema().getProducer());
    // check creator tool
    Assert.assertEquals("Canon ", meta.getXMPBasicSchema().getCreatorTool());
}
Also used : XMPMetadata(org.apache.xmpbox.XMPMetadata) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) Test(org.junit.Test)

Example 19 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class DeserializationTest method testWithNoXPacketStart.

@Test
public void testWithNoXPacketStart() throws Exception {
    InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacket.xml");
    DomXmpParser xdb = new DomXmpParser();
    try {
        xdb.parse(fis);
        Assert.fail("Should fail during parse");
    } catch (XmpParsingException e) {
        Assert.assertEquals(ErrorType.XpacketBadStart, e.getErrorType());
    }
}
Also used : XmpParsingException(org.apache.xmpbox.xml.XmpParsingException) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) Test(org.junit.Test)

Example 20 with DomXmpParser

use of org.apache.xmpbox.xml.DomXmpParser in project pdfbox by apache.

the class DeserializationTest method testWithTwoRDFElement.

@Test
public void testWithTwoRDFElement() throws Exception {
    InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/tworoot.xml");
    DomXmpParser xdb = new DomXmpParser();
    try {
        xdb.parse(fis);
        Assert.fail("Should fail during parse");
    } catch (XmpParsingException e) {
        Assert.assertEquals(ErrorType.Format, e.getErrorType());
    }
}
Also used : XmpParsingException(org.apache.xmpbox.xml.XmpParsingException) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) Test(org.junit.Test)

Aggregations

DomXmpParser (org.apache.xmpbox.xml.DomXmpParser)28 InputStream (java.io.InputStream)21 Test (org.junit.Test)21 XmpParsingException (org.apache.xmpbox.xml.XmpParsingException)12 XMPMetadata (org.apache.xmpbox.XMPMetadata)11 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)6 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)3 PDMetadata (org.apache.pdfbox.pdmodel.common.PDMetadata)3 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)3 XMPBasicSchema (org.apache.xmpbox.schema.XMPBasicSchema)3 File (java.io.File)2 PDDocumentCatalog (org.apache.pdfbox.pdmodel.PDDocumentCatalog)2 AdobePDFSchema (org.apache.xmpbox.schema.AdobePDFSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 PDDocumentInformation (org.apache.pdfbox.pdmodel.PDDocumentInformation)1 PreflightDocument (org.apache.pdfbox.preflight.PreflightDocument)1