changeset 325:4022ea69d1cb

Write filters to create document if they are given. artifacts/trunk@2567 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 24 Aug 2011 14:35:27 +0000
parents ee6e1b2f137a
children 3447fa62f007
files ChangeLog artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java artifacts-common/src/main/java/de/intevation/artifacts/common/utils/CreationFilter.java
diffstat 3 files changed, 85 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Aug 24 13:49:59 2011 +0000
+++ b/ChangeLog	Wed Aug 24 14:35:27 2011 +0000
@@ -1,3 +1,11 @@
+2011-08-24	Sascha L. Teichmann	<teichmann@intevation.de>
+
+	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java:
+	  Write filters to create document if they are given.
+
+	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/CreationFilter.java:
+	  New. Model for the creation filter.
+
 2011-08-24  Ingo Weinzierl <ingo@intevation.de>
 
 	* artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java:
--- a/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Wed Aug 24 13:49:59 2011 +0000
+++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java	Wed Aug 24 14:35:27 2011 +0000
@@ -84,6 +84,13 @@
         return newCreateDocument(factory, uuid, null);
     }
 
+    public static Document newCreateDocument(
+        String  factory,
+        String  uuid,
+        String  ids
+    ) {
+        return newCreateDocument(factory, uuid, ids, null);
+    }
 
     /**
      * This method creates a new CREATE document.
@@ -91,10 +98,11 @@
      * @return the CREATE document.
      */
     public static Document newCreateDocument(
-        String  factory,
-        String  uuid,
-        String  ids)
-    {
+        String         factory,
+        String         uuid,
+        String         ids,
+        CreationFilter filter
+    ) {
         Document doc = XMLUtils.newDocument();
 
         XMLUtils.ElementCreator cr = new XMLUtils.ElementCreator(
@@ -124,6 +132,10 @@
             action.appendChild(id);
         }
 
+        if (filter != null) {
+            action.appendChild(filter.toXML(cr));
+        }
+
         doc.appendChild(action);
 
         return doc;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/CreationFilter.java	Wed Aug 24 14:35:27 2011 +0000
@@ -0,0 +1,61 @@
+package de.intevation.artifacts.common.utils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.w3c.dom.Element;
+
+public class CreationFilter
+{
+    public static class Facet {
+
+        protected String name;
+        protected String index;
+
+        public Facet() {
+        }
+
+        public Facet(String name, String index) {
+            this.name  = name;
+            this.index = index;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getIndex() {
+            return index;
+        }
+    }
+
+    protected Map<String, List<Facet>> outs;
+
+    public CreationFilter() {
+        outs = new HashMap<String, List<Facet>>();
+    }
+
+    public void add(String out, List<Facet> facets) {
+        outs.put(out, facets);
+    }
+
+    public Element toXML(XMLUtils.ElementCreator ec) {
+        Element filter = ec.create("filter");
+
+        for (Map.Entry<String, List<Facet>> entry: outs.entrySet()) {
+            Element out = ec.create("out");
+            out.setAttribute("name", entry.getKey());
+            for (Facet facet: entry.getValue()) {
+                Element f = ec.create("facet");
+                f.setAttribute("name", facet.getName());
+                f.setAttribute("index", facet.getIndex());
+                out.appendChild(f);
+            }
+            filter.appendChild(out);
+        }
+
+        return filter;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org