comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java @ 1159:fb5a7ff9feb8

Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part. flys-artifacts/trunk@2695 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 12 Sep 2011 06:23:48 +0000
parents 8da5f5a9ed3c
children 28154920e0b3
comparison
equal deleted inserted replaced
1158:fbe18ad4caff 1159:fb5a7ff9feb8
16 import de.intevation.artifacts.ArtifactNamespaceContext; 16 import de.intevation.artifacts.ArtifactNamespaceContext;
17 import de.intevation.artifacts.CallContext; 17 import de.intevation.artifacts.CallContext;
18 import de.intevation.artifacts.CallMeta; 18 import de.intevation.artifacts.CallMeta;
19 19
20 import de.intevation.artifacts.common.utils.XMLUtils; 20 import de.intevation.artifacts.common.utils.XMLUtils;
21 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
21 22
22 import de.intevation.artifactdatabase.ProtocolUtils; 23 import de.intevation.artifactdatabase.ProtocolUtils;
23 24
24 import de.intevation.artifactdatabase.data.StateData; 25 import de.intevation.artifactdatabase.data.StateData;
25 26
56 Document document, 57 Document document,
57 Node root, 58 Node root,
58 CallContext context, 59 CallContext context,
59 String uuid) 60 String uuid)
60 { 61 {
61 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( 62 ElementCreator creator = new ElementCreator(
62 document, 63 document,
63 ArtifactNamespaceContext.NAMESPACE_URI, 64 ArtifactNamespaceContext.NAMESPACE_URI,
64 ArtifactNamespaceContext.NAMESPACE_PREFIX); 65 ArtifactNamespaceContext.NAMESPACE_PREFIX);
65 66
66 CallMeta meta = context.getMeta(); 67 CallMeta meta = context.getMeta();
78 79
79 Iterator<String> iter = theData.keySet().iterator(); 80 Iterator<String> iter = theData.keySet().iterator();
80 FLYSArtifact flys = (FLYSArtifact) artifact; 81 FLYSArtifact flys = (FLYSArtifact) artifact;
81 82
82 while (iter.hasNext()) { 83 while (iter.hasNext()) {
83 String name = iter.next(); 84 String name = iter.next();
84 StateData data = getData(flys, name); 85 appendStaticData(flys, meta, creator, ui, name);
85
86 String value = (data != null) ? (String) data.getValue() : null;
87
88 if (value == null) {
89 continue;
90 }
91
92 logger.debug("Append element '" + name + "' (" + value + ")");
93
94 Element dataElement = creator.create("data");
95 creator.addAttr(dataElement, "name", name, true);
96 creator.addAttr(dataElement, "type", data.getType(), true);
97
98 Element itemElement = creator.create("item");
99 creator.addAttr(itemElement, "value", value, true);
100
101 String attrValue = "";
102 try {
103 // XXX A better way to format the output would be to use the
104 // 'type' value of the data objects.
105 double doubleVal = Double.valueOf(value);
106 Locale l = Resources.getLocale(meta);
107 NumberFormat nf = NumberFormat.getInstance(l);
108
109 attrValue = nf.format(doubleVal);
110 }
111 catch (NumberFormatException nfe) {
112 attrValue = Resources.getMsg(meta, value, value);
113 }
114
115 creator.addAttr(itemElement, "label", attrValue, true);
116
117 dataElement.appendChild(itemElement);
118 ui.appendChild(dataElement);
119 } 86 }
120 87
121 return ui; 88 return ui;
89 }
90
91
92 protected void appendStaticData(
93 FLYSArtifact flys,
94 CallMeta meta,
95 ElementCreator creator,
96 Element ui,
97 String name
98 ) {
99 StateData data = getData(flys, name);
100 String value = (data != null) ? (String) data.getValue() : null;
101
102 if (value == null) {
103 return;
104 }
105
106 logger.debug("Append element '" + name + "' (" + value + ")");
107
108 Element dataElement = creator.create("data");
109 creator.addAttr(dataElement, "name", name, true);
110 creator.addAttr(dataElement, "type", data.getType(), true);
111
112 Element itemElement = creator.create("item");
113 creator.addAttr(itemElement, "value", value, true);
114
115 String attrValue = "";
116 try {
117 // XXX A better way to format the output would be to use the
118 // 'type' value of the data objects.
119 double doubleVal = Double.valueOf(value);
120 Locale l = Resources.getLocale(meta);
121 NumberFormat nf = NumberFormat.getInstance(l);
122
123 attrValue = nf.format(doubleVal);
124 }
125 catch (NumberFormatException nfe) {
126 attrValue = Resources.getMsg(meta, value, value);
127 }
128
129 creator.addAttr(itemElement, "label", attrValue, true);
130
131 dataElement.appendChild(itemElement);
132 ui.appendChild(dataElement);
122 } 133 }
123 134
124 135
125 public Element describe( 136 public Element describe(
126 Artifact artifact, 137 Artifact artifact,
127 Document document, 138 Document document,
128 Node root, 139 Node root,
129 CallContext context, 140 CallContext context,
130 String uuid) 141 String uuid)
131 { 142 {
132 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( 143 ElementCreator creator = new ElementCreator(
133 document, 144 document,
134 ArtifactNamespaceContext.NAMESPACE_URI, 145 ArtifactNamespaceContext.NAMESPACE_URI,
135 ArtifactNamespaceContext.NAMESPACE_PREFIX); 146 ArtifactNamespaceContext.NAMESPACE_PREFIX);
136 147
137 Element ui = null; 148 Element ui = null;
203 * @param name The name of the amount of data. 214 * @param name The name of the amount of data.
204 * 215 *
205 * @return the root node of the item list. 216 * @return the root node of the item list.
206 */ 217 */
207 protected Element createData( 218 protected Element createData(
208 XMLUtils.ElementCreator cr, 219 ElementCreator cr,
209 Artifact artifact, 220 Artifact artifact,
210 StateData data, 221 StateData data,
211 CallContext context) 222 CallContext context)
212 { 223 {
213 Element select = ProtocolUtils.createArtNode( 224 Element select = ProtocolUtils.createArtNode(
236 * @param name The name of the amount of data. 247 * @param name The name of the amount of data.
237 * 248 *
238 * @return a list of items. 249 * @return a list of items.
239 */ 250 */
240 protected Element[] createItems( 251 protected Element[] createItems(
241 XMLUtils.ElementCreator cr, 252 ElementCreator cr,
242 Artifact artifact, 253 Artifact artifact,
243 String name, 254 String name,
244 CallContext context 255 CallContext context
245 ) { 256 ) {
246 return null; 257 return null;

http://dive4elements.wald.intevation.org