changeset 7464:f16dce7a2407

Simplified recommendattion monitor code a bit.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 30 Oct 2013 11:57:04 +0100
parents 52c364813cb1
children 4b29bb2c785f
files artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java
diffstat 1 files changed, 11 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java	Wed Oct 30 11:56:13 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java	Wed Oct 30 11:57:04 2013 +0100
@@ -12,18 +12,16 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.xml.xpath.XPathConstants;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.ArtifactNamespaceContext;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.Hook;
 
-import org.dive4elements.artifacts.common.utils.XMLUtils;
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
 
 import org.dive4elements.artifactdatabase.state.Output;
@@ -33,9 +31,6 @@
 /** Monitors collection changes. */
 public class CollectionMonitor implements Hook {
 
-    public static final String XPATH_RESULT = "/art:result";
-
-
     @Override
     public void setup(Node cfg) {
     }
@@ -51,11 +46,14 @@
             return;
         }
 
-        Element result = (Element) XMLUtils.xpath(
-            doc,
-            XPATH_RESULT,
-            XPathConstants.NODE,
-            ArtifactNamespaceContext.INSTANCE);
+        NodeList results = doc.getElementsByTagNameNS(
+            ArtifactNamespaceContext.NAMESPACE_URI, "result");
+
+        if (results.getLength() < 1) {
+            return;
+        }
+
+        Element result = (Element)results.item(0);
 
         ElementCreator creator = new ElementCreator(
             doc,
@@ -63,7 +61,6 @@
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
         Element recommended = creator.create("recommended-artifacts");
-        result.appendChild(recommended);
 
         String[] outs              = extractOutputNames(flys, context);
         Map<String, Object> params = getNoneUserSpecificParameters(flys, context);
@@ -73,6 +70,8 @@
         // TODO For newer official-lines recommendations we actually
         // need user-id (null here).
         rec.recommend(flys, null, outs, params, recommended);
+
+        result.appendChild(recommended);
     }
 
 

http://dive4elements.wald.intevation.org