[PATCH] Parse meta data for multi attribute data
Wald Commits
scm-commit at wald.intevation.org
Tue Aug 5 18:28:10 CEST 2014
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1407256084 -7200
# Node ID 6e6506ec0ae00b55c996b157adfb5202c1be3213
# Parent d77f53c1e5a170c6ac4676c924ff9f656eec6372
Parse meta data for multi attribute data.
diff -r d77f53c1e5a1 -r 6e6506ec0ae0 gwt-client/src/main/java/org/dive4elements/river/client/server/DataFactory.java
--- 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;
diff -r d77f53c1e5a1 -r 6e6506ec0ae0 gwt-client/src/main/java/org/dive4elements/river/client/shared/model/MultiAttributeData.java
--- 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.
More information about the Dive4Elements-commits
mailing list