changeset 569:c7301a701da9

DistanceInfoService: Got rid of namespace. Use DOM instead of XPath. flys-client/trunk@2118 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 14 Jun 2011 16:28:19 +0000
parents 1d20533a4ae3
children 85d7cc0f2bab
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java
diffstat 2 files changed, 21 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Jun 14 15:46:31 2011 +0000
+++ b/flys-client/ChangeLog	Tue Jun 14 16:28:19 2011 +0000
@@ -1,3 +1,8 @@
+2011-06-14	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java:
+	  Got rid of namespace. Use DOM instead of XPath.
+
 2011-06-14	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/DistanceInfoRecord.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java	Tue Jun 14 15:46:31 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DistanceInfoServiceImpl.java	Tue Jun 14 16:28:19 2011 +0000
@@ -89,15 +89,10 @@
     protected DistanceInfoObject[] extractDistanceInfoObjects(Document result)
     throws    ServerException
     {
-        NodeList list = (NodeList) XMLUtils.xpath(
-            result,
-            XPATH_DISTANCES,
-            XPathConstants.NODESET,
-            ArtifactNamespaceContext.INSTANCE);
+        NodeList list = result.getElementsByTagName("distance");
 
         if (list == null || list.getLength() == 0) {
             System.err.println("No distance info found.");
-
             throw new ServerException(ERROR_NO_DISTANCEINFO_FOUND);
         }
 
@@ -108,7 +103,8 @@
             new ArrayList<DistanceInfoObject>(num);
 
         for (int i = 0; i < num; i++) {
-            DistanceInfoObject obj = buildDistanceInfoObject(list.item(i));
+            DistanceInfoObject obj = buildDistanceInfoObject(
+                (Element)list.item(i));
 
             if (obj != null) {
                 objects.add(obj);
@@ -130,43 +126,21 @@
      *
      * @return a valid DistanceInfoObject.
      */
-    protected DistanceInfoObject buildDistanceInfoObject(Node node) {
-
-        // XXX: Using XPath here is much too expensive. DOM will do!
-
-        String desc = XMLUtils.xpathString(
-            node, "@art:description", ArtifactNamespaceContext.INSTANCE);
-
-        String from = XMLUtils.xpathString(
-            node, "@art:from", ArtifactNamespaceContext.INSTANCE);
-
-        String to = XMLUtils.xpathString(
-            node, "@art:to", ArtifactNamespaceContext.INSTANCE);
-
-        String riverside = XMLUtils.xpathString(
-            node, "@art:riverside", ArtifactNamespaceContext.INSTANCE);
+    protected DistanceInfoObject buildDistanceInfoObject(Element node) {
 
-        String bottom = XMLUtils.xpathString(
-            node, "@art:bottom", ArtifactNamespaceContext.INSTANCE);
-
-        String top = XMLUtils.xpathString(
-            node, "@art:top", ArtifactNamespaceContext.INSTANCE);
-
-        if (desc != null && from != null) {
-            try {
-                Double f = new Double(from);
+        String desc      = node.getAttribute("description").trim();
+        String from      = node.getAttribute("from").trim();
+        String to        = node.getAttribute("to").trim();
+        String riverside = node.getAttribute("riverside").trim();
+        String bottom    = node.getAttribute("bottom").trim();
+        String top       = node.getAttribute("top").trim();
 
-                Double t = to != null && (to=to.trim()).length() > 0
-                    ? new Double(to)
-                    : null;
-
-                Double tp = top != null && (top=top.trim()).length() > 0
-                    ? new Double(top)
-                    : null;
-
-                Double b = bottom != null && (bottom=bottom.trim()).length() > 0
-                    ? new Double(bottom)
-                    : null;
+        if (desc.length() > 0 && from.length() > 0) {
+            try {
+                Double f  = new Double(from);
+                Double t  = to    .length() > 0 ? new Double(to)     : null;
+                Double b  = bottom.length() > 0 ? new Double(bottom) : null;
+                Double tp = top   .length() > 0 ? new Double(top)    : null;
 
                 return new DistanceInfoObjectImpl(desc, f, t, riverside, b, tp);
             }

http://dive4elements.wald.intevation.org