changeset 5975:95b9e40bbad0

Add handling for OUT id's parameter to D4EArtifact Patch mostly provided by Sascha Teichmann
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 10 May 2013 15:16:36 +0200
parents 95cb104a871b
children 178a873df7a9
files artifacts/src/main/java/org/dive4elements/river/artifacts/D4EArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/StaticD4EArtifact.java
diffstat 2 files changed, 56 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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 :
--- 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,

http://dive4elements.wald.intevation.org