|
21 | 21 |
|
22 | 22 | package org.apache.xmpbox.xml; |
23 | 23 |
|
| 24 | +import java.io.ByteArrayOutputStream; |
24 | 25 | import java.io.IOException; |
25 | 26 | import java.io.InputStream; |
26 | 27 | import java.nio.charset.StandardCharsets; |
27 | 28 | import java.util.Calendar; |
28 | 29 | import java.util.List; |
| 30 | +import javax.xml.transform.TransformerException; |
29 | 31 |
|
30 | 32 | import org.apache.xmpbox.XMPMetadata; |
31 | 33 | import org.apache.xmpbox.schema.AdobePDFSchema; |
@@ -788,4 +790,74 @@ void testBadSchema() throws XmpParsingException |
788 | 790 | () -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8))); |
789 | 791 | assertEquals("This namespace is not from a schema: http://ns.adobe.com/xap/1.0/sType/Job#", ex.getMessage()); |
790 | 792 | } |
| 793 | + |
| 794 | + @Test |
| 795 | + void testPDFBOX6126() throws XmpParsingException, BadFieldValueException, TransformerException |
| 796 | + { |
| 797 | + // XMP originally from PDFBOX-4325, had this exception: |
| 798 | + // Cannot find a definition for the namespace http://www.w3.org/1999/02/22-rdf-syntax-ns#, property: rdf:Description |
| 799 | + // Cause: "<rdf:Description" as child of <rdf:li . |
| 800 | + String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + |
| 801 | + "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n" + |
| 802 | + "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"\n" + |
| 803 | + " x:xmptk=\"Adobe XMP Core 5.1.0-jc003\">\n" + |
| 804 | + " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" + |
| 805 | + " <rdf:Description xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" + |
| 806 | + " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"\n" + |
| 807 | + " xmlns:pdfaExtension=\"http://www.aiim.org/pdfa/ns/extension/\"\n" + |
| 808 | + " xmlns:pdfaProperty=\"http://www.aiim.org/pdfa/ns/property#\"\n" + |
| 809 | + " xmlns:pdfaSchema=\"http://www.aiim.org/pdfa/ns/schema#\"\n" + |
| 810 | + " xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\"\n" + |
| 811 | + " xmlns:pdfuaid=\"http://www.aiim.org/pdfua/ns/id/\"\n" + |
| 812 | + " xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"\n" + |
| 813 | + " dc:format=\"application/pdf\"\n" + |
| 814 | + " pdf:Producer=\"iText® 5.5.13 ©2000-2018 iText Group NV (AGPL-version)\"\n" + |
| 815 | + " pdfaid:conformance=\"B\"\n" + |
| 816 | + " pdfaid:part=\"1\"\n" + |
| 817 | + " rdf:about=\"\"\n" + |
| 818 | + " xmp:CreateDate=\"2018-09-24T09:00:57+02:00\"\n" + |
| 819 | + " xmp:ModifyDate=\"2018-09-24T09:00:57+02:00\">\n" + |
| 820 | + " <pdfaExtension:schemas>\n" + |
| 821 | + " <rdf:Bag>\n" + |
| 822 | + " <rdf:li rdf:parseType=\"Resource\">\n" + |
| 823 | + " <rdf:Description pdfaSchema:namespaceURI=\"http://www.aiim.org/pdfua/ns/id/\"\n" + |
| 824 | + " pdfaSchema:prefix=\"pdfuaid\"\n" + |
| 825 | + " pdfaSchema:schema=\"PDF/UA identification schema\">\n" + |
| 826 | + " <pdfaSchema:property>\n" + |
| 827 | + " <rdf:Seq>\n" + |
| 828 | + " <rdf:li pdfaProperty:category=\"internal\"\n" + |
| 829 | + " pdfaProperty:description=\"PDF/UA version identifier\"\n" + |
| 830 | + " pdfaProperty:name=\"part\"\n" + |
| 831 | + " pdfaProperty:valueType=\"Integer\"/>\n" + |
| 832 | + " <rdf:li pdfaProperty:category=\"internal\"\n" + |
| 833 | + " pdfaProperty:description=\"PDF/UA amendment identifier\"\n" + |
| 834 | + " pdfaProperty:name=\"amd\"\n" + |
| 835 | + " pdfaProperty:valueType=\"Text\"/>\n" + |
| 836 | + " <rdf:li pdfaProperty:category=\"internal\"\n" + |
| 837 | + " pdfaProperty:description=\"PDF/UA corrigenda identifier\"\n" + |
| 838 | + " pdfaProperty:name=\"corr\"\n" + |
| 839 | + " pdfaProperty:valueType=\"Text\"/>\n" + |
| 840 | + " </rdf:Seq>\n" + |
| 841 | + " </pdfaSchema:property>\n" + |
| 842 | + " </rdf:Description>\n" + |
| 843 | + " </rdf:li>\n" + |
| 844 | + " </rdf:Bag>\n" + |
| 845 | + " </pdfaExtension:schemas>\n" + |
| 846 | + " <pdfuaid:part>1</pdfuaid:part>\n" + |
| 847 | + " </rdf:Description>\n" + |
| 848 | + " </rdf:RDF>\n" + |
| 849 | + "</x:xmpmeta><?xpacket end=\"w\"?>"; |
| 850 | + DomXmpParser xmpParser1 = new DomXmpParser(); |
| 851 | + XMPMetadata xmp1 = xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8)); |
| 852 | + XMPSchema uaSchema1 = xmp1.getSchema("http://www.aiim.org/pdfua/ns/id/"); |
| 853 | + assertEquals(1, uaSchema1.getIntegerPropertyValueAsSimple("part")); |
| 854 | + XmpSerializer serializer = new XmpSerializer(); |
| 855 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 856 | + // make sure that nothing is lost in serialization |
| 857 | + serializer.serialize(xmp1, baos, true); |
| 858 | + DomXmpParser xmpParser2 = new DomXmpParser(); |
| 859 | + XMPMetadata xmp2 = xmpParser2.parse(baos.toByteArray()); |
| 860 | + XMPSchema uaSchema2 = xmp2.getSchema("http://www.aiim.org/pdfua/ns/id/"); |
| 861 | + assertEquals(1, uaSchema2.getIntegerPropertyValueAsSimple("part")); |
| 862 | + } |
791 | 863 | } |
0 commit comments