@@ -192,6 +192,24 @@ public XMPMetadata parse(InputStream input) throws XmpParsingException
192192 // Now, parse the content of root
193193 Element rdfRdf = findDescriptionsParent (root );
194194 nsFinder .push (rdfRdf ); // PDFBOX-6099: push namespaces in rdf:RDF
195+
196+ // PDFBOX-6127: look for non standard namespaces (similar to PDFBOX-2378)
197+ if (!strictParsing )
198+ {
199+ NamedNodeMap nnm = rdfRdf .getAttributes ();
200+ if (nnm != null )
201+ {
202+ for (int i = 0 ; i < nnm .getLength (); i ++)
203+ {
204+ Attr attr = (Attr ) nnm .item (i );
205+ if (XMLConstants .XMLNS_ATTRIBUTE .equals (attr .getPrefix ()))
206+ {
207+ maybeAddNonStandardNamespace (xmp , attr );
208+ }
209+ }
210+ }
211+ }
212+
195213 List <Element > descriptions = DomHelper .getElementChildren (rdfRdf );
196214 for (Element description : descriptions )
197215 {
@@ -212,6 +230,23 @@ public XMPMetadata parse(InputStream input) throws XmpParsingException
212230 return xmp ;
213231 }
214232
233+ private void maybeAddNonStandardNamespace (XMPMetadata xmp , Attr attr )
234+ {
235+ // xmlns:prefix="namespace"
236+ TypeMapping tm = xmp .getTypeMapping ();
237+ String namespace = attr .getValue ();
238+ if (!XmpConstants .RDF_NAMESPACE .equals (namespace ) &&
239+ !tm .isStructuredTypeNamespace (namespace ) &&
240+ xmp .getSchema (namespace ) == null && tm .getSchemaFactory (namespace ) == null )
241+ {
242+ // PDFBOX-5128 / PDFBOX-6127: Add the schema on the fly if it can't be found
243+ // PDFBOX-5649: But only if the namespace isn't already known
244+ // because this adds a namespace without property descriptions
245+ // PDFBOX-6127: never rdf
246+ tm .addNewNameSpace (namespace , attr .getLocalName ());
247+ }
248+ }
249+
215250 private boolean isSchemaExtensionProperty (final Element element )
216251 {
217252 return element != null && "pdfaExtension" .equals (element .getPrefix ());
@@ -279,14 +314,9 @@ else if (attr.getPrefix() == null && XmpConstants.ABOUT_NAME.equals(attr.getLoca
279314 }
280315 else if (XMLConstants .XMLNS_ATTRIBUTE .equals (attr .getPrefix ()))
281316 {
282- String namespace = attr .getValue ();
283- if (!strictParsing && !tm .isStructuredTypeNamespace (namespace ) &&
284- xmp .getSchema (namespace ) == null && tm .getSchemaFactory (namespace ) == null )
317+ if (!strictParsing )
285318 {
286- // PDFBOX-5128: Add the schema on the fly if it can't be found
287- // PDFBOX-5649: But only if the namespace isn't already known
288- // because this adds a namespace without property descriptions
289- tm .addNewNameSpace (namespace , attr .getLocalName ());
319+ maybeAddNonStandardNamespace (xmp , attr );
290320 }
291321 }
292322 else
0 commit comments