pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1647162 - /pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Date Sun, 21 Dec 2014 16:12:25 GMT
Author: tilman
Date: Sun Dec 21 16:12:25 2014
New Revision: 1647162

URL: http://svn.apache.org/r1647162
Log:
PDFBOX-2576: split up long method into smaller ones

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
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java?rev=1647162&r1=1647161&r2=1647162&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java Sun Dec 21 16:12:25
2014
@@ -69,13 +69,6 @@ import org.xml.sax.SAXException;
 
 public class DomXmpParser
 {
-
-    /**
-     * Log instance.
-     */
-    private static final Log LOG = LogFactory.getLog(DomXmpParser.class);
-
-
     private DocumentBuilder dBuilder;
 
     private NamespaceFinder nsFinder;
@@ -270,27 +263,7 @@ public class DomXmpParser
                     }
                 }
             }
-            // parse children elements as properties
-            for (Element property : properties)
-            {
-                String namespace = property.getNamespaceURI();
-                PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property));
-                // create the container
-                if (!tm.isDefinedSchema(namespace))
-                {
-                    throw new XmpParsingException(ErrorType.NoSchema,
-                            "This namespace is not a schema or a structured type : " + namespace);
-                }
-                XMPSchema schema = xmp.getSchema(namespace);
-                if (schema == null)
-                {
-                    schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, property.getPrefix());
-                    loadAttributes(schema, description);
-                }
-                ComplexPropertyContainer container = schema.getContainer();
-                // create property
-                createProperty(xmp, property, type, container);
-            }
+            parseChildrenAsProperties(xmp, properties, tm, description);
         }
         catch (XmpSchemaException e)
         {
@@ -302,6 +275,32 @@ public class DomXmpParser
         }
     }
 
+    private void parseChildrenAsProperties(XMPMetadata xmp, List<Element> properties,
TypeMapping tm, Element description)
+            throws XmpParsingException, XmpSchemaException
+    {
+        // parse children elements as properties
+        for (Element property : properties)
+        {
+            String namespace = property.getNamespaceURI();
+            PropertyType type = checkPropertyDefinition(xmp, DomHelper.getQName(property));
+            // create the container
+            if (!tm.isDefinedSchema(namespace))
+            {
+                throw new XmpParsingException(ErrorType.NoSchema,
+                        "This namespace is not a schema or a structured type : " + namespace);
+            }
+            XMPSchema schema = xmp.getSchema(namespace);
+            if (schema == null)
+            {
+                schema = tm.getSchemaFactory(namespace).createXMPSchema(xmp, property.getPrefix());
+                loadAttributes(schema, description);
+            }
+            ComplexPropertyContainer container = schema.getContainer();
+            // create property
+            createProperty(xmp, property, type, container);
+        }
+    }
+
     private void createProperty(XMPMetadata xmp, Element property, PropertyType type, ComplexPropertyContainer
container)
             throws XmpParsingException
     {
@@ -339,47 +338,11 @@ public class DomXmpParser
             }
             else if (type.type().isStructured())
             {
-                if (DomHelper.isParseTypeResource(property))
-                {
-                    AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property),
property);
-                    if (ast != null)
-                    {
-                        ast.setPrefix(prefix);
-                        container.addProperty(ast);
-                    }
-                }
-                else
-                {
-                    Element inner = DomHelper.getFirstChildElement(property);
-                    if (inner != null)
-                    {
-                        nsFinder.push(inner);
-                        AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property),
inner);
-                        ast.setPrefix(prefix);
-                        container.addProperty(ast);
-                    }
-                }
+                manageStructuredType(xmp, property, prefix, container);
             }
             else if (type.type() == Types.DefinedType)
             {
-                if (DomHelper.isParseTypeResource(property))
-                {
-                    AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property),
property);
-                    ast.setPrefix(prefix);
-                    container.addProperty(ast);
-                }
-                else
-                {
-                    Element inner = DomHelper.getFirstChildElement(property);
-                    if (inner == null)
-                    {
-                        throw new XmpParsingException(ErrorType.Format, "property should
contain child element : "
-                                + property);
-                    }
-                    AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property),
inner);
-                    ast.setPrefix(prefix);
-                    container.addProperty(ast);
-                }
+                manageDefinedType(xmp, property, prefix, container);
             }
         }
         catch (IllegalArgumentException e)
@@ -390,7 +353,54 @@ public class DomXmpParser
         {
             nsFinder.pop();
         }
+    }
+
+    private void manageDefinedType(XMPMetadata xmp, Element property, String prefix, ComplexPropertyContainer
container)
+            throws XmpParsingException
+    {
+        if (DomHelper.isParseTypeResource(property))
+        {
+            AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property),
property);
+            ast.setPrefix(prefix);
+            container.addProperty(ast);
+        }
+        else
+        {
+            Element inner = DomHelper.getFirstChildElement(property);
+            if (inner == null)
+            {
+                throw new XmpParsingException(ErrorType.Format, "property should contain
child element : "
+                        + property);
+            }
+            AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property),
inner);
+            ast.setPrefix(prefix);
+            container.addProperty(ast);
+        }
+    }
 
+    private void manageStructuredType(XMPMetadata xmp, Element property, String prefix, ComplexPropertyContainer
container)
+            throws XmpParsingException
+    {
+        if (DomHelper.isParseTypeResource(property))
+        {
+            AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property),
property);
+            if (ast != null)
+            {
+                ast.setPrefix(prefix);
+                container.addProperty(ast);
+            }
+        }
+        else
+        {
+            Element inner = DomHelper.getFirstChildElement(property);
+            if (inner != null)
+            {
+                nsFinder.push(inner);
+                AbstractStructuredType ast = parseLiDescription(xmp, DomHelper.getQName(property),
inner);
+                ast.setPrefix(prefix);
+                container.addProperty(ast);
+            }
+        }
     }
 
     private void manageSimpleType(XMPMetadata xmp, Element property, Types type, ComplexPropertyContainer
container)



Mime
View raw message