changeset 8071:6e6506ec0ae0

Parse meta data for multi attribute data.
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 05 Aug 2014 18:28:04 +0200
parents d77f53c1e5a1
children 5f28aa1be795 bd0dfa57b1fe
files gwt-client/src/main/java/org/dive4elements/river/client/server/DataFactory.java gwt-client/src/main/java/org/dive4elements/river/client/shared/model/MultiAttributeData.java
diffstat 2 files changed, 44 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/DataFactory.java	Tue Aug 05 18:03:45 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/DataFactory.java	Tue Aug 05 18:28:04 2014 +0200
@@ -8,20 +8,20 @@
 
 package org.dive4elements.river.client.server;
 
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Map;
 
 import javax.xml.xpath.XPathConstants;
 
+import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-
 import org.apache.log4j.Logger;
-
 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
 import org.dive4elements.artifacts.common.utils.XMLUtils;
-
 import org.dive4elements.river.client.shared.model.Data;
 import org.dive4elements.river.client.shared.model.DataItem;
 import org.dive4elements.river.client.shared.model.DefaultData;
@@ -36,7 +36,6 @@
 import org.dive4elements.river.client.shared.model.StringData;
 import org.dive4elements.river.client.shared.model.StringOptionsData;
 import org.dive4elements.river.client.shared.model.LongRangeData;
-
 import org.dive4elements.river.client.shared.model.IntDataItem;
 
 /**
@@ -119,7 +118,33 @@
         return new MultiAttributeData(
             name,
             label,
-            extractMultiDataItems(element));
+            extractMultiDataItems(element),
+            extractMeta(element));
+    }
+
+
+    private static Map<String, Map<String, String>> extractMeta(Element element) {
+        NodeList nl = element.getElementsByTagName("meta");
+        int N = nl.getLength();
+        if (N < 1) {
+            logger.debug("No meta data found for multi attribute data");
+            return Collections.<String, Map<String, String>>emptyMap();
+        }
+        Map<String, Map<String, String>> map =
+            new HashMap<String, Map<String, String>>();
+
+        for (int i = 0; i < N; ++i) {
+            Element e = (Element)nl.item(i);
+            NamedNodeMap attrs = e.getAttributes();
+            Map<String, String> kvs = new HashMap<String, String>();
+            for (int j = 0, A = attrs.getLength(); j < A; ++j) {
+                Attr attr = (Attr)attrs.item(j);
+                kvs.put(attr.getName(), attr.getValue());
+            }
+            map.put(e.getTagName(), kvs);
+        }
+
+        return map;
     }
 
 
@@ -145,7 +170,7 @@
              HashMap<String, String> data = new HashMap<String, String>();
              String label = tmp.getAttributeNS(NS_URI, "label");
              NamedNodeMap attributes = tmp.getAttributes();
-             for (int j = 0; j < attributes.getLength(); j++) {
+             for (int j = 0, L = attributes.getLength(); j < L; j++) {
                  Node n = attributes.item(j);
                  if (n.getNodeName().equals("label")) {
                      continue;
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/MultiAttributeData.java	Tue Aug 05 18:03:45 2014 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/MultiAttributeData.java	Tue Aug 05 18:28:04 2014 +0200
@@ -1,5 +1,7 @@
 package org.dive4elements.river.client.shared.model;
 
+import java.util.Map;
+
 
 public class MultiAttributeData
 implements Data
@@ -10,6 +12,8 @@
     protected String label;
     protected String description;
 
+    protected Map<String, Map<String, String>> meta;
+
     public DataItem[] opts;
 
 
@@ -17,12 +21,20 @@
     }
 
 
-    public MultiAttributeData(String label, String desc, DataItem[] opts) {
+    public MultiAttributeData(
+        String                           label,
+        String                           desc,
+        DataItem[]                       opts,
+        Map<String, Map<String, String>> meta
+    ) {
         this.label       = label;
         this.description = desc;
         this.opts        = opts;
     }
 
+    public Map<String, Map<String, String>> getMeta() {
+        return meta;
+    }
 
     /**
      * Returns the label of the item.

http://dive4elements.wald.intevation.org