changeset 813:57ea5af8a967

Meta data service converter: transfer attributes to client, too. flys-client/trunk@2469 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 08 Aug 2011 15:54:59 +0000
parents 70b728a9f4e8
children 6db4839e0ba1
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java flys-client/src/main/java/de/intevation/flys/client/shared/model/AttrList.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DataCageNode.java
diffstat 4 files changed, 94 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Aug 08 14:49:14 2011 +0000
+++ b/flys-client/ChangeLog	Mon Aug 08 15:54:59 2011 +0000
@@ -1,3 +1,14 @@
+2011-08-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de> 
+
+	* src/main/java/de/intevation/flys/client/shared/model/AttrList.java:
+	  New. List of attributes for each DataCageNode.
+
+	* src/main/java/de/intevation/flys/client/server/meta/Converter.java:
+	  Generate the list of attributes for each datacage node.
+
+	* src/main/java/de/intevation/flys/client/shared/model/DataCageNode.java:
+	  Added the attribute list.
+
 2011-08-08	Sascha L. Teichmann	<sascha.teichmann@intevation.de> 
 
 	* src/main/java/de/intevation/flys/client/client/ui/DatacageWindow.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java	Mon Aug 08 14:49:14 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/meta/Converter.java	Mon Aug 08 15:54:59 2011 +0000
@@ -4,9 +4,13 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.Attr;
+import org.w3c.dom.NamedNodeMap;
+
 
 import de.intevation.flys.client.shared.model.DataCageTree;
 import de.intevation.flys.client.shared.model.DataCageNode;
+import de.intevation.flys.client.shared.model.AttrList;
 
 import java.util.ArrayList;
 import java.util.Map;
@@ -25,7 +29,9 @@
     public static class NameConverter implements NodeConverter {
         public DataCageNode convert(Element node, Converter converter) {
             System.err.println("NameConverter called");
-            DataCageNode out = new DataCageNode(node.getAttribute("name"));
+            DataCageNode out = new DataCageNode(
+                node.getAttribute("name"),
+                toAttrList(node.getAttributes()));
             converter.convertChildren(out, node);
             return out;
         }
@@ -35,7 +41,9 @@
         public DataCageNode convert(Element node, Converter converter) {
             System.err.println("I18NConverter called");
             DataCageNode out =
-                new DataCageNode("${" + node.getLocalName() + "}");
+                new DataCageNode(
+                    "${" + node.getLocalName() + "}",
+                    toAttrList(node.getAttributes()));
             converter.convertChildren(out, node);
             return out;
         }
@@ -99,5 +107,30 @@
             ? new DataCageTree()
             : new DataCageTree(roots.get(0));
     }
+
+    public static AttrList toAttrList(NamedNodeMap nodeMap) {
+        if (nodeMap == null) {
+            return null;
+        }
+        int N = nodeMap.getLength();
+
+        if (N == 0) {
+            return null;
+        }
+
+        AttrList result = new AttrList(N);
+
+        for (int i = 0; i < N; ++i) {
+            Node node = nodeMap.item(i);
+            if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
+                Attr   attr   = (Attr)node;
+                String key   = attr.getName();
+                String value = attr.getValue();
+                result.add(key, value);
+            }
+        }
+
+        return result;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/AttrList.java	Mon Aug 08 15:54:59 2011 +0000
@@ -0,0 +1,37 @@
+package de.intevation.flys.client.shared.model;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import java.io.Serializable;
+
+public class AttrList implements Serializable
+{
+    protected List<String> keyValues;
+
+    public AttrList() {
+        this(5);
+    }
+
+    public AttrList(int size) {
+        keyValues = new ArrayList<String>(size*2);
+    }
+
+    public int size() {
+        return keyValues != null ? keyValues.size()/2 : null;
+    }
+
+    public String getKey(int index) {
+        return keyValues.get(index/2);
+    }
+
+    public String getValue(int index) {
+        return keyValues.get(index/2 + 1);
+    }
+
+    public void add(String key, String value) {
+        keyValues.add(key);
+        keyValues.add(value);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DataCageNode.java	Mon Aug 08 14:49:14 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DataCageNode.java	Mon Aug 08 15:54:59 2011 +0000
@@ -9,12 +9,18 @@
 {
     protected String             name;
     protected List<DataCageNode> children;
+    protected AttrList           attrs;
 
     public DataCageNode() {
     }
 
     public DataCageNode(String name) {
-        this.name = name;
+        this(name, null);
+    }
+
+    public DataCageNode(String name, AttrList attrs) {
+        this.name  = name;
+        this.attrs = attrs;
     }
 
     public String getName() {
@@ -35,5 +41,9 @@
     public List<DataCageNode> getChildren() {
         return children;
     }
+
+    public AttrList getAttributes() {
+        return attrs;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org