[Dive4elements-commits] [PATCH 3 of 4] Used DOM instead of XPath to extract main values

Wald Commits scm-commit at wald.intevation.org
Fri Apr 5 23:30:08 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1365197268 -7200
# Node ID 4b281c7046c86e102d590f3874b26a82baad94dd
# Parent  d35a0bc153fa4722419b633edc9bf045966a0fb3
Used DOM instead of XPath to extract main values.

diff -r d35a0bc153fa -r 4b281c7046c8 flys-client/src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java
--- a/flys-client/src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java	Fri Apr 05 23:19:01 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java	Fri Apr 05 23:27:48 2013 +0200
@@ -131,7 +131,7 @@
             new ArrayList<WQInfoObject>(num);
 
         for (int i = 0; i < num; i++) {
-            WQInfoObject obj = buildWQInfoObject(list.item(i));
+            WQInfoObject obj = buildWQInfoObject((Element)list.item(i));
 
             if (obj != null) {
                 objects.add(obj);
@@ -176,20 +176,15 @@
      *
      * @return a valid WQInfoObject.
      */
-    protected WQInfoObject buildWQInfoObject(Node node) {
+    protected static WQInfoObject buildWQInfoObject(Element node) {
 
-        // TODO: Replace this expensive XPaths with simpler use of DOM.
-        String name = XMLUtils.xpathString(
-            node, "@name", ArtifactNamespaceContext.INSTANCE);
+        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
 
-        String type = XMLUtils.xpathString(
-            node, "@type", ArtifactNamespaceContext.INSTANCE);
+        String name  = node.getAttributeNS(uri, "name");
+        String type  = node.getAttributeNS(uri, "type");
+        String value = node.getAttributeNS(uri, "value");
 
-        String value = XMLUtils.xpathString(
-            node, "@value", ArtifactNamespaceContext.INSTANCE);
-
-
-        if (name != null && type != null) {
+        if (!name.isEmpty() && !type.isEmpty()) {
             try {
                 return new WQInfoObjectImpl(
                     name,


More information about the Dive4elements-commits mailing list