3535import org .apache .xmpbox .schema .ExifSchema ;
3636import org .apache .xmpbox .schema .PDFAIdentificationSchema ;
3737import org .apache .xmpbox .schema .PhotoshopSchema ;
38+ import org .apache .xmpbox .schema .TiffSchema ;
39+ import org .apache .xmpbox .schema .XMPBasicSchema ;
3840import org .apache .xmpbox .schema .XMPMediaManagementSchema ;
3941import org .apache .xmpbox .schema .XMPPageTextSchema ;
4042import org .apache .xmpbox .schema .XMPSchema ;
@@ -661,6 +663,10 @@ void testBadLocalName() throws XmpParsingException
661663 XmpParsingException .class ,
662664 () -> xmpParser .parse (s .getBytes (StandardCharsets .UTF_8 )));
663665 assertEquals ("Expecting local name 'xmpmeta' and found 'xapmeta'" , ex .getMessage ());
666+ DomXmpParser xmpParser2 = new DomXmpParser ();
667+ xmpParser2 .setStrictParsing (false );
668+ XMPMetadata xmp2 = xmpParser2 .parse (s .getBytes (StandardCharsets .UTF_8 ));
669+ assertEquals (0 , xmp2 .getAllSchemas ().size ());
664670 }
665671
666672 @ Test
@@ -1259,4 +1265,91 @@ void testLenientPdfaExtension() throws XmpParsingException
12591265 assertEquals ("uuid:0b306144-6a43-dcbd-6b3e-c6b6b1df873d" , xmpMediaManagementSchema .getInstanceID ());
12601266 assertEquals ("uuid:0b306144-6a43-dcbd-6b3e-c6b6b1df873d" , xmpMediaManagementSchema .getDocumentID ());
12611267 }
1262- }
1268+
1269+ @ Test
1270+ void testNoProcessingInstruction () throws XmpParsingException , TransformerException
1271+ {
1272+ // From file 000163.pdf
1273+ // Coastal Services Magazine Volume 11_6 November/December
1274+ String s = "<x:xmpmeta xmlns:x=\" adobe:ns:meta/\" x:xmptk=\" Adobe XMP Core 4.1-c037 46.282696, Mon Apr 02 2007 18:36:42 \" >\n " +
1275+ " <rdf:RDF xmlns:rdf=\" http://www.w3.org/1999/02/22-rdf-syntax-ns#\" >\n " +
1276+ " <rdf:Description rdf:about=\" \" \n " +
1277+ " xmlns:xapMM=\" http://ns.adobe.com/xap/1.0/mm/\" \n " +
1278+ " xmlns:stRef=\" http://ns.adobe.com/xap/1.0/sType/ResourceRef#\" \n " +
1279+ " xmlns:tiff=\" http://ns.adobe.com/tiff/1.0/\" \n " +
1280+ " xmlns:xap=\" http://ns.adobe.com/xap/1.0/\" \n " +
1281+ " xmlns:exif=\" http://ns.adobe.com/exif/1.0/\" \n " +
1282+ " xmlns:dc=\" http://purl.org/dc/elements/1.1/\" \n " +
1283+ " xmlns:photoshop=\" http://ns.adobe.com/photoshop/1.0/\" \n " +
1284+ " xapMM:DocumentID=\" uuid:F1FEDA1D7D03DA11B0F6E4B4E63B0143\" \n " +
1285+ " xapMM:InstanceID=\" uuid:7A28FBF56920DA11B4BBB356C0A5C72B\" \n " +
1286+ " tiff:Orientation=\" 1\" \n " +
1287+ " tiff:XResolution=\" 3050000/10000\" \n " +
1288+ " tiff:YResolution=\" 3050000/10000\" \n " +
1289+ " tiff:ResolutionUnit=\" 2\" \n " +
1290+ " tiff:NativeDigest=\" 123456\" \n " +
1291+ " xap:ModifyDate=\" 2005-09-08T09:13:10-04:00\" \n " +
1292+ " xap:CreatorTool=\" Adobe Photoshop CS2 Windows\" \n " +
1293+ " xap:CreateDate=\" 2005-08-02T13:47:24-04:00\" \n " +
1294+ " xap:MetadataDate=\" 2005-09-08T09:13:10-04:00\" \n " +
1295+ " exif:ColorSpace=\" -1\" \n " +
1296+ " exif:PixelXDimension=\" 1525\" \n " +
1297+ " exif:PixelYDimension=\" 387\" \n " +
1298+ " exif:NativeDigest=\" 12345678\" \n " +
1299+ " dc:format=\" image/tiff\" \n " +
1300+ " photoshop:ColorMode=\" 4\" \n " +
1301+ " photoshop:ICCProfile=\" U.S. Web Coated (SWOP) v2\" \n " +
1302+ " photoshop:History=\" \" >\n " +
1303+ " <xapMM:DerivedFrom\n " +
1304+ " stRef:instanceID=\" adobe:docid:photoshop:28ff3dc5-4801-11d8-85d1-bb49d244e2ef\" \n " +
1305+ " stRef:documentID=\" adobe:docid:photoshop:28ff3dc5-4801-11d8-85d1-bb49d244e2ef\" />\n " +
1306+ " </rdf:Description>\n " +
1307+ " </rdf:RDF>\n " +
1308+ "</x:xmpmeta>" ;
1309+ final DomXmpParser xmpParser1 = new DomXmpParser ();
1310+ XmpParsingException ex = assertThrows (XmpParsingException .class ,
1311+ () -> xmpParser1 .parse (s .getBytes (StandardCharsets .UTF_8 )));
1312+ assertEquals ("xmp should start with a processing instruction" , ex .getMessage ());
1313+ DomXmpParser xmpParser2 = new DomXmpParser ();
1314+ xmpParser2 .setStrictParsing (false );
1315+ XMPMetadata xmp2 = xmpParser2 .parse (s .getBytes (StandardCharsets .UTF_8 ));
1316+ DublinCoreSchema dublinCoreSchema = xmp2 .getDublinCoreSchema ();
1317+ assertEquals ("image/tiff" , dublinCoreSchema .getFormat ());
1318+ XMPMediaManagementSchema xmpMediaManagementSchema = xmp2 .getXMPMediaManagementSchema ();
1319+ assertEquals ("uuid:F1FEDA1D7D03DA11B0F6E4B4E63B0143" , xmpMediaManagementSchema .getDocumentID ());
1320+ TiffSchema tiffSchema = (TiffSchema ) xmp2 .getSchema (TiffSchema .class );
1321+ assertEquals ("[Orientation=IntegerType:1]" , tiffSchema .getProperty (TiffSchema .ORIENTATION ).toString ());
1322+ PhotoshopSchema photoshopSchema = xmp2 .getPhotoshopSchema ();
1323+ assertEquals ((Integer ) 4 , photoshopSchema .getColorMode ());
1324+ ExifSchema exifSchema = (ExifSchema ) xmp2 .getSchema (ExifSchema .class );
1325+ assertEquals ("[PixelXDimension=IntegerType:1525]" , exifSchema .getProperty (ExifSchema .PIXEL_X_DIMENSION ).toString ());
1326+ XMPBasicSchema xmpBasicSchema = xmp2 .getXMPBasicSchema ();
1327+ assertEquals ("Adobe Photoshop CS2 Windows" , xmpBasicSchema .getCreatorTool ());
1328+ XmpSerializer serializer = new XmpSerializer ();
1329+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
1330+ serializer .serialize (xmp2 , baos , true );
1331+ // check that there are no isolated properties
1332+ // (Happened before the change at the bottom of loadAttributes())
1333+ String s2 = baos .toString (StandardCharsets .UTF_8 );
1334+ assertFalse (s2 .contains (" ColorMode=" ));
1335+ assertFalse (s2 .contains (" CreateDate=" ));
1336+ assertFalse (s2 .contains (" CreatorTool=" ));
1337+ assertFalse (s2 .contains (" DocumentID=" ));
1338+ // now make sure that parsing again still brings the same data
1339+ DomXmpParser xmpParser3 = new DomXmpParser ();
1340+ xmpParser3 .setStrictParsing (false );
1341+ XMPMetadata xmp3 = xmpParser3 .parse (baos .toByteArray ());
1342+ DublinCoreSchema dublinCoreSchema3 = xmp3 .getDublinCoreSchema ();
1343+ assertEquals ("image/tiff" , dublinCoreSchema3 .getFormat ());
1344+ XMPMediaManagementSchema xmpMediaManagementSchema3 = xmp3 .getXMPMediaManagementSchema ();
1345+ assertEquals ("uuid:F1FEDA1D7D03DA11B0F6E4B4E63B0143" , xmpMediaManagementSchema3 .getDocumentID ());
1346+ TiffSchema tiffSchema3 = (TiffSchema ) xmp3 .getSchema (TiffSchema .class );
1347+ assertEquals ("[Orientation=IntegerType:1]" , tiffSchema3 .getProperty (TiffSchema .ORIENTATION ).toString ());
1348+ PhotoshopSchema photoshopSchema3 = xmp3 .getPhotoshopSchema ();
1349+ assertEquals ((Integer ) 4 , photoshopSchema3 .getColorMode ());
1350+ ExifSchema exifSchema3 = (ExifSchema ) xmp3 .getSchema (ExifSchema .class );
1351+ assertEquals ("[PixelXDimension=IntegerType:1525]" , exifSchema3 .getProperty (ExifSchema .PIXEL_X_DIMENSION ).toString ());
1352+ XMPBasicSchema xmpBasicSchema3 = xmp3 .getXMPBasicSchema ();
1353+ assertEquals ("Adobe Photoshop CS2 Windows" , xmpBasicSchema3 .getCreatorTool ());
1354+ }
1355+ }
0 commit comments