[Dive4elements-commits] [PATCH 2 of 3] Add handling for OUT id's parameter to D4EArtifact

Wald Commits scm-commit at wald.intevation.org
Fri May 10 15:23:48 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1368191796 -7200
# Node ID 95b9e40bbad0e5a6212b4db276d435b615e349c1
# Parent  95cb104a871bda0b2570a3e7a8c0e6793c493010
Add handling for OUT id's parameter to D4EArtifact

    Patch mostly provided by Sascha Teichmann

diff -r 95cb104a871b -r 95b9e40bbad0 artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java	Fri May 10 11:31:51 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java	Fri May 10 15:16:36 2013 +0200
@@ -17,6 +17,8 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.xml.xpath.XPathConstants;
 
@@ -84,6 +86,13 @@
     public static final String XPATH_FILTER =
         "/art:action/art:filter/art:out";
 
+    public static final Pattern CONTAINS_OUT =
+        Pattern.compile( "^(.*):OUT=(.+)$");
+
+    /** Path to 'ids' (data) in doc that comes from datacage. */
+    public static final String XPATH_IDS = "/art:action/art:ids/@value";
+
+
     /** The constant string that shows that an operation was successful. */
     public static final String OPERATION_SUCCESSFUL = "SUCCESS";
 
@@ -111,6 +120,8 @@
      */
     protected Map<String, List<Facet>> filterFacets;
 
+    protected String boundToOut;
+
 
     /**
      * The default constructor that creates an empty D4EArtifact.
@@ -225,8 +236,49 @@
         }
 
         filterFacets = buildFilterFacets(data);
+
+        extractOut(data);
     }
 
+    protected void extractOut(Document data) {
+        log.debug("extractOut");
+        String ids = XMLUtils.xpathString(data, XPATH_IDS,
+            ArtifactNamespaceContext.INSTANCE);
+
+        log.debug("ids: '" + ids + "'");
+        if (ids != null) {
+            Matcher m = CONTAINS_OUT.matcher(ids);
+            if (m.matches()) {
+                boundToOut = m.group(2);
+                log.debug("Bound to out :'" + boundToOut + "'");
+            }
+            else {
+                log.debug("does not match");
+            }
+        }
+    }
+
+    /**
+     * Return the value of id element in Datacage data document.
+     * @param data Document as passed by datacage.
+     * @return the id element value of data document.
+     */
+    public static String getDatacageIDValue(Document data) {
+
+        String ids = XMLUtils.xpathString(data, XPATH_IDS,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (ids != null) {
+            Matcher m = CONTAINS_OUT.matcher(ids);
+            if (m.matches()) {
+                ids = m.group(1);
+            }
+        }
+
+        return ids;
+    }
+
+
 
     /** Get copy of previous state ids as Strings in list. */
     protected List<String> clonePreviousStateIds() {
@@ -1568,5 +1620,9 @@
     protected List<Facet> getFacets(String stateid) {
         return this.facets.get(stateid);
     }
+
+    public String getBoundToOut() {
+        return boundToOut;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 95cb104a871b -r 95b9e40bbad0 artifacts/src/main/java/org/dive4elements/river/artifacts/StaticD4EArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/StaticD4EArtifact.java	Fri May 10 11:31:51 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/StaticD4EArtifact.java	Fri May 10 15:16:36 2013 +0200
@@ -37,9 +37,6 @@
     private static final Logger logger =
         Logger.getLogger(StaticD4EArtifact.class);
 
-    /** Path to 'ids' (data) in doc that comes from datacage. */
-    public static final String XPATH_IDS = "/art:action/art:ids/@value";
-
     /**
      * Create description document which includes outputmodes.
      * @param data ignored.
@@ -94,17 +91,6 @@
     }
 
 
-    /**
-     * Return the value of id element in Datacage data document.
-     * @param data Document as passed by datacage.
-     * @return the id element value of data document.
-     */
-    public static String getDatacageIDValue(Document data) {
-        return XMLUtils.xpathString(data, XPATH_IDS,
-            ArtifactNamespaceContext.INSTANCE);
-    }
-
-
     protected Element createOutputModes(
         CallContext    cc,
         Document       doc,


More information about the Dive4elements-commits mailing list