Skip to content

Commit 8e26bd6

Browse files
committed
PDFBOX-6138: push/pop root
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930995 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3f5e792 commit 8e26bd6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public XMPMetadata parse(InputStream input) throws XmpParsingException
202202
}
203203
// xpacket is OK and there are no more nodes
204204
// Now, parse the content of root
205+
nsFinder.push(root); // PDFBOX-6138: push namespaces in root
205206
Element rdfRdf = findDescriptionsParent(root);
206207
nsFinder.push(rdfRdf); // PDFBOX-6099: push namespaces in rdf:RDF
207208

@@ -234,6 +235,7 @@ public XMPMetadata parse(InputStream input) throws XmpParsingException
234235
parseDescriptionRoot(xmp, description);
235236
}
236237

238+
nsFinder.pop();
237239
nsFinder.pop();
238240

239241
return xmp;

xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,4 +1688,48 @@ void testPDFBox6136() throws XmpParsingException
16881688
assertEquals("B", xmp.getPDFAIdentificationSchema().getConformance());
16891689
assertEquals((Integer) 1, xmp.getPDFAIdentificationSchema().getPart());
16901690
}
1691+
1692+
/**
1693+
* PDFBOX-6138: namespaces are in the root, instead of in rdf:RDF or deeper.
1694+
*
1695+
* @throws XmpParsingException
1696+
*/
1697+
@Test
1698+
void testNamespaceInRoot() throws XmpParsingException
1699+
{
1700+
String s =
1701+
"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n" +
1702+
"<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>" +
1703+
"<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" xmlns:pdfaExtension=\"http://www.aiim.org/pdfa/ns/extension/\" " +
1704+
"xmlns:pdfaProperty=\"http://www.aiim.org/pdfa/ns/property#\" xmlns:pdfaSchema=\"http://www.aiim.org/pdfa/ns/schema#\" " +
1705+
"xmlns:pdfuaid=\"http://www.aiim.org/pdfua/ns/id/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" " +
1706+
"x:xmptk=\"Adobe XMP Core 5.6-c015 91.163280, 2018/06/22-11:31:03 \">\n" +
1707+
" <rdf:RDF>\n" +
1708+
" <rdf:Description rdf:about=\"\">\n" +
1709+
" <pdfaExtension:schemas>\n" +
1710+
" <rdf:Bag>\n" +
1711+
" <rdf:li rdf:parseType=\"Resource\">\n" +
1712+
" <pdfaSchema:schema>PDF/UA Universal Accessibility Schema</pdfaSchema:schema>\n" +
1713+
" <pdfaSchema:namespaceURI>http://www.aiim.org/pdfua/ns/id/</pdfaSchema:namespaceURI>\n" +
1714+
" <pdfaSchema:prefix>pdfuaid</pdfaSchema:prefix>\n" +
1715+
" <pdfaSchema:property>\n" +
1716+
" <rdf:Seq>\n" +
1717+
" <rdf:li rdf:parseType=\"Resource\">\n" +
1718+
" <pdfaProperty:name>part</pdfaProperty:name>\n" +
1719+
" <pdfaProperty:valueType>Integer</pdfaProperty:valueType>\n" +
1720+
" <pdfaProperty:category>internal</pdfaProperty:category>\n" +
1721+
" <pdfaProperty:description>Indicates, which part of ISO 14289 standard is followed</pdfaProperty:description>\n" +
1722+
" </rdf:li>\n" +
1723+
" </rdf:Seq>\n" +
1724+
" </pdfaSchema:property>\n" +
1725+
" </rdf:li>\n" +
1726+
" </rdf:Bag>\n" +
1727+
" </pdfaExtension:schemas>\n" +
1728+
" <pdfuaid:part>1</pdfuaid:part>\n" +
1729+
" </rdf:Description>\n" +
1730+
" </rdf:RDF>\n" +
1731+
"</x:xmpmeta><?xpacket end='w'?>";
1732+
final DomXmpParser xmpParser = new DomXmpParser();
1733+
XMPMetadata xmp = xmpParser.parse(s.getBytes(StandardCharsets.UTF_8));
1734+
}
16911735
}

0 commit comments

Comments
 (0)