comparison gwt-client/src/main/java/org/dive4elements/river/client/server/ArtifactDescriptionFactory.java @ 9390:f575ff573cbb

"Name der Peilung" columname minfo.
author gernotbelger
date Thu, 09 Aug 2018 15:22:31 +0200
parents 5e38e2924c07
children
comparison
equal deleted inserted replaced
9389:63c086139391 9390:f575ff573cbb
11 import java.util.ArrayList; 11 import java.util.ArrayList;
12 import java.util.List; 12 import java.util.List;
13 13
14 import javax.xml.xpath.XPathConstants; 14 import javax.xml.xpath.XPathConstants;
15 15
16 import org.w3c.dom.Document;
17 import org.w3c.dom.Element;
18 import org.w3c.dom.Node;
19 import org.w3c.dom.NodeList;
20
21 import org.apache.log4j.Logger; 16 import org.apache.log4j.Logger;
22
23 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; 17 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
24 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; 18 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils;
25 import org.dive4elements.artifacts.common.utils.XMLUtils; 19 import org.dive4elements.artifacts.common.utils.XMLUtils;
26
27 import org.dive4elements.river.client.shared.model.ArtifactDescription; 20 import org.dive4elements.river.client.shared.model.ArtifactDescription;
28 import org.dive4elements.river.client.shared.model.DataItem; 21 import org.dive4elements.river.client.shared.model.DataItem;
29 import org.dive4elements.river.client.shared.model.DataList; 22 import org.dive4elements.river.client.shared.model.DataList;
30 import org.dive4elements.river.client.shared.model.DefaultArtifactDescription; 23 import org.dive4elements.river.client.shared.model.DefaultArtifactDescription;
31 import org.dive4elements.river.client.shared.model.DefaultData; 24 import org.dive4elements.river.client.shared.model.DefaultData;
32 import org.dive4elements.river.client.shared.model.DefaultDataItem; 25 import org.dive4elements.river.client.shared.model.DefaultDataItem;
33 import org.dive4elements.river.client.shared.model.DefaultOutputMode; 26 import org.dive4elements.river.client.shared.model.DefaultOutputMode;
34 import org.dive4elements.river.client.shared.model.DoubleArrayData; 27 import org.dive4elements.river.client.shared.model.DoubleArrayData;
35 import org.dive4elements.river.client.shared.model.DoubleRangeData; 28 import org.dive4elements.river.client.shared.model.DoubleRangeData;
36 import org.dive4elements.river.client.shared.model.IntegerArrayData; 29 import org.dive4elements.river.client.shared.model.IntegerArrayData;
30 import org.dive4elements.river.client.shared.model.IntegerOptionsData;
37 import org.dive4elements.river.client.shared.model.IntegerRangeData; 31 import org.dive4elements.river.client.shared.model.IntegerRangeData;
38 import org.dive4elements.river.client.shared.model.IntegerOptionsData;
39 import org.dive4elements.river.client.shared.model.LongRangeData; 32 import org.dive4elements.river.client.shared.model.LongRangeData;
40 import org.dive4elements.river.client.shared.model.OutputMode; 33 import org.dive4elements.river.client.shared.model.OutputMode;
41 import org.dive4elements.river.client.shared.model.Recommendation; 34 import org.dive4elements.river.client.shared.model.Recommendation;
42 import org.dive4elements.river.client.shared.model.WQDataItem; 35 import org.dive4elements.river.client.shared.model.WQDataItem;
43 36 import org.w3c.dom.Document;
37 import org.w3c.dom.Element;
38 import org.w3c.dom.Node;
39 import org.w3c.dom.NodeList;
44 40
45 /** 41 /**
46 * This factory class helps creating an {@link ArtifactDescription} based on the 42 * This factory class helps creating an {@link ArtifactDescription} based on the
47 * DESCRIBE document of an artifact returned by the artifact server. Use the 43 * DESCRIBE document of an artifact returned by the artifact server. Use the
48 * {@link createArtifactDescription(org.w3c.dom.Document)} method with the 44 * {@link createArtifactDescription(org.w3c.dom.Document)} method with the
50 * 46 *
51 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 47 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
52 */ 48 */
53 public class ArtifactDescriptionFactory { 49 public class ArtifactDescriptionFactory {
54 50
55 private static final Logger log = 51 private static final Logger log = Logger.getLogger(ArtifactDescriptionFactory.class);
56 Logger.getLogger(ArtifactDescriptionFactory.class);
57
58 52
59 public static final String XPATH_STATE_NAME = "@art:name"; 53 public static final String XPATH_STATE_NAME = "@art:name";
60 54
61 public static final String XPATH_UIPROVIDER = "@art:uiprovider"; 55 public static final String XPATH_UIPROVIDER = "@art:uiprovider";
62 56
68 62
69 public static final String XPATH_STATIC_DATA_NODE = "art:data"; 63 public static final String XPATH_STATIC_DATA_NODE = "art:data";
70 64
71 public static final String XPATH_STATIC_ITEM_NODE = "art:item"; 65 public static final String XPATH_STATIC_ITEM_NODE = "art:item";
72 66
73 public static final String XPATH_RECOMMENDED_ARTIFACTS = 67 public static final String XPATH_RECOMMENDED_ARTIFACTS = "/art:result/art:recommended-artifacts//*[@factory]";
74 "/art:result/art:recommended-artifacts//*[@factory]";
75 68
76 /** 69 /**
77 * This method creates the {@link ArtifactDescription} of the DESCRIBE 70 * This method creates the {@link ArtifactDescription} of the DESCRIBE
78 * document <i>doc</i>. 71 * document <i>doc</i>.
79 * 72 *
80 * @param doc A DESCRIBE document. 73 * @param doc
74 * A DESCRIBE document.
81 * 75 *
82 * @return the {@link ArtifactDescription}. 76 * @return the {@link ArtifactDescription}.
83 */ 77 */
84 public static ArtifactDescription createArtifactDescription(Document doc) { 78 public static ArtifactDescription createArtifactDescription(final Document doc) {
85 log.debug("ArtifactDescriptionFactory.createArtifactDescription"); 79 log.debug("ArtifactDescriptionFactory.createArtifactDescription");
86 80
87 Node currentState = ClientProtocolUtils.getCurrentState(doc); 81 final Node currentState = ClientProtocolUtils.getCurrentState(doc);
88 Node staticNode = ClientProtocolUtils.getStaticUI(doc); 82 final Node staticNode = ClientProtocolUtils.getStaticUI(doc);
89 Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc); 83 final Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc);
90 Node reachable = ClientProtocolUtils.getReachableStates(doc); 84 final Node reachable = ClientProtocolUtils.getReachableStates(doc);
91 NodeList outputs = ClientProtocolUtils.getOutputModes(doc); 85 final NodeList outputs = ClientProtocolUtils.getOutputModes(doc);
92 86
93 String state = (String) XMLUtils.xpath( 87 final String state = (String) XMLUtils.xpath(currentState, XPATH_STATE_NAME, XPathConstants.STRING, ArtifactNamespaceContext.INSTANCE);
94 currentState,
95 XPATH_STATE_NAME,
96 XPathConstants.STRING,
97 ArtifactNamespaceContext.INSTANCE);
98 88
99 log.debug("Current state name: " + state); 89 log.debug("Current state name: " + state);
100 90
101 DataList currentData = extractCurrentData(dynamicNode, state); 91 final DataList currentData = extractCurrentData(dynamicNode, state);
102 DataList[] old = extractOldData(staticNode); 92 final DataList[] old = extractOldData(staticNode);
103 String[] states = extractReachableStates(reachable); 93 final String[] states = extractReachableStates(reachable);
104 OutputMode[] outs = extractOutputModes(outputs); 94 final OutputMode[] outs = extractOutputModes(outputs);
105 Recommendation[] rec = extractRecommendedArtifacts(doc); 95 final Recommendation[] rec = extractRecommendedArtifacts(doc);
106 96
107 return new DefaultArtifactDescription( 97 return new DefaultArtifactDescription(old, currentData, state, states, outs, rec);
108 old, 98 }
109 currentData,
110 state,
111 states,
112 outs,
113 rec);
114 }
115
116 99
117 /** 100 /**
118 * This method extracts the data that the user is able to enter in the 101 * This method extracts the data that the user is able to enter in the
119 * current state of the artifact. 102 * current state of the artifact.
120 * 103 *
121 * @param dynamicNode The dynamic node of the DESCRIBE document. 104 * @param dynamicNode
122 * @param state The name of the current state. 105 * The dynamic node of the DESCRIBE document.
106 * @param state
107 * The name of the current state.
123 * 108 *
124 * @return A {@link Data} object that represents the data which might be 109 * @return A {@link Data} object that represents the data which might be
125 * entered by the user in the current state or null, if no data might be 110 * entered by the user in the current state or null, if no data might be
126 * entered. 111 * entered.
127 */ 112 */
128 protected static DataList extractCurrentData( 113 protected static DataList extractCurrentData(final Node dynamicNode, final String state) {
129 Node dynamicNode,
130 String state
131 ) {
132 log.debug("ArtifactDescriptionFactory.extractCurrentData"); 114 log.debug("ArtifactDescriptionFactory.extractCurrentData");
133 115
134 NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode); 116 final NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode);
135 String help = extractHelpText(dynamicNode); 117 final String help = extractHelpText(dynamicNode);
136 String uiProvider = extractUIProvider(dynamicNode); 118 final String uiProvider = extractUIProvider(dynamicNode);
137 119
138 if (data == null || data.getLength() == 0) { 120 if (data == null || data.getLength() == 0) {
139 return null; 121 return null;
140 } 122 }
141 123
142 int dataNum = data.getLength(); 124 final int dataNum = data.getLength();
143 DataList list = new DataList(state, dataNum, uiProvider, null, help); 125 final DataList list = new DataList(state, dataNum, uiProvider, null, help);
144 126
145 for (int i = 0; i < dataNum; i++) { 127 for (int i = 0; i < dataNum; i++) {
146 Element d = (Element) data.item(i); 128 final Element d = (Element) data.item(i);
147 String label = ClientProtocolUtils.getLabel(d); 129 final String label = ClientProtocolUtils.getLabel(d);
148 String name = XMLUtils.xpathString( 130 final String name = XMLUtils.xpathString(d, "@art:name", ArtifactNamespaceContext.INSTANCE);
149 d, "@art:name", ArtifactNamespaceContext.INSTANCE); 131 final String type = XMLUtils.xpathString(d, "@art:type", ArtifactNamespaceContext.INSTANCE);
150 String type = XMLUtils.xpathString(
151 d, "@art:type", ArtifactNamespaceContext.INSTANCE);
152 132
153 log.debug("Create new IntegerRangeData object for: " + name); 133 log.debug("Create new IntegerRangeData object for: " + name);
154 log.debug("New Data is from type: " + type); 134 log.debug("New Data is from type: " + type);
155 135
156 // TODO replace with DataFactory. 136 // TODO replace with DataFactory.
157 137
158 if (type == null || type.length() == 0) { 138 if (type == null || type.length() == 0) {
159 NodeList choices = ClientProtocolUtils.getItemNodes(d); 139 final NodeList choices = ClientProtocolUtils.getItemNodes(d);
160 DataItem[] dataItems = extractCurrentDataItems(choices); 140 final DataItem[] dataItems = extractCurrentDataItems(choices);
161 DataItem def = extractDefaultDataItem(d); 141 final DataItem def = extractDefaultDataItem(d);
142
143 list.add(new DefaultData(name, label, null, dataItems, def));
144 } else if (type.equals("intrange")) {
145 final String min = ClientProtocolUtils.getMinNode(d);
146 final String max = ClientProtocolUtils.getMaxNode(d);
147
148 final String defMin = ClientProtocolUtils.getDefMin(d);
149 final String defMax = ClientProtocolUtils.getDefMax(d);
150
151 try {
152 final int lower = Integer.parseInt(min);
153 final int upper = Integer.parseInt(max);
154
155 if (defMin != null && defMax != null) {
156 list.add(new IntegerRangeData(name, label, lower, upper, Integer.parseInt(defMin), Integer.parseInt(defMax)));
157 } else {
158 list.add(new IntegerRangeData(name, label, lower, upper));
159 }
160 }
161 catch (final NumberFormatException nfe) {
162 log.warn("NumberFormatException: ", nfe);
163 }
164 } else if (type.equals("longrange")) {
165 final String min = ClientProtocolUtils.getMinNode(d);
166 final String max = ClientProtocolUtils.getMaxNode(d);
167
168 final String defMin = ClientProtocolUtils.getDefMin(d);
169 final String defMax = ClientProtocolUtils.getDefMax(d);
170
171 try {
172 final long lower = Long.valueOf(min);
173 final long upper = Long.valueOf(max);
174
175 if (defMin != null && defMax != null) {
176 list.add(new LongRangeData(name, label, lower, upper, Long.valueOf(defMin), Long.valueOf(defMax)));
177 }
178 }
179 catch (final NumberFormatException nfe) {
180 log.warn("NumberFormatException: ", nfe);
181 }
182 } else if (type.equals("intarray")) {
183 list.add(new IntegerArrayData(name, label, null));
184 } else if (type.equals("intoptions") && uiProvider.startsWith("parameter-matrix")// uiProvider.equals("parameter-matrix") // what the...? used to be
185 // "equals", but column-name for "itemname" refactoring created new
186 // UIProviderFactory-Names starting with "parameter-matrix"
187 ) {
188 list.add(DataFactory.createIntegerOptionsData(d, name, label));
189 } else if (type.equals("options")) {
190 list.add(DataFactory.createStringOptionsData(d, name, label));
191 } else if (type.equals("intoptions")) {
192 final NodeList choices = ClientProtocolUtils.getItemNodes(d);
193 final DataItem[] opts = extractCurrentDataItems(choices);
194
195 list.add(new IntegerOptionsData(name, label, opts));
196 } else if (type.equals("doublearray")) {
197 list.add(new DoubleArrayData(name, label, null));
198 } else if (type.equals("multiattribute")) {
199 list.add(DataFactory.createMultiAttributeData(d, name, label));
200 } else {
201 log.warn("Unrecognized Dynamic data type.");
202 final NodeList choices = ClientProtocolUtils.getItemNodes(d);
203 final DataItem[] dataItems = extractCurrentDataItems(choices);
204 final DataItem def = extractDefaultDataItem(d);
205
206 final String min = ClientProtocolUtils.getMinNode(d);
207 final String max = ClientProtocolUtils.getMaxNode(d);
208 if (min != null && max != null) {
209 list.add(new DoubleRangeData(name, label, Double.valueOf(min), Double.valueOf(max), Double.valueOf(min), Double.valueOf(max)));
210 }
162 211
163 list.add(new DefaultData(name, label, null, dataItems, def)); 212 list.add(new DefaultData(name, label, null, dataItems, def));
164 } 213 }
165 else if (type.equals("intrange")) {
166 String min = ClientProtocolUtils.getMinNode(d);
167 String max = ClientProtocolUtils.getMaxNode(d);
168
169 String defMin = ClientProtocolUtils.getDefMin(d);
170 String defMax = ClientProtocolUtils.getDefMax(d);
171
172 try {
173 int lower = Integer.parseInt(min);
174 int upper = Integer.parseInt(max);
175
176 if (defMin != null && defMax != null) {
177 list.add(new IntegerRangeData(
178 name, label,
179 lower, upper,
180 Integer.parseInt(defMin),
181 Integer.parseInt(defMax)));
182 }
183 else {
184 list.add(
185 new IntegerRangeData(name, label, lower, upper));
186 }
187 }
188 catch (NumberFormatException nfe) {
189 log.warn("NumberFormatException: ", nfe);
190 }
191 }
192 else if (type.equals("longrange")) {
193 String min = ClientProtocolUtils.getMinNode(d);
194 String max = ClientProtocolUtils.getMaxNode(d);
195
196 String defMin = ClientProtocolUtils.getDefMin(d);
197 String defMax = ClientProtocolUtils.getDefMax(d);
198
199 try {
200 long lower = Long.valueOf(min);
201 long upper = Long.valueOf(max);
202
203 if (defMin != null && defMax != null) {
204 list.add(new LongRangeData(
205 name, label,
206 lower, upper,
207 Long.valueOf(defMin),
208 Long.valueOf(defMax)));
209 }
210 }
211 catch (NumberFormatException nfe) {
212 log.warn("NumberFormatException: ", nfe);
213 }
214 }
215 else if (type.equals("intarray")) {
216 list.add(new IntegerArrayData(name, label, null));
217 }
218 else if (type.equals("intoptions")
219 && uiProvider.equals("parameter-matrix")
220 ) {
221 list.add(DataFactory.createIntegerOptionsData(d, name, label));
222 }
223 else if (type.equals("options")) {
224 list.add(DataFactory.createStringOptionsData(d, name, label));
225 }
226 else if (type.equals("intoptions")) {
227 NodeList choices = ClientProtocolUtils.getItemNodes(d);
228 DataItem[] opts = extractCurrentDataItems(choices);
229
230 list.add(new IntegerOptionsData(name, label, opts));
231 }
232 else if (type.equals("doublearray")) {
233 list.add(new DoubleArrayData(name, label, null));
234 }
235 else if (type.equals("multiattribute")) {
236 list.add(DataFactory.createMultiAttributeData(d, name, label));
237 }
238 else {
239 log.warn("Unrecognized Dynamic data type.");
240 NodeList choices = ClientProtocolUtils.getItemNodes(d);
241 DataItem[] dataItems = extractCurrentDataItems(choices);
242 DataItem def = extractDefaultDataItem(d);
243
244 String min = ClientProtocolUtils.getMinNode(d);
245 String max = ClientProtocolUtils.getMaxNode(d);
246 if (min != null && max != null) {
247 list.add(new DoubleRangeData(
248 name, label,
249 Double.valueOf(min), Double.valueOf(max),
250 Double.valueOf(min), Double.valueOf(max)));
251 }
252
253 list.add(new DefaultData(name, label, null, dataItems, def));
254 }
255 214
256 } 215 }
257 216
258 return list; 217 return list;
259 } 218 }
260 219
261
262 /** 220 /**
263 * This method extracts the default value of a Data object. 221 * This method extracts the default value of a Data object.
264 * 222 *
265 * @param data The data object node. 223 * @param data
224 * The data object node.
266 * 225 *
267 * @return the default DataItem. 226 * @return the default DataItem.
268 */ 227 */
269 protected static DataItem extractDefaultDataItem(Node data) { 228 protected static DataItem extractDefaultDataItem(final Node data) {
270 log.debug("ArtifactDescriptionFactory.extractDefaultDataItem"); 229 log.debug("ArtifactDescriptionFactory.extractDefaultDataItem");
271 230
272 String value = XMLUtils.xpathString( 231 final String value = XMLUtils.xpathString(data, "@art:defaultValue", ArtifactNamespaceContext.INSTANCE);
273 data, "@art:defaultValue", ArtifactNamespaceContext.INSTANCE); 232
274 233 final String label = XMLUtils.xpathString(data, "@art:defaultLabel", ArtifactNamespaceContext.INSTANCE);
275 String label = XMLUtils.xpathString(
276 data, "@art:defaultLabel", ArtifactNamespaceContext.INSTANCE);
277 234
278 if (value != null && label != null) { 235 if (value != null && label != null) {
279 return new DefaultDataItem(label, null, value); 236 return new DefaultDataItem(label, null, value);
280 } 237 }
281 238
282 return null; 239 return null;
283 } 240 }
284 241
285
286 /** 242 /**
287 * This method extract the {@link DataItem}s of the DESCRIBE document. 243 * This method extract the {@link DataItem}s of the DESCRIBE document.
288 * 244 *
289 * @param items The items in the DESCRIBE document. 245 * @param items
246 * The items in the DESCRIBE document.
290 * 247 *
291 * @return the {@link DataItem}s. 248 * @return the {@link DataItem}s.
292 */ 249 */
293 protected static DataItem[] extractCurrentDataItems(NodeList items) { 250 protected static DataItem[] extractCurrentDataItems(final NodeList items) {
294 log.debug("ArtifactDescriptionFactory.extractCurrentDataItems"); 251 log.debug("ArtifactDescriptionFactory.extractCurrentDataItems");
295 252
296 if (items == null || items.getLength() == 0) { 253 if (items == null || items.getLength() == 0) {
297 log.debug("No data items found."); 254 log.debug("No data items found.");
298 return null; 255 return null;
299 } 256 }
300 257
301 int count = items.getLength(); 258 final int count = items.getLength();
302 259
303 List<DataItem> dataItems = new ArrayList<DataItem>(count); 260 final List<DataItem> dataItems = new ArrayList<DataItem>(count);
304 261
305 for (int i = 0; i < count; i++) { 262 for (int i = 0; i < count; i++) {
306 Node item = items.item(i); 263 final Node item = items.item(i);
307 String label = ClientProtocolUtils.getLabel(item); 264 final String label = ClientProtocolUtils.getLabel(item);
308 String value = ClientProtocolUtils.getValue(item); 265 final String value = ClientProtocolUtils.getValue(item);
309 266
310 double[] mmQ = extractMinMaxQValues(item); 267 final double[] mmQ = extractMinMaxQValues(item);
311 double[] mmW = extractMinMaxWValues(item); 268 final double[] mmW = extractMinMaxWValues(item);
312 269
313 if (mmQ != null || mmW != null) { 270 if (mmQ != null || mmW != null) {
314 dataItems.add(new WQDataItem(label, null, value, mmQ, mmW)); 271 dataItems.add(new WQDataItem(label, null, value, mmQ, mmW));
315 } 272 } else {
316 else {
317 dataItems.add(new DefaultDataItem(label, null, value)); 273 dataItems.add(new DefaultDataItem(label, null, value));
318 } 274 }
319 } 275 }
320 276
321 return dataItems.toArray(new DataItem[count]); 277 return dataItems.toArray(new DataItem[count]);
322 } 278 }
323 279
324 280 protected static double[] extractMinMaxQValues(final Node item) {
325 protected static double[] extractMinMaxQValues(Node item) {
326 log.debug("ArtifactDescriptionFactory.extractMinMaxQValues"); 281 log.debug("ArtifactDescriptionFactory.extractMinMaxQValues");
327 282
328 if (item == null) { 283 if (item == null) {
329 log.debug("This node is empty - no min/max Q values."); 284 log.debug("This node is empty - no min/max Q values.");
330 return null; 285 return null;
331 } 286 }
332 287
333 Node node = (Node) XMLUtils.xpath( 288 final Node node = (Node) XMLUtils.xpath(item, "art:range[@art:type='Q']", XPathConstants.NODE, ArtifactNamespaceContext.INSTANCE);
334 item,
335 "art:range[@art:type='Q']",
336 XPathConstants.NODE,
337 ArtifactNamespaceContext.INSTANCE);
338 289
339 if (node == null) { 290 if (node == null) {
340 log.debug("No min/max Q values found."); 291 log.debug("No min/max Q values found.");
341 return null; 292 return null;
342 } 293 }
343 294
344 return extractMinMaxValues(node); 295 return extractMinMaxValues(node);
345 } 296 }
346 297
347 298 protected static double[] extractMinMaxWValues(final Node item) {
348 protected static double[] extractMinMaxWValues(Node item) {
349 log.debug("ArtifactDescriptionFactory.extractMinMaxWValues"); 299 log.debug("ArtifactDescriptionFactory.extractMinMaxWValues");
350 300
351 if (item == null) { 301 if (item == null) {
352 log.debug("This node is empty - no min/max W values."); 302 log.debug("This node is empty - no min/max W values.");
353 return null; 303 return null;
354 } 304 }
355 305
356 Node node = (Node) XMLUtils.xpath( 306 final Node node = (Node) XMLUtils.xpath(item, "art:range[@art:type='W']", XPathConstants.NODE, ArtifactNamespaceContext.INSTANCE);
357 item,
358 "art:range[@art:type='W']",
359 XPathConstants.NODE,
360 ArtifactNamespaceContext.INSTANCE);
361 307
362 if (node == null) { 308 if (node == null) {
363 log.debug("No min/max W values found."); 309 log.debug("No min/max W values found.");
364 return null; 310 return null;
365 } 311 }
366 312
367 return extractMinMaxValues(node); 313 return extractMinMaxValues(node);
368 } 314 }
369 315
370 316 protected static double[] extractMinMaxValues(final Node node) {
371 protected static double[] extractMinMaxValues(Node node) {
372 log.debug("ArtifactDescriptionFactory.extractMinMaxValues"); 317 log.debug("ArtifactDescriptionFactory.extractMinMaxValues");
373 318
374 String minStr = XMLUtils.xpathString( 319 final String minStr = XMLUtils.xpathString(node, "art:min/text()", ArtifactNamespaceContext.INSTANCE);
375 node, "art:min/text()", ArtifactNamespaceContext.INSTANCE); 320
376 321 final String maxStr = XMLUtils.xpathString(node, "art:max/text()", ArtifactNamespaceContext.INSTANCE);
377 String maxStr = XMLUtils.xpathString(
378 node, "art:max/text()", ArtifactNamespaceContext.INSTANCE);
379 322
380 if (maxStr == null || minStr == null) { 323 if (maxStr == null || minStr == null) {
381 log.debug("No min/max values found."); 324 log.debug("No min/max values found.");
382 return null; 325 return null;
383 } 326 }
384 327
385 try { 328 try {
386 double min = Double.valueOf(minStr); 329 final double min = Double.valueOf(minStr);
387 double max = Double.valueOf(maxStr); 330 final double max = Double.valueOf(maxStr);
388 331
389 return new double[] { min, max }; 332 return new double[] { min, max };
390 } 333 }
391 catch (NumberFormatException nfe) { 334 catch (final NumberFormatException nfe) {
392 log.debug("Error while parsing min/max values."); 335 log.debug("Error while parsing min/max values.");
393 } 336 }
394 337
395 return null; 338 return null;
396 } 339 }
397
398 340
399 /** 341 /**
400 * This method extracts the data objects from the data node of the static ui 342 * This method extracts the data objects from the data node of the static ui
401 * part of the DESCRIBE document. 343 * part of the DESCRIBE document.
402 * 344 *
403 * @param staticNode The static ui node of the DESCRIBE. 345 * @param staticNode
346 * The static ui node of the DESCRIBE.
404 * 347 *
405 * @return the DataList objects. 348 * @return the DataList objects.
406 */ 349 */
407 protected static DataList[] extractOldData(Node staticNode) { 350 protected static DataList[] extractOldData(final Node staticNode) {
408 log.debug("ArtifactDescriptionFactory.extractOldData()"); 351 log.debug("ArtifactDescriptionFactory.extractOldData()");
409 352
410 NodeList stateNodes = (NodeList) XMLUtils.xpath( 353 final NodeList stateNodes = (NodeList) XMLUtils.xpath(staticNode, XPATH_STATIC_STATE_NODE, XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);
411 staticNode,
412 XPATH_STATIC_STATE_NODE,
413 XPathConstants.NODESET,
414 ArtifactNamespaceContext.INSTANCE);
415 354
416 if (stateNodes == null || stateNodes.getLength() == 0) { 355 if (stateNodes == null || stateNodes.getLength() == 0) {
417 log.debug("No old items found."); 356 log.debug("No old items found.");
418 return null; 357 return null;
419 } 358 }
420 359
421 int count = stateNodes.getLength(); 360 final int count = stateNodes.getLength();
422 DataList[] data = new DataList[count]; 361 final DataList[] data = new DataList[count];
423 362
424 for (int i = 0; i < count; i++) { 363 for (int i = 0; i < count; i++) {
425 Node tmp = stateNodes.item(i); 364 final Node tmp = stateNodes.item(i);
426 365
427 String name = XMLUtils.xpathString( 366 final String name = XMLUtils.xpathString(tmp, "@art:name", ArtifactNamespaceContext.INSTANCE);
428 tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); 367 final String uiprovider = XMLUtils.xpathString(tmp, "@art:uiprovider", ArtifactNamespaceContext.INSTANCE);
429 String uiprovider = XMLUtils.xpathString( 368 final String label = XMLUtils.xpathString(tmp, "@art:label", ArtifactNamespaceContext.INSTANCE);
430 tmp, "@art:uiprovider", ArtifactNamespaceContext.INSTANCE); 369 final String help = XMLUtils.xpathString(tmp, "@art:helpText", ArtifactNamespaceContext.INSTANCE);
431 String label = XMLUtils.xpathString( 370
432 tmp, "@art:label", ArtifactNamespaceContext.INSTANCE); 371 final NodeList dataNodes = (NodeList) XMLUtils.xpath(tmp, XPATH_STATIC_DATA_NODE, XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);
433 String help = XMLUtils.xpathString(
434 tmp, "@art:helpText", ArtifactNamespaceContext.INSTANCE);
435
436 NodeList dataNodes = (NodeList) XMLUtils.xpath(
437 tmp,
438 XPATH_STATIC_DATA_NODE,
439 XPathConstants.NODESET,
440 ArtifactNamespaceContext.INSTANCE);
441 372
442 if (dataNodes == null || dataNodes.getLength() == 0) { 373 if (dataNodes == null || dataNodes.getLength() == 0) {
443 continue; 374 continue;
444 } 375 }
445 376
446 int size = dataNodes.getLength(); 377 final int size = dataNodes.getLength();
447 DataList list = new DataList(name, size, uiprovider, label, help); 378 final DataList list = new DataList(name, size, uiprovider, label, help);
448 379
449 for (int j = 0; j < size; j++) { 380 for (int j = 0; j < size; j++) {
450 Node dataNode = dataNodes.item(j); 381 final Node dataNode = dataNodes.item(j);
451 382
452 list.add(DataFactory.createDataFromElement((Element) dataNode)); 383 list.add(DataFactory.createDataFromElement((Element) dataNode));
453 384
454 data[i] = list; 385 data[i] = list;
455 } 386 }
456 } 387 }
457 388
458 return data; 389 return data;
459 } 390 }
460 391
461
462 /** 392 /**
463 * This method extracts the UIProvider specified by the data node. 393 * This method extracts the UIProvider specified by the data node.
464 * 394 *
465 * @param data The data node. 395 * @param data
396 * The data node.
466 * 397 *
467 * @return the UIProvider that is specified in the data node. 398 * @return the UIProvider that is specified in the data node.
468 */ 399 */
469 protected static String extractUIProvider(Node ui) { 400 protected static String extractUIProvider(final Node ui) {
470 return (String) XMLUtils.xpath( 401 return (String) XMLUtils.xpath(ui, XPATH_UIPROVIDER, XPathConstants.STRING, ArtifactNamespaceContext.INSTANCE);
471 ui, 402 }
472 XPATH_UIPROVIDER,
473 XPathConstants.STRING,
474 ArtifactNamespaceContext.INSTANCE);
475 }
476
477 403
478 /** 404 /**
479 * This method extracts the help text specified by the data node. 405 * This method extracts the help text specified by the data node.
480 * 406 *
481 * @param ui The data node. 407 * @param ui
408 * The data node.
482 * 409 *
483 * @return the help text. 410 * @return the help text.
484 */ 411 */
485 protected static String extractHelpText(Node ui) { 412 protected static String extractHelpText(final Node ui) {
486 return (String) XMLUtils.xpath( 413 return (String) XMLUtils.xpath(ui, XPATH_HELP_TEXT, XPathConstants.STRING, ArtifactNamespaceContext.INSTANCE);
487 ui, 414 }
488 XPATH_HELP_TEXT,
489 XPathConstants.STRING,
490 ArtifactNamespaceContext.INSTANCE);
491 }
492
493 415
494 /** 416 /**
495 * This method extracts the reachable states of the current artifact. 417 * This method extracts the reachable states of the current artifact.
496 * 418 *
497 * @param reachable The reachable states node. 419 * @param reachable
420 * The reachable states node.
498 * 421 *
499 * @return an array with identifiers of reachable states. 422 * @return an array with identifiers of reachable states.
500 */ 423 */
501 protected static String[] extractReachableStates(Node reachable) { 424 protected static String[] extractReachableStates(final Node reachable) {
502 log.debug("ArtifactDescriptionFactory.extractReachableStates()"); 425 log.debug("ArtifactDescriptionFactory.extractReachableStates()");
503 426
504 NodeList list = (NodeList) XMLUtils.xpath( 427 final NodeList list = (NodeList) XMLUtils.xpath(reachable, XPATH_REACHABLE_STATE, XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);
505 reachable,
506 XPATH_REACHABLE_STATE,
507 XPathConstants.NODESET,
508 ArtifactNamespaceContext.INSTANCE);
509 428
510 if (list == null || list.getLength() == 0) { 429 if (list == null || list.getLength() == 0) {
511 return null; 430 return null;
512 } 431 }
513 432
514 int count = list.getLength(); 433 final int count = list.getLength();
515 434
516 String[] states = new String[count]; 435 final String[] states = new String[count];
517 436
518 for (int i = 0; i < count; i++) { 437 for (int i = 0; i < count; i++) {
519 Node state = list.item(i); 438 final Node state = list.item(i);
520 439
521 String name = XMLUtils.xpathString( 440 final String name = XMLUtils.xpathString(state, "@art:name", ArtifactNamespaceContext.INSTANCE);
522 state, "@art:name", ArtifactNamespaceContext.INSTANCE);
523 441
524 states[i] = name; 442 states[i] = name;
525 } 443 }
526 444
527 return states; 445 return states;
528 } 446 }
529 447
530
531 /** 448 /**
532 * This method extract available output modes of the the current artifact. 449 * This method extract available output modes of the the current artifact.
533 * 450 *
534 * @param outputs A list of nodes that contain information about output 451 * @param outputs
535 * modes. 452 * A list of nodes that contain information about output
453 * modes.
536 * 454 *
537 * @return an array of Output modes. 455 * @return an array of Output modes.
538 */ 456 */
539 protected static OutputMode[] extractOutputModes(NodeList outputs) { 457 protected static OutputMode[] extractOutputModes(final NodeList outputs) {
540 log.debug("ArtifactDescriptionFactory.extractOutputModes"); 458 log.debug("ArtifactDescriptionFactory.extractOutputModes");
541 459
542 if (outputs == null || outputs.getLength() == 0) { 460 if (outputs == null || outputs.getLength() == 0) {
543 return null; 461 return null;
544 } 462 }
545 463
546 int size = outputs.getLength(); 464 final int size = outputs.getLength();
547 465
548 List<OutputMode> outs = new ArrayList<OutputMode>(size); 466 final List<OutputMode> outs = new ArrayList<OutputMode>(size);
549 467
550 for (int i = 0; i < size; i++) { 468 for (int i = 0; i < size; i++) {
551 Node out = outputs.item(i); 469 final Node out = outputs.item(i);
552 470
553 String name = XMLUtils.xpathString( 471 final String name = XMLUtils.xpathString(out, "@art:name", ArtifactNamespaceContext.INSTANCE);
554 out, "@art:name", ArtifactNamespaceContext.INSTANCE); 472 final String desc = XMLUtils.xpathString(out, "@art:description", ArtifactNamespaceContext.INSTANCE);
555 String desc = XMLUtils.xpathString( 473 final String mimeType = XMLUtils.xpathString(out, "@art:mime-type", ArtifactNamespaceContext.INSTANCE);
556 out, "@art:description", ArtifactNamespaceContext.INSTANCE);
557 String mimeType = XMLUtils.xpathString(
558 out, "@art:mime-type", ArtifactNamespaceContext.INSTANCE);
559 474
560 if (name != null) { 475 if (name != null) {
561 outs.add(new DefaultOutputMode(name, desc, mimeType)); 476 outs.add(new DefaultOutputMode(name, desc, mimeType));
562 } 477 } else {
563 else {
564 log.debug("Found an invalid output mode."); 478 log.debug("Found an invalid output mode.");
565 } 479 }
566 } 480 }
567 481
568 return (OutputMode[]) outs.toArray(new OutputMode[size]); 482 return outs.toArray(new OutputMode[size]);
569 } 483 }
570 484
571 485 protected static Recommendation[] extractRecommendedArtifacts(final Document doc) {
572 protected static Recommendation[] extractRecommendedArtifacts(Document doc){
573 log.debug("ArtifactDescriptionFactory.extractRecommendedArtifacts."); 486 log.debug("ArtifactDescriptionFactory.extractRecommendedArtifacts.");
574 487
575 NodeList list = (NodeList) XMLUtils.xpath( 488 final NodeList list = (NodeList) XMLUtils.xpath(doc, XPATH_RECOMMENDED_ARTIFACTS, XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);
576 doc, 489
577 XPATH_RECOMMENDED_ARTIFACTS, 490 final int num = list != null ? list.getLength() : 0;
578 XPathConstants.NODESET, 491
579 ArtifactNamespaceContext.INSTANCE); 492 final Recommendation[] rec = new Recommendation[num];
580
581 int num = list != null ? list.getLength() : 0;
582
583 Recommendation[] rec = new Recommendation[num];
584 493
585 for (int i = 0; i < num; i++) { 494 for (int i = 0; i < num; i++) {
586 Element e = (Element) list.item(i); 495 final Element e = (Element) list.item(i);
587 String factory = e.getAttribute("factory"); 496 final String factory = e.getAttribute("factory");
588 String index = e.getAttribute("ids"); 497 final String index = e.getAttribute("ids");
589 String targetOut = e.getAttribute("target_out"); 498 final String targetOut = e.getAttribute("target_out");
590 499
591 if (factory != null && factory.length() > 0) { 500 if (factory != null && factory.length() > 0) {
592 log.debug("Adding Recommendation. Factory: " + factory + 501 log.debug("Adding Recommendation. Factory: " + factory + " IDs: " + index + " target out " + targetOut);
593 " IDs: " + index + " target out " + targetOut); 502 rec[i] = new Recommendation(factory, index, null, null, targetOut);
594 rec[i] = new Recommendation(
595 factory, index, null, null, targetOut);
596 } 503 }
597 } 504 }
598 505
599 return rec; 506 return rec;
600 } 507 }

http://dive4elements.wald.intevation.org