# HG changeset patch # User Björn Ricks # Date 1351777783 -3600 # Node ID 823c8afa13356a4983cb9f2dbed8dfe389c44940 # Parent cb1655e87ce67d44baca4dd674a7e9f436d381b9 Refactor Converter to use common code diff -r cb1655e87ce6 -r 823c8afa1335 flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java --- 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 roots = new ArrayList(); 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.