You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2025/12/27 16:22:18 UTC

svn commit: r1930894 - in pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox: type xml

Author: tilman
Date: Sat Dec 27 16:22:18 2025
New Revision: 1930894

Log:
PDFBOX-6133: introduce new parameter in getSpecifiedPropertyType for later changes, rename some variables for clarity - no changes in functionality in this commit

Modified:
   pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java
   pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java	Sat Dec 27 15:02:34 2025	(r1930893)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java	Sat Dec 27 16:22:18 2025	(r1930894)
@@ -244,13 +244,14 @@ public final class TypeMapping
 
     /**
      * Give type of specified property in specified schema (given by its namespaceURI)
-     * 
-     * @param qName
-     *            the property Qualified Name
+     *
+     * @param qName the property Qualified Name
+     * @param parentTypeName the type name of the parent, or null if not known. This is intended to
+     * help when the field name is in several types, e.g. "Values" in exif.
      * @return Property type declared for namespace specified, null if unknown
-     * @throws org.apache.xmpbox.type.BadFieldValueException if the name was not found.
+     * @throws org.apache.xmpbox.type.BadFieldValueException if the name of a type was not found.
      */
-    public PropertyType getSpecifiedPropertyType(QName qName) throws BadFieldValueException
+    public PropertyType getSpecifiedPropertyType(QName qName, String parentTypeName) throws BadFieldValueException
     {
         XMPSchemaFactory factory = getSchemaFactory(qName.getNamespaceURI());
         if (factory != null)

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java	Sat Dec 27 15:02:34 2025	(r1930893)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java	Sat Dec 27 16:22:18 2025	(r1930894)
@@ -292,7 +292,7 @@ public class DomXmpParser
                     throw new XmpParsingException(ErrorType.NoSchema,
                             "This namespace is not from a schema: " + namespace);
                 }
-                PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(schemaExtension));
+                PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(schemaExtension), null);
                 final XMPSchema schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, schemaExtension.getPrefix());
                 loadAttributes(schema, description);
                 ComplexPropertyContainer container = schema.getContainer();
@@ -369,7 +369,7 @@ public class DomXmpParser
         {
             ComplexPropertyContainer container = schema.getContainer();
             PropertyType type = checkPropertyDefinition(xmp,
-                    new QName(attr.getNamespaceURI(), attr.getLocalName(), attr.getPrefix()));
+                    new QName(attr.getNamespaceURI(), attr.getLocalName(), attr.getPrefix()), null);
 
             if (type == null)
             {
@@ -426,7 +426,7 @@ public class DomXmpParser
         {
             nsFinder.push(property);
             String namespace = property.getNamespaceURI();
-            PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property));
+            PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property), null);
             // create the container
             if (!tm.isDefinedSchema(namespace))
             {
@@ -662,7 +662,7 @@ public class DomXmpParser
             for (Element property : properties)
             {
                 String name = property.getLocalName();
-                PropertyType dtype = checkPropertyDefinition(xmp, DomHelper.getQName(property));
+                PropertyType dtype = checkPropertyDefinition(xmp, DomHelper.getQName(property), null);
                 PropertyType ptype = tm.getStructuredPropMapping(dtype.type()).getPropertyType(name);
                 // create property
                 createProperty(xmp, property, ptype, parentContainer);
@@ -775,7 +775,7 @@ public class DomXmpParser
         }
     }
 
