comparison flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java @ 65:8f719fa1a691

The output modes of an artifact are extracted from DESCRIBE document and put into the ArtifactDescription. flys-client/trunk@1547 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 23 Mar 2011 11:19:18 +0000
parents f983d5ce6402
children 27ffaf628b54
comparison
equal deleted inserted replaced
64:3d646d3e8e27 65:8f719fa1a691
17 import de.intevation.flys.client.shared.model.DataItem; 17 import de.intevation.flys.client.shared.model.DataItem;
18 import de.intevation.flys.client.shared.model.DataList; 18 import de.intevation.flys.client.shared.model.DataList;
19 import de.intevation.flys.client.shared.model.DefaultArtifactDescription; 19 import de.intevation.flys.client.shared.model.DefaultArtifactDescription;
20 import de.intevation.flys.client.shared.model.DefaultData; 20 import de.intevation.flys.client.shared.model.DefaultData;
21 import de.intevation.flys.client.shared.model.DefaultDataItem; 21 import de.intevation.flys.client.shared.model.DefaultDataItem;
22 import de.intevation.flys.client.shared.model.DefaultOutputMode;
23 import de.intevation.flys.client.shared.model.OutputMode;
22 24
23 25
24 /** 26 /**
25 * This factory class helps creating an {@link ArtifactDescription} based on the 27 * This factory class helps creating an {@link ArtifactDescription} based on the
26 * DESCRIBE document of an artifact returned by the artifact server. Use the 28 * DESCRIBE document of an artifact returned by the artifact server. Use the
56 58
57 Node currentState = ClientProtocolUtils.getCurrentState(doc); 59 Node currentState = ClientProtocolUtils.getCurrentState(doc);
58 Node staticNode = ClientProtocolUtils.getStaticUI(doc); 60 Node staticNode = ClientProtocolUtils.getStaticUI(doc);
59 Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc); 61 Node dynamicNode = ClientProtocolUtils.getDynamicUI(doc);
60 Node reachable = ClientProtocolUtils.getReachableStates(doc); 62 Node reachable = ClientProtocolUtils.getReachableStates(doc);
63 NodeList outputs = ClientProtocolUtils.getOutputModes(doc);
61 64
62 String state = (String) XMLUtils.xpath( 65 String state = (String) XMLUtils.xpath(
63 currentState, 66 currentState,
64 XPATH_STATE_NAME, 67 XPATH_STATE_NAME,
65 XPathConstants.STRING, 68 XPathConstants.STRING,
67 System.out.println("Current state name: " + state); 70 System.out.println("Current state name: " + state);
68 71
69 DataList currentData = extractCurrentData(dynamicNode, state); 72 DataList currentData = extractCurrentData(dynamicNode, state);
70 DataList[] old = extractOldData(staticNode); 73 DataList[] old = extractOldData(staticNode);
71 String[] states = extractReachableStates(reachable); 74 String[] states = extractReachableStates(reachable);
72 75 OutputMode[] outs = extractOutputModes(outputs);
73 return new DefaultArtifactDescription(old, currentData, state, states); 76
77 return new DefaultArtifactDescription(
78 old,
79 currentData,
80 state,
81 states,
82 outs);
74 } 83 }
75 84
76 85
77 /** 86 /**
78 * This method extracts the data that the user is able to enter in the 87 * This method extracts the data that the user is able to enter in the
303 states[i] = name; 312 states[i] = name;
304 } 313 }
305 314
306 return states; 315 return states;
307 } 316 }
317
318
319 /**
320 * This method extract available output modes of the the current artifact.
321 *
322 * @param outputs A list of nodes that contain information about output
323 * modes.
324 *
325 * @return an array of Output modes.
326 */
327 protected static OutputMode[] extractOutputModes(NodeList outputs) {
328 System.out.println("ArtifactDescriptionFactory - extractOutputModes()");
329
330 if (outputs == null || outputs.getLength() == 0) {
331 return null;
332 }
333
334 int size = outputs.getLength();
335
336 List<OutputMode> outs = new ArrayList<OutputMode>(size);
337
338 for (int i = 0; i < size; i++) {
339 Node out = outputs.item(i);
340
341 String name = XMLUtils.xpathString(
342 out, "@art:name", ArtifactNamespaceContext.INSTANCE);
343 String desc = XMLUtils.xpathString(
344 out, "@art:description", ArtifactNamespaceContext.INSTANCE);
345 String mimeType = XMLUtils.xpathString(
346 out, "@art:mime-type", ArtifactNamespaceContext.INSTANCE);
347
348 if (name != null) {
349 outs.add(new DefaultOutputMode(name, desc, mimeType));
350 }
351 else {
352 System.err.println("Found an invalid output mode.");
353 }
354 }
355
356 return (OutputMode[]) outs.toArray(new OutputMode[size]);
357 }
308 } 358 }
309 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 359 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org