Skip to content

Commit ecc4e9a

Browse files
committed
PDFBOX-6133: introduce new parameter in getSpecifiedPropertyType for later changes, rename some variables for clarity - no changes in functionality in this commit
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930894 13f79535-47bb-0310-9956-ffa450edef68
1 parent 94e9cbe commit ecc4e9a

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

xmpbox/src/main/java/org/apache/xmpbox/type/TypeMapping.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,14 @@ public boolean isDefinedNamespace(String namespace)
244244

245245
/**
246246
* Give type of specified property in specified schema (given by its namespaceURI)
247-
*
248-
* @param qName
249-
* the property Qualified Name
247+
*
248+
* @param qName the property Qualified Name
249+
* @param parentTypeName the type name of the parent, or null if not known. This is intended to
250+
* help when the field name is in several types, e.g. "Values" in exif.
250251
* @return Property type declared for namespace specified, null if unknown
251-
* @throws org.apache.xmpbox.type.BadFieldValueException if the name was not found.
252+
* @throws org.apache.xmpbox.type.BadFieldValueException if the name of a type was not found.
252253
*/
253-
public PropertyType getSpecifiedPropertyType(QName qName) throws BadFieldValueException
254+
public PropertyType getSpecifiedPropertyType(QName qName, String parentTypeName) throws BadFieldValueException
254255
{
255256
XMPSchemaFactory factory = getSchemaFactory(qName.getNamespaceURI());
256257
if (factory != null)

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private void parseSchemaExtensions(final XMPMetadata xmp, final Element descript
292292
throw new XmpParsingException(ErrorType.NoSchema,
293293
"This namespace is not from a schema: " + namespace);
294294
}
295-
PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(schemaExtension));
295+
PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(schemaExtension), null);
296296
final XMPSchema schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, schemaExtension.getPrefix());
297297
loadAttributes(schema, description);
298298
ComplexPropertyContainer container = schema.getContainer();
@@ -369,7 +369,7 @@ private void parseDescriptionRootAttr(XMPMetadata xmp, Element description, Attr
369369
{
370370
ComplexPropertyContainer container = schema.getContainer();
371371
PropertyType type = checkPropertyDefinition(xmp,
372-
new QName(attr.getNamespaceURI(), attr.getLocalName(), attr.getPrefix()));
372+
new QName(attr.getNamespaceURI(), attr.getLocalName(), attr.getPrefix()), null);
373373

374374
if (type == null)
375375
{
@@ -426,7 +426,7 @@ private void parseChildrenAsProperties(XMPMetadata xmp, List<Element> properties
426426
{
427427
nsFinder.push(property);
428428
String namespace = property.getNamespaceURI();
429-
PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property));
429+
PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property), null);
430430
// create the container
431431
if (!tm.isDefinedSchema(namespace))
432432
{
@@ -662,7 +662,7 @@ private void parseDescriptionInner(XMPMetadata xmp, Element description, Complex
662662
for (Element property : properties)
663663
{
664664
String name = property.getLocalName();
665-
PropertyType dtype = checkPropertyDefinition(xmp, DomHelper.getQName(property));
665+
PropertyType dtype = checkPropertyDefinition(xmp, DomHelper.getQName(property), null);
666666
PropertyType ptype = tm.getStructuredPropMapping(dtype.type()).getPropertyType(name);
667667
// create property
668668
createProperty(xmp, property, ptype, parentContainer);
@@ -775,34 +775,34 @@ else if (XMLConstants.XML_NS_URI.equals(attr.getNamespaceURI()))
775775
}
776776
}
777777

778-
private AbstractStructuredType parseLiDescription(XMPMetadata xmp, QName descriptor, Element liDescriptionElement)
778+
private AbstractStructuredType parseLiDescription(XMPMetadata xmp, QName parentQName, Element liDescriptionElement)
779779
throws XmpParsingException
780780
{
781781
TypeMapping tm = xmp.getTypeMapping();
782782
List<Element> liDescriptionElementChildren = DomHelper.getElementChildren(liDescriptionElement);
783783
if (liDescriptionElementChildren.isEmpty())
784784
{
785785
// The list is empty
786-
return tryParseAttributesAsProperties(xmp, liDescriptionElement, tm, null, null, descriptor);
786+
return tryParseAttributesAsProperties(xmp, liDescriptionElement, tm, null, null, parentQName);
787787
}
788788
Element firstLiDescriptionElementChild = liDescriptionElementChildren.get(0);
789789
if ("rdf:Description".equals(firstLiDescriptionElementChild.getTagName()))
790790
{
791791
// PDFBOX-6126: "<rdf:Description" as child of "<rdf:li"
792-
return parseLiDescription(xmp, descriptor, firstLiDescriptionElementChild);
792+
return parseLiDescription(xmp, parentQName, firstLiDescriptionElementChild);
793793
}
794794
// Instantiate abstract structured type with hint from first element
795795
nsFinder.push(firstLiDescriptionElementChild);
796-
QName qName = DomHelper.getQName(firstLiDescriptionElementChild);
797-
PropertyType ctype = checkPropertyDefinition(xmp, qName);
796+
QName firstChildQName = DomHelper.getQName(firstLiDescriptionElementChild);
797+
PropertyType ctype = checkPropertyDefinition(xmp, firstChildQName, parentQName.getLocalPart());
798798
if (ctype == null)
799799
{
800800
// PDFBOX-5649
801801
throw new XmpParsingException(ErrorType.NoType,
802-
"Property '" + qName.getLocalPart() + "' not defined in " + qName.getNamespaceURI());
802+
"Property '" + firstChildQName.getLocalPart() + "' not defined in " + firstChildQName.getNamespaceURI());
803803
}
804804
Types tt = ctype.type();
805-
AbstractStructuredType ast = instanciateStructured(tm, tt, descriptor.getLocalPart(), firstLiDescriptionElementChild.getNamespaceURI());
805+
AbstractStructuredType ast = instanciateStructured(tm, tt, parentQName.getLocalPart(), firstLiDescriptionElementChild.getNamespaceURI());
806806

807807
ast.setNamespace(firstLiDescriptionElementChild.getNamespaceURI());
808808
ast.setPrefix(firstLiDescriptionElementChild.getPrefix());
@@ -836,7 +836,7 @@ else if (type.card().isArray())
836836
List<Element> lis = DomHelper.getElementChildren(bagOrSeq);
837837
for (Element element2 : lis)
838838
{
839-
AbstractField ast2 = parseLiElement(xmp, descriptor, element2, type.type());
839+
AbstractField ast2 = parseLiElement(xmp, parentQName, element2, type.type());
840840
if (ast2 != null)
841841
{
842842
array.addProperty(ast2);
@@ -878,7 +878,7 @@ else if (type.type().isStructured())
878878
}
879879

880880
}
881-
ast = tryParseAttributesAsProperties(xmp, liDescriptionElement, tm, ast, pm, descriptor);
881+
ast = tryParseAttributesAsProperties(xmp, liDescriptionElement, tm, ast, pm, parentQName);
882882
nsFinder.pop();
883883
return ast;
884884
}
@@ -1103,7 +1103,7 @@ else if (type.isDefined())
11031103
}
11041104
}
11051105

1106-
private PropertyType checkPropertyDefinition(XMPMetadata xmp, QName qName) throws XmpParsingException
1106+
private PropertyType checkPropertyDefinition(XMPMetadata xmp, QName qName, String parentTypeName) throws XmpParsingException
11071107
{
11081108
TypeMapping tm = xmp.getTypeMapping();
11091109
// test if namespace is set in xml
@@ -1121,7 +1121,7 @@ private PropertyType checkPropertyDefinition(XMPMetadata xmp, QName qName) throw
11211121
}
11221122
try
11231123
{
1124-
return tm.getSpecifiedPropertyType(qName);
1124+
return tm.getSpecifiedPropertyType(qName, null);
11251125
}
11261126
catch (BadFieldValueException e)
11271127
{
@@ -1180,7 +1180,7 @@ else if (XmpConstants.DEFAULT_RDF_PREFIX.equals(attr.getPrefix()))
11801180
// like in parseLiDescription():
11811181
// Instantiate abstract structured type with hint from first element
11821182
QName attrQName = new QName(attr.getNamespaceURI(), attr.getLocalName(), attr.getPrefix());
1183-
PropertyType ctype = checkPropertyDefinition(xmp, attrQName);
1183+
PropertyType ctype = checkPropertyDefinition(xmp, attrQName, null);
11841184
// this is the type of the AbstractStructuredType, not of the element(s)
11851185
if (ctype == null)
11861186
{

0 commit comments

Comments
 (0)