comparison flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java @ 1367:ab8eb2f544f2

Replaced stdout and stderr logging with log4j loggers in server classes. flys-client/trunk@3069 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 25 Oct 2011 12:31:15 +0000
parents 6a1cd38e6e18
children df9baca681a0
comparison
equal deleted inserted replaced
1366:d0eb2202ffbe 1367:ab8eb2f544f2
7 7
8 import org.w3c.dom.Document; 8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element; 9 import org.w3c.dom.Element;
10 import org.w3c.dom.Node; 10 import org.w3c.dom.Node;
11 import org.w3c.dom.NodeList; 11 import org.w3c.dom.NodeList;
12
13 import org.apache.log4j.Logger;
12 14
13 import de.intevation.artifacts.common.ArtifactNamespaceContext; 15 import de.intevation.artifacts.common.ArtifactNamespaceContext;
14 import de.intevation.artifacts.common.utils.ClientProtocolUtils; 16 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
15 import de.intevation.artifacts.common.utils.XMLUtils; 17 import de.intevation.artifacts.common.utils.XMLUtils;
16 18
34 * 36 *
35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 37 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
36 */ 38 */
37 public class ArtifactDescriptionFactory { 39 public class ArtifactDescriptionFactory {
38 40
41 private static final Logger logger =
42 Logger.getLogger(ArtifactDescriptionFactory.class);
43
44
39 public static final String XPATH_STATE_NAME = "@art:name"; 45 public static final String XPATH_STATE_NAME = "@art:name";
40 46
41 public static final String XPATH_UIPROVIDER = "@art:uiprovider"; 47 public static final String XPATH_UIPROVIDER = "@art:uiprovider";
42 48
43 public static final String XPATH_REACHABLE_STATE = "art:state"; 49 public static final String XPATH_REACHABLE_STATE = "art:state";
58 * @param doc A DESCRIBE document. 64 * @param doc A DESCRIBE document.
59 * 65 *
60 * @return the {@link ArtifactDescription}. 66 * @return the {@link ArtifactDescription}.
61 */ 67 */
62 public static ArtifactDescription createArtifactDescription(Document doc) { 68 public static ArtifactDescription createArtifactDescription(Document doc) {
63 System.out.println("ArtifactDescriptionFactory - create()"); 69 logger.debug("ArtifactDescriptionFactory.createArtifactDescription");
64 70
65 Node currentState = ClientProtocolUtils.getCurrentState(doc); 71 Node currentState = ClientProtocolUtils.getCurrentState(doc);
66 Node staticNode = ClientProtocolUtils.getStaticUI(doc); 72 Node staticNode = ClientProtocolUtils.getStaticUI(doc);
67 Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc); 73 Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc);
68 Node reachable = ClientProtocolUtils.getReachableStates(doc); 74 Node reachable = ClientProtocolUtils.getReachableStates(doc);
71 String state = (String) XMLUtils.xpath( 77 String state = (String) XMLUtils.xpath(
72 currentState, 78 currentState,
73 XPATH_STATE_NAME, 79 XPATH_STATE_NAME,
74 XPathConstants.STRING, 80 XPathConstants.STRING,
75 ArtifactNamespaceContext.INSTANCE); 81 ArtifactNamespaceContext.INSTANCE);
76 System.out.println("Current state name: " + state); 82
83 logger.debug("Current state name: " + state);
77 84
78 DataList currentData = extractCurrentData(dynamicNode, state); 85 DataList currentData = extractCurrentData(dynamicNode, state);
79 DataList[] old = extractOldData(staticNode); 86 DataList[] old = extractOldData(staticNode);
80 String[] states = extractReachableStates(reachable); 87 String[] states = extractReachableStates(reachable);
81 OutputMode[] outs = extractOutputModes(outputs); 88 OutputMode[] outs = extractOutputModes(outputs);
101 * @return A {@link Data} object that represents the data which might be 108 * @return A {@link Data} object that represents the data which might be
102 * entered by the user in the current state or null, if no data might be 109 * entered by the user in the current state or null, if no data might be
103 * entered. 110 * entered.
104 */ 111 */
105 protected static DataList extractCurrentData(Node dynamicNode, String state) { 112 protected static DataList extractCurrentData(Node dynamicNode, String state) {
106 System.out.println("ArtifactDescriptionFactory - extractCurrentData()"); 113 logger.debug("ArtifactDescriptionFactory.extractCurrentData");
107 114
108 NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode); 115 NodeList data = ClientProtocolUtils.getSelectNode(dynamicNode);
109 String uiProvider = extractUIProvider(dynamicNode); 116 String uiProvider = extractUIProvider(dynamicNode);
110 117
111 if (data == null || data.getLength() == 0) { 118 if (data == null || data.getLength() == 0) {
139 * @param data The data object node. 146 * @param data The data object node.
140 * 147 *
141 * @return the default DataItem. 148 * @return the default DataItem.
142 */ 149 */
143 protected static DataItem extractDefaultDataItem(Node data) { 150 protected static DataItem extractDefaultDataItem(Node data) {
144 System.out.println( 151 logger.debug("ArtifactDescriptionFactory.extractDefaultDataItem");
145 "ArtifactDescriptionFactory - extractSelectedDataItem");
146 152
147 String value = XMLUtils.xpathString( 153 String value = XMLUtils.xpathString(
148 data, "@art:defaultValue", ArtifactNamespaceContext.INSTANCE); 154 data, "@art:defaultValue", ArtifactNamespaceContext.INSTANCE);
149 155
150 String label = XMLUtils.xpathString( 156 String label = XMLUtils.xpathString(
164 * @param items The items in the DESCRIBE document. 170 * @param items The items in the DESCRIBE document.
165 * 171 *
166 * @return the {@link DataItem}s. 172 * @return the {@link DataItem}s.
167 */ 173 */
168 protected static DataItem[] extractCurrentDataItems(NodeList items) { 174 protected static DataItem[] extractCurrentDataItems(NodeList items) {
169 System.out.println( 175 logger.debug("ArtifactDescriptionFactory.extractCurrentDataItems");
170 "ArtifactDescriptionFactory - extractCurrentDataItems()");
171 176
172 if (items == null || items.getLength() == 0) { 177 if (items == null || items.getLength() == 0) {
173 System.out.println("No data items found."); 178 logger.debug("No data items found.");
174 return null; 179 return null;
175 } 180 }
176 181
177 int count = items.getLength(); 182 int count = items.getLength();
178 183
197 return (DataItem[]) dataItems.toArray(new DataItem[count]); 202 return (DataItem[]) dataItems.toArray(new DataItem[count]);
198 } 203 }
199 204
200 205
201 protected static double[] extractMinMaxQValues(Node item) { 206 protected static double[] extractMinMaxQValues(Node item) {
202 System.out.println("ArtifactDescriptionFactory - extractMinMaxQValues"); 207 logger.debug("ArtifactDescriptionFactory.extractMinMaxQValues");
203 208
204 if (item == null) { 209 if (item == null) {
205 System.err.println("This node is empty - no min/max Q values."); 210 logger.debug("This node is empty - no min/max Q values.");
206 return null; 211 return null;
207 } 212 }
208 213
209 Node node = (Node) XMLUtils.xpath( 214 Node node = (Node) XMLUtils.xpath(
210 item, 215 item,
211 "art:range[@art:type='Q']", 216 "art:range[@art:type='Q']",
212 XPathConstants.NODE, 217 XPathConstants.NODE,
213 ArtifactNamespaceContext.INSTANCE); 218 ArtifactNamespaceContext.INSTANCE);
214 219
215 if (node == null) { 220 if (node == null) {
216 System.out.println("No min/max Q values found."); 221 logger.debug("No min/max Q values found.");
217 return null; 222 return null;
218 } 223 }
219 224
220 return extractMinMaxValues(node); 225 return extractMinMaxValues(node);
221 } 226 }
222 227
223 228
224 protected static double[] extractMinMaxWValues(Node item) { 229 protected static double[] extractMinMaxWValues(Node item) {
225 System.out.println("ArtifactDescriptionFactory - extractMinMaxWValues"); 230 logger.debug("ArtifactDescriptionFactory.extractMinMaxWValues");
226 231
227 if (item == null) { 232 if (item == null) {
228 System.err.println("This node is empty - no min/max W values."); 233 logger.debug("This node is empty - no min/max W values.");
229 return null; 234 return null;
230 } 235 }
231 236
232 Node node = (Node) XMLUtils.xpath( 237 Node node = (Node) XMLUtils.xpath(
233 item, 238 item,
234 "art:range[@art:type='W']", 239 "art:range[@art:type='W']",
235 XPathConstants.NODE, 240 XPathConstants.NODE,
236 ArtifactNamespaceContext.INSTANCE); 241 ArtifactNamespaceContext.INSTANCE);
237 242
238 if (node == null) { 243 if (node == null) {
239 System.out.println("No min/max W values found."); 244 logger.debug("No min/max W values found.");
240 return null; 245 return null;
241 } 246 }
242 247
243 return extractMinMaxValues(node); 248 return extractMinMaxValues(node);
244 } 249 }
245 250
246 251
247 protected static double[] extractMinMaxValues(Node node) { 252 protected static double[] extractMinMaxValues(Node node) {
248 System.out.println("ArtifactDescriptionFactory.extractMinMaxValues"); 253 logger.debug("ArtifactDescriptionFactory.extractMinMaxValues");
249 254
250 String minStr = XMLUtils.xpathString( 255 String minStr = XMLUtils.xpathString(
251 node, "art:min/text()", ArtifactNamespaceContext.INSTANCE); 256 node, "art:min/text()", ArtifactNamespaceContext.INSTANCE);
252 257
253 String maxStr = XMLUtils.xpathString( 258 String maxStr = XMLUtils.xpathString(
254 node, "art:max/text()", ArtifactNamespaceContext.INSTANCE); 259 node, "art:max/text()", ArtifactNamespaceContext.INSTANCE);
255 260
256 if (maxStr == null || minStr == null) { 261 if (maxStr == null || minStr == null) {
257 System.err.println("No min/max values found."); 262 logger.debug("No min/max values found.");
258 return null; 263 return null;
259 } 264 }
260 265
261 try { 266 try {
262 double min = Double.valueOf(minStr); 267 double min = Double.valueOf(minStr);
263 double max = Double.valueOf(maxStr); 268 double max = Double.valueOf(maxStr);
264 269
265 return new double[] { min, max }; 270 return new double[] { min, max };
266 } 271 }
267 catch (NumberFormatException nfe) { 272 catch (NumberFormatException nfe) {
268 System.err.println("Error while parsing min/max values."); 273 logger.debug("Error while parsing min/max values.");
269 } 274 }
270 275
271 return null; 276 return null;
272 } 277 }
273 278
279 * @param staticNode The static ui node of the DESCRIBE. 284 * @param staticNode The static ui node of the DESCRIBE.
280 * 285 *
281 * @return the DataList objects. 286 * @return the DataList objects.
282 */ 287 */
283 protected static DataList[] extractOldData(Node staticNode) { 288 protected static DataList[] extractOldData(Node staticNode) {
284 System.out.println("ArtifactDescriptionFactory - extractOldData()"); 289 logger.debug("ArtifactDescriptionFactory.extractOldData()");
285 290
286 NodeList stateNodes = (NodeList) XMLUtils.xpath( 291 NodeList stateNodes = (NodeList) XMLUtils.xpath(
287 staticNode, 292 staticNode,
288 XPATH_STATIC_STATE_NODE, 293 XPATH_STATIC_STATE_NODE,
289 XPathConstants.NODESET, 294 XPathConstants.NODESET,
290 ArtifactNamespaceContext.INSTANCE); 295 ArtifactNamespaceContext.INSTANCE);
291 296
292 if (stateNodes == null || stateNodes.getLength() == 0) { 297 if (stateNodes == null || stateNodes.getLength() == 0) {
293 System.out.println("No old items found."); 298 logger.debug("No old items found.");
294 return null; 299 return null;
295 } 300 }
296 301
297 int count = stateNodes.getLength(); 302 int count = stateNodes.getLength();
298 DataList[] data = new DataList[count]; 303 DataList[] data = new DataList[count];
354 XPATH_STATIC_ITEM_NODE, 359 XPATH_STATIC_ITEM_NODE,
355 XPathConstants.NODESET, 360 XPathConstants.NODESET,
356 ArtifactNamespaceContext.INSTANCE); 361 ArtifactNamespaceContext.INSTANCE);
357 362
358 if (itemList == null || itemList.getLength() == 0) { 363 if (itemList == null || itemList.getLength() == 0) {
359 System.out.println("No old data items found."); 364 logger.debug("No old data items found.");
360 return null; 365 return null;
361 } 366 }
362 367
363 int count = itemList.getLength(); 368 int count = itemList.getLength();
364 369
401 * @param reachable The reachable states node. 406 * @param reachable The reachable states node.
402 * 407 *
403 * @return an array with identifiers of reachable states. 408 * @return an array with identifiers of reachable states.
404 */ 409 */
405 protected static String[] extractReachableStates(Node reachable) { 410 protected static String[] extractReachableStates(Node reachable) {
406 System.out.println("ArtifactDescriptionFactory - extractReachableStates()"); 411 logger.debug("ArtifactDescriptionFactory.extractReachableStates()");
407 412
408 NodeList list = (NodeList) XMLUtils.xpath( 413 NodeList list = (NodeList) XMLUtils.xpath(
409 reachable, 414 reachable,
410 XPATH_REACHABLE_STATE, 415 XPATH_REACHABLE_STATE,
411 XPathConstants.NODESET, 416 XPathConstants.NODESET,
439 * modes. 444 * modes.
440 * 445 *
441 * @return an array of Output modes. 446 * @return an array of Output modes.
442 */ 447 */
443 protected static OutputMode[] extractOutputModes(NodeList outputs) { 448 protected static OutputMode[] extractOutputModes(NodeList outputs) {
444 System.out.println("ArtifactDescriptionFactory - extractOutputModes()"); 449 logger.debug("ArtifactDescriptionFactory.extractOutputModes");
445 450
446 if (outputs == null || outputs.getLength() == 0) { 451 if (outputs == null || outputs.getLength() == 0) {
447 return null; 452 return null;
448 } 453 }
449 454
463 468
464 if (name != null) { 469 if (name != null) {
465 outs.add(new DefaultOutputMode(name, desc, mimeType)); 470 outs.add(new DefaultOutputMode(name, desc, mimeType));
466 } 471 }
467 else { 472 else {
468 System.err.println("Found an invalid output mode."); 473 logger.debug("Found an invalid output mode.");
469 } 474 }
470 } 475 }
471 476
472 return (OutputMode[]) outs.toArray(new OutputMode[size]); 477 return (OutputMode[]) outs.toArray(new OutputMode[size]);
473 } 478 }
474 479
475 480
476 protected static Recommendation[] extractRecommendedArtifacts(Document doc){ 481 protected static Recommendation[] extractRecommendedArtifacts(Document doc){
477 System.out.println("ArtifactDescriptionFactory - extract recommended."); 482 logger.debug("ArtifactDescriptionFactory.extractRecommendedArtifacts.");
478 483
479 NodeList list = (NodeList) XMLUtils.xpath( 484 NodeList list = (NodeList) XMLUtils.xpath(
480 doc, 485 doc,
481 XPATH_RECOMMENDED_ARTIFACTS, 486 XPATH_RECOMMENDED_ARTIFACTS,
482 XPathConstants.NODESET, 487 XPathConstants.NODESET,

http://dive4elements.wald.intevation.org