changeset 683:8a9456d5a081

DistanceInfoService: Got rid of namespace in result document. flys-artifacts/trunk@2117 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 14 Jun 2011 16:26:59 +0000
parents 591249171c32
children 82eb41beb4de
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java
diffstat 2 files changed, 29 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jun 14 15:34:27 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jun 14 16:26:59 2011 +0000
@@ -1,3 +1,8 @@
+2011-06-14  Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java:
+	  Got rid of namespace in result document.
+
 2011-06-14  Ingo Weinzierl <ingo@intevation.de>
 
 	  flys/issue77 (Diagramm: Beschriftung der Kurven bei Dauerlinien)
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java	Tue Jun 14 15:34:27 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java	Tue Jun 14 16:26:59 2011 +0000
@@ -12,7 +12,6 @@
 
 import de.intevation.artifacts.common.ArtifactNamespaceContext;
 import de.intevation.artifacts.common.utils.XMLUtils;
-import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
 
 import de.intevation.artifactdatabase.DefaultService;
 
@@ -99,22 +98,17 @@
 
         Document result = XMLUtils.newDocument();
 
-        ElementCreator ec = new ElementCreator(
-            result,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
-
         Session session = SessionHolder.acquire();
 
         try {
             Iterator<Annotation> iter =
                 AnnotationsFactory.getAnnotationsIterator(river);
 
-            Element all = ec.create("distances");
+            Element all = result.createElement("distances");
 
             while (iter.hasNext()) {
                 Annotation a = iter.next();
-                Element distance = buildDistanceNode(ec, a);
+                Element distance = buildDistanceNode(result, a);
                 all.appendChild(distance);
             }
 
@@ -137,33 +131,41 @@
      *
      * @return an Element that contains information about a distance.
      */
-    protected static Element buildDistanceNode(ElementCreator ec, Annotation anno) {
-        Position  pos   = anno.getPosition();
-        Range     range = anno.getRange();
-        Attribute attr  = anno.getAttribute();
-        Edge      edge  = anno.getEdge();
+    protected static Element buildDistanceNode(
+        Document   document,
+        Annotation anno
+    ) {
+        Position   pos   = anno.getPosition();
+        Range      range = anno.getRange();
+        Attribute  attr  = anno.getAttribute();
+        Edge       edge  = anno.getEdge();
+        BigDecimal a     = range.getA();
+        BigDecimal b     = range.getB();
 
-        BigDecimal a = range.getA();
-        BigDecimal b = range.getB();
+        Element distance = document.createElement("distance");
 
-        Element distance = ec.create("distance");
-        ec.addAttr(distance, "description", pos.getValue(), true);
-        ec.addAttr(distance, "riverside", attr.getValue(), true);
+        distance.setAttribute("description", pos.getValue());
+
+        String riverSide = attr.getValue();
+
+        if (riverSide != null && riverSide.length() > 0) {
+            distance.setAttribute("riverside", riverSide);
+        }
 
         if (a != null) {
-            ec.addAttr(distance, "from", a.toString(), true);
+            distance.setAttribute("from", a.toString());
         }
         if (b != null) {
-            ec.addAttr(distance, "to", b.toString(), true);
+            distance.setAttribute("to", b.toString());
         }
         if (edge != null) {
             BigDecimal bottom = edge.getBottom();
             BigDecimal top    = edge.getTop();
             if (bottom != null) {
-                ec.addAttr(distance, "bottom", bottom.toString(), true);
+                distance.setAttribute("bottom", bottom.toString());
             }
             if (top != null) {
-                ec.addAttr(distance, "top", top.toString(), true);
+                distance.setAttribute("top", top.toString());
             }
         }
 

http://dive4elements.wald.intevation.org