-    private AbstractStructuredType parseLiDescription(XMPMetadata xmp, QName descriptor, Element liDescriptionElement)
+    private AbstractStructuredType parseLiDescription(XMPMetadata xmp, QName parentQName, Element liDescriptionElement)
             throws XmpParsingException
     {
         TypeMapping tm = xmp.getTypeMapping();
@@ -783,26 +783,26 @@ public class DomXmpParser
         if (liDescriptionElementChildren.isEmpty())
         {
             // The list is empty
-            return tryParseAttributesAsProperties(xmp, liDescriptionElement, tm, null, null, descriptor);
+            return tryParseAttributesAsProperties(xmp, liDescriptionElement, tm, null, null, parentQName);
         }
         Element firstLiDescriptionElementChild = liDescriptionElementChildren.get(0);
         if ("rdf:Description".equals(firstLiDescriptionElementChild.getTagName()))
         {
             // PDFBOX-6126: "<rdf:Description" as child of "<rdf:li"
-            return parseLiDescription(xmp, descriptor, firstLiDescriptionElementChild);
+            return parseLiDescription(xmp, parentQName, firstLiDescriptionElementChild);
         }
         // Instantiate abstract structured type with hint from first element
         nsFinder.push(firstLiDescriptionElementChild);
-        QName qName = DomHelper.getQName(firstLiDescriptionElementChild);
-        PropertyType ctype = checkPropertyDefinition(xmp, qName);
+        QName firstChildQName = DomHelper.getQName(firstLiDescriptionElementChild);
+        PropertyType ctype = checkPropertyDefinition(xmp, firstChildQName, parentQName.getLocalPart());
         if (ctype == null)
         {
             // PDFBOX-5649
             throw new XmpParsingException(ErrorType.NoType,
-                    "Property '" + qName.getLocalPart() + "' not defined in " + qName.getNamespaceURI());
+                    "Property '" + firstChildQName.getLocalPart() + "' not defined in " + firstChildQName.getNamespaceURI());
         }
         Types tt = ctype.type();
-        AbstractStructuredType ast = instanciateStructured(tm, tt, descriptor.getLocalPart(), firstLiDescriptionElementChild.getNamespaceURI());
+        AbstractStructuredType ast = instanciateStructured(tm, tt, parentQName.getLocalPart(), firstLiDescriptionElementChild.getNamespaceURI());
 
         ast.setNamespace(firstLiDescriptionElementChild.getNamespaceURI());
         ast.setPrefix(firstLiDescriptionElementChild.getPrefix());
@@ -836,7 +836,7 @@ public class DomXmpParser
                 List<Element> lis = DomHelper.getElementChildren(bagOrSeq);
                 for (Element element2 : lis)
                 {
-                    AbstractField ast2 = parseLiElement(xmp, descriptor, element2, type.type());
+                    AbstractField ast2 = parseLiElement(xmp, parentQName, element2, type.type());
                     if (ast2 != null)
                     {
                         array.addProperty(ast2);
@@ -878,7 +878,7 @@ public class DomXmpParser
             }
 
         }
-        ast = tryParseAttributesAsProperties(xmp, liDescriptionElement, tm, ast, pm, descriptor);
+        ast = tryParseAttributesAsProperties(xmp, liDescriptionElement, tm, ast, pm, parentQName);
         nsFinder.pop();
         return ast;
     }
@@ -1103,7 +1103,7 @@ public class DomXmpParser
         }
     }
 
-    private PropertyType checkPropertyDefinition(XMPMetadata xmp, QName qName) throws XmpParsingException
+    private PropertyType checkPropertyDefinition(XMPMetadata xmp, QName qName, String parentTypeName) throws XmpParsingException
     {
         TypeMapping tm = xmp.getTypeMapping();
         // test if namespace is set in xml
@@ -1121,7 +1121,7 @@ public class DomXmpParser
         }
         try
         {
-            return tm.getSpecifiedPropertyType(qName);
+            return tm.getSpecifiedPropertyType(qName, null);
         }
         catch (BadFieldValueException e)
         {
@@ -1180,7 +1180,7 @@ public class DomXmpParser
                     // like in parseLiDescription():
                     // Instantiate abstract structured type with hint from first element
                     QName attrQName = new QName(attr.getNamespaceURI(), attr.getLocalName(), attr.getPrefix());
-                    PropertyType ctype = checkPropertyDefinition(xmp, attrQName);
+                    PropertyType ctype = checkPropertyDefinition(xmp, attrQName, null);
                     // this is the type of the AbstractStructuredType, not of the element(s)
                     if (ctype == null)
                     {