Author: tilman
Date: Sun Dec 28 20:22:15 2025
New Revision: 1930947
Log:
PDFBOX-6133: refactor
Modified:
pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
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
Sun Dec 28 20:22:10 2025 (r1930946)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Sun Dec 28 20:22:15 2025 (r1930947)
@@ -153,13 +153,10 @@ public class DomXmpParser
{
throw new XmpParsingException(ErrorType.XpacketBadStart, "xmp
should start with a processing instruction");
}
- else
- {
- xmp =
XMPMetadata.createXMPMetadata(XmpConstants.DEFAULT_XPACKET_BEGIN,
- XmpConstants.DEFAULT_XPACKET_ID,
- XmpConstants.DEFAULT_XPACKET_BYTES,
- XmpConstants.DEFAULT_XPACKET_ENCODING);
- }
+ xmp =
XMPMetadata.createXMPMetadata(XmpConstants.DEFAULT_XPACKET_BEGIN,
+ XmpConstants.DEFAULT_XPACKET_ID,
+ XmpConstants.DEFAULT_XPACKET_BYTES,
+ XmpConstants.DEFAULT_XPACKET_ENCODING);
}
else
{
@@ -190,10 +187,7 @@ public class DomXmpParser
{
throw new XmpParsingException(ErrorType.XpacketBadEnd, "xmp
should end with a processing instruction");
}
- else
- {
- xmp.setEndXPacket(XmpConstants.DEFAULT_XPACKET_END);
- }
+ xmp.setEndXPacket(XmpConstants.DEFAULT_XPACKET_END);
}
else
{
@@ -215,15 +209,12 @@ public class DomXmpParser
if (!strictParsing)
{
NamedNodeMap nnm = rdfRdf.getAttributes();
- if (nnm != null)
+ for (int i = 0; i < nnm.getLength(); i++)
{
- for (int i = 0; i < nnm.getLength(); i++)
+ Attr attr = (Attr) nnm.item(i);
+ if (XMLConstants.XMLNS_ATTRIBUTE.equals(attr.getPrefix()))
{
- Attr attr = (Attr) nnm.item(i);
- if (XMLConstants.XMLNS_ATTRIBUTE.equals(attr.getPrefix()))
- {
- maybeAddNonStandardNamespace(xmp, attr);
- }
+ maybeAddNonStandardNamespace(xmp, attr);
}
}
}
@@ -378,11 +369,8 @@ public class DomXmpParser
throw new XmpParsingException(ErrorType.InvalidType, "No
type defined for {" + attr.getNamespaceURI() + "}"
+ attr.getLocalName());
}
- else
- {
- // PDFBOX-2318, PDFBOX-6106: Default to text if no type is
found
- type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
- }
+ // PDFBOX-2318, PDFBOX-6106: Default to text if no type is
found
+ type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
}
else if (!type.type().isSimple() || type.card().isArray() ||
type.type() == Types.LangAlt)
{
@@ -392,16 +380,13 @@ public class DomXmpParser
type.type().name() + "' in '" + attr.getPrefix() +
":" + attr.getLocalName() + "=" + attr.getValue()
+ "' is a structured or array type, but attributes
are simple types");
}
- else
+ // PDFBOX-6125: Default to text or skip
+ if (attr.getValue() == null || attr.getValue().isEmpty())
{
- // PDFBOX-6125: Default to text or skip
- if (attr.getValue() == null || attr.getValue().isEmpty())
- {
- schema.removeAttribute(attr.getLocalName());
- return;
- }
- type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
+ schema.removeAttribute(attr.getLocalName());
+ return;
}
+ type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
}
try
@@ -467,11 +452,8 @@ public class DomXmpParser
throw new XmpParsingException(ErrorType.InvalidType, "No
type defined for {" + namespace + "}"
+ name);
}
- else
- {
- // use it as string
- manageSimpleType(xmp, property, Types.Text, container);
- }
+ // use it as string
+ manageSimpleType(xmp, property, Types.Text, container);
}
else if (type.type() == Types.LangAlt)
{
@@ -1153,10 +1135,6 @@ public class DomXmpParser
PropertiesDescription pm, QName qName) throws XmpParsingException
{
NamedNodeMap attributes = liElement.getAttributes();
- if (attributes == null)
- {
- return ast;
- }
for (int i = 0; i < attributes.getLength(); ++i)
{
Attr attr = (Attr) attributes.item(i);
@@ -1212,11 +1190,8 @@ public class DomXmpParser
throw new
XmpParsingException(ErrorType.InvalidType, "No type defined for {" +
attr.getNamespaceURI() + "}"
+ attr.getLocalName());
}
- else
- {
- // PDFBOX-2318, PDFBOX-6106: Default to text if no
type is found
- type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
- }
+ // PDFBOX-2318, PDFBOX-6106: Default to text if no
type is found
+ type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
}
else if (!type.type().isSimple() || type.card().isArray()
|| type.type() == Types.LangAlt)
{
@@ -1226,15 +1201,12 @@ public class DomXmpParser
type.type().name() + "' in '" +
attr.getPrefix() + ":" + attr.getLocalName() + "=" + attr.getValue()
+ "' is a structured or array type, but
attributes are simple types");
}
- else
+ // PDFBOX-6125: Default to text or skip
+ if (attr.getValue() == null ||
attr.getValue().isEmpty())
{
- // PDFBOX-6125: Default to text or skip
- if (attr.getValue() == null ||
attr.getValue().isEmpty())
- {
- continue;
- }
- type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
+ continue;
}
+ type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
}
AbstractSimpleProperty asp = tm.instanciateSimpleProperty(
attr.getNamespaceURI(), attr.getPrefix(),
attr.getLocalName(),