|
28 | 28 | import java.util.List; |
29 | 29 |
|
30 | 30 | import org.apache.xmpbox.XMPMetadata; |
| 31 | +import org.apache.xmpbox.schema.AdobePDFSchema; |
31 | 32 | import org.apache.xmpbox.schema.DublinCoreSchema; |
32 | 33 | import org.apache.xmpbox.schema.PDFAIdentificationSchema; |
33 | 34 | import org.apache.xmpbox.schema.PhotoshopSchema; |
@@ -555,4 +556,91 @@ void testLenientBagSeqMixup() throws XmpParsingException |
555 | 556 | assertEquals("Important subject", subjects.get(0)); |
556 | 557 | assertEquals("Unimportant subject", subjects.get(1)); |
557 | 558 | } |
| 559 | + |
| 560 | + @Test |
| 561 | + void testBadType() throws XmpParsingException |
| 562 | + { |
| 563 | + String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + |
| 564 | + "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>\n" + |
| 565 | + "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" + |
| 566 | + " xmlns:iX=\"http://ns.adobe.com/iX/1.0/\">\n" + |
| 567 | + " <rdf:Description xmlns=\"http://ns.adobe.com/pdf/1.3/\"\n" + |
| 568 | + " xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\"\n" + |
| 569 | + " about=\"\"\n" + |
| 570 | + " pdf:Author=\"edocslib\"/>\n" + |
| 571 | + "</rdf:RDF>\n" + |
| 572 | + "<?xpacket end='r'?>"; |
| 573 | + XmpParsingException ex = assertThrows( |
| 574 | + XmpParsingException.class, |
| 575 | + () -> new DomXmpParser().parse(s.getBytes(StandardCharsets.UTF_8))); |
| 576 | + assertEquals("No type defined for {http://ns.adobe.com/pdf/1.3/}Author", ex.getMessage()); |
| 577 | + DomXmpParser xmpParser = new DomXmpParser(); |
| 578 | + xmpParser.setStrictParsing(false); |
| 579 | + XMPMetadata xmp = xmpParser.parse(s.getBytes(StandardCharsets.UTF_8)); |
| 580 | + AdobePDFSchema adobePDFSchema = xmp.getAdobePDFSchema(); |
| 581 | + TextType tt = (TextType) adobePDFSchema.getProperty("Author"); |
| 582 | + assertEquals("[Author=TextType:edocslib]", tt.toString()); |
| 583 | + } |
| 584 | + |
| 585 | + @Test |
| 586 | + void testBadLocalName() throws XmpParsingException |
| 587 | + { |
| 588 | + String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + |
| 589 | + "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?><?adobe-xap-filters esc=\"CR\"?>\n" + |
| 590 | + "<x:xapmeta xmlns:x=\"adobe:ns:meta/\">\n" + |
| 591 | + " <rdf:RDF xmlns:iX=\"http://ns.adobe.com/iX/1.0/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" + |
| 592 | + " </rdf:RDF>\n" + |
| 593 | + "</x:xapmeta><?xpacket end='w'?>"; |
| 594 | + XmpParsingException ex = assertThrows( |
| 595 | + XmpParsingException.class, |
| 596 | + () -> new DomXmpParser().parse(s.getBytes(StandardCharsets.UTF_8))); |
| 597 | + assertEquals("Expecting local name 'xmpmeta' and found 'xapmeta'", ex.getMessage()); |
| 598 | + } |
| 599 | + |
| 600 | + @Test |
| 601 | + void testBadXPacketEnd1() throws XmpParsingException |
| 602 | + { |
| 603 | + String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + |
| 604 | + "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\" ?><x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n" + |
| 605 | + " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" + |
| 606 | + " <rdf:Description xmlns:dc=\"http://purl.org/dc/elements/1.1/\" rdf:about=\"\">\n" + |
| 607 | + " <dc:format>application/pdf</dc:format>\n" + |
| 608 | + " </rdf:Description>\n" + |
| 609 | + " </rdf:RDF>\n" + |
| 610 | + "</x:xmpmeta><?xpacket ends=\"w\" ?>"; |
| 611 | + XmpParsingException ex = assertThrows( |
| 612 | + XmpParsingException.class, |
| 613 | + () -> new DomXmpParser().parse(s.getBytes(StandardCharsets.UTF_8))); |
| 614 | + assertEquals("Excepted xpacket 'end' attribute (must be present and placed in first)", ex.getMessage()); |
| 615 | + } |
| 616 | + |
| 617 | + @Test |
| 618 | + void testBadXPacketEnd2() throws XmpParsingException |
| 619 | + { |
| 620 | + String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + |
| 621 | + "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\" ?><x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n" + |
| 622 | + " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" + |
| 623 | + " <rdf:Description xmlns:dc=\"http://purl.org/dc/elements/1.1/\" rdf:about=\"\">\n" + |
| 624 | + " <dc:format>application/pdf</dc:format>\n" + |
| 625 | + " </rdf:Description>\n" + |
| 626 | + " </rdf:RDF>\n" + |
| 627 | + "</x:xmpmeta><?xpacket end=\"k\" ?>"; |
| 628 | + XmpParsingException ex = assertThrows( |
| 629 | + XmpParsingException.class, |
| 630 | + () -> new DomXmpParser().parse(s.getBytes(StandardCharsets.UTF_8))); |
| 631 | + assertEquals("Excepted xpacket 'end' attribute with value 'r' or 'w' ", ex.getMessage()); |
| 632 | + } |
| 633 | + |
| 634 | + @Test |
| 635 | + void testNoRdfChildren() throws XmpParsingException |
| 636 | + { |
| 637 | + String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + |
| 638 | + "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\" ?>" + |
| 639 | + " <x:xmpmeta xmlns:x=\"adobe:ns:meta/\"/>\n" + |
| 640 | + "<?xpacket end=\"w\" ?>"; |
| 641 | + XmpParsingException ex = assertThrows( |
| 642 | + XmpParsingException.class, |
| 643 | + () -> new DomXmpParser().parse(s.getBytes(StandardCharsets.UTF_8))); |
| 644 | + assertEquals("No rdf description found in xmp", ex.getMessage()); |
| 645 | + } |
558 | 646 | } |
0 commit comments