changeset 4352:823c8afa1335

Refactor Converter to use common code
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 01 Nov 2012 14:49:43 +0100
parents cb1655e87ce6
children daf0919df76d
files flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java
diffstat 1 files changed, 23 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java	Thu Nov 01 12:30:07 2012 +0100
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java	Thu Nov 01 14:49:43 2012 +0100
@@ -82,19 +82,18 @@
 
     public DataCageTree convert(Document document) {
         logger.debug("convert called");
-        //System.err.println(XMLUtils.toString(document));
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(XMLUtils.toString(document));
+        }
 
         ArrayList<DataCageNode> roots = new ArrayList<DataCageNode>();
         NodeList nodes = document.getChildNodes();
         for (int i = 0, N = nodes.getLength(); i < N; ++i) {
             Node node = nodes.item(i);
             if (node.getNodeType() == Node.ELEMENT_NODE) {
-                logger.debug("search for name: " + node.getLocalName());
-                NodeConverter converter = converters.get(node.getLocalName());
-                if (converter == null) {
-                    converter = I18N_CONVERTER;
-                }
-                roots.add(converter.convert((Element)node, this));
+                Element ele = (Element)node;
+                roots.add(convertElement(ele));
             }
         }
         return roots.isEmpty()
@@ -108,21 +107,28 @@
         for (int i = 0, N = children.getLength(); i < N; ++i) {
             Node child = children.item(i);
             if (child.getNodeType() == Node.ELEMENT_NODE) {
-                String name = child.getLocalName();
-                NodeConverter converter = converters.get(name);
-                if (converter == null) {
-                    converter = I18N_CONVERTER;
-                }
-                DataCageNode son = converter.convert(
-                    (Element)child, this);
-                parent.addChild(son);
+                Element childele = (Element)child;
+                parent.addChild(convertElement(childele));
 
-            if (((Element)child).hasAttribute("description"))
-                logger.debug("nwd: " + ((Element)child).getAttribute("description"));
+            if (childele.hasAttribute("description"))
+                logger.debug("nwd: " + childele.getAttribute("description"));
             }
         } // for all children
     }
 
+    private DataCageNode convertElement(Element element) {
+        String name = element.getLocalName();
+
+        logger.debug("search for name: " + name);
+
+        NodeConverter converter = converters.get(name);
+        if (converter == null) {
+            converter = I18N_CONVERTER;
+        }
+        return converter.convert(element, this);
+
+    }
+
 
     /**
      * Creates key/value pairs from Nodes Attributes.

http://dive4elements.wald.intevation.org