comparison flys-client/src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java @ 870:d5fb88ba99d2

Display status message and progress information in the WSPLGEN loading panel. flys-client/trunk@2690 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 09 Sep 2011 15:08:15 +0000
parents c9549074ecd1
children ab8eb2f544f2
comparison
equal deleted inserted replaced
869:94d9c8353ca9 870:d5fb88ba99d2
1 package de.intevation.flys.client.server; 1 package de.intevation.flys.client.server;
2 2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.xml.xpath.XPathConstants;
7
3 import org.w3c.dom.Document; 8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10 import org.w3c.dom.NodeList;
4 11
5 import de.intevation.artifacts.common.utils.XMLUtils; 12 import de.intevation.artifacts.common.utils.XMLUtils;
6 import de.intevation.artifacts.common.ArtifactNamespaceContext; 13 import de.intevation.artifacts.common.ArtifactNamespaceContext;
7 14
8 import de.intevation.artifacts.httpclient.utils.ArtifactCreator; 15 import de.intevation.artifacts.httpclient.utils.ArtifactCreator;
9 16
10 import de.intevation.flys.client.shared.model.Artifact; 17 import de.intevation.flys.client.shared.model.Artifact;
18 import de.intevation.flys.client.shared.model.CalculationMessage;
11 import de.intevation.flys.client.shared.model.DefaultArtifact; 19 import de.intevation.flys.client.shared.model.DefaultArtifact;
12 import de.intevation.flys.client.shared.model.WINFOArtifact; 20 import de.intevation.flys.client.shared.model.WINFOArtifact;
13 21
14 22
15 /** 23 /**
30 /** The XPath to the artifact's name value.*/ 38 /** The XPath to the artifact's name value.*/
31 public static final String XPATH_NAME = "/art:result/art:name/@art:value"; 39 public static final String XPATH_NAME = "/art:result/art:name/@art:value";
32 40
33 /** The XPath to the value that determines if the artifact is processing in 41 /** The XPath to the value that determines if the artifact is processing in
34 * background.*/ 42 * background.*/
43 public static final String XPATH_BACKGROUND_VALUE =
44 "/art:result/art:background-processing/@art:value";
45
46 /** The XPath that points to the (if existing) background messages.*/
35 public static final String XPATH_BACKGROUND = 47 public static final String XPATH_BACKGROUND =
36 "/art:result/art:background-processing/@art:value"; 48 "/art:result/art:background-processing";
37 49
38 50
39 /** 51 /**
40 * Creates a new instance of an {@link ArtifactCreator}. 52 * Creates a new instance of an {@link ArtifactCreator}.
41 */ 53 */
80 92
81 String name = XMLUtils.xpathString( 93 String name = XMLUtils.xpathString(
82 doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE); 94 doc, XPATH_NAME, ArtifactNamespaceContext.INSTANCE);
83 95
84 String backgroundStr = XMLUtils.xpathString( 96 String backgroundStr = XMLUtils.xpathString(
85 doc, XPATH_BACKGROUND, ArtifactNamespaceContext.INSTANCE); 97 doc, XPATH_BACKGROUND_VALUE, ArtifactNamespaceContext.INSTANCE);
86 98
87 boolean background = false; 99 boolean background = false;
88 if (backgroundStr != null && backgroundStr.length() > 0) { 100 if (backgroundStr != null && backgroundStr.length() > 0) {
89 background = Boolean.valueOf(backgroundStr); 101 background = Boolean.valueOf(backgroundStr);
90 } 102 }
103
104 List<CalculationMessage> msg = parseBackgroundMessages(doc);
91 105
92 System.out.println("NEW Artifact UUID: " + uuid); 106 System.out.println("NEW Artifact UUID: " + uuid);
93 System.out.println("NEW Artifact HASH: " + hash); 107 System.out.println("NEW Artifact HASH: " + hash);
94 System.out.println("NEW Artifact NAME: " + name); 108 System.out.println("NEW Artifact NAME: " + name);
95 System.out.println("NEW Artifact IN BACKGROUND: " + background); 109 System.out.println("NEW Artifact IN BACKGROUND: " + background);
96 110
97 if (name == null) { 111 if (name == null) {
98 return new DefaultArtifact(uuid, hash, background); 112 return new DefaultArtifact(uuid, hash, background, msg);
99 } 113 }
100 114
101 name = name.trim(); 115 name = name.trim();
102 116
103 if (name.length() > 0 && name.equals("winfo")) { 117 if (name.length() > 0 && name.equals("winfo")) {
104 System.out.println("+++++ NEW WINFO ARTIFACT."); 118 System.out.println("+++++ NEW WINFO ARTIFACT.");
105 return new WINFOArtifact(uuid, hash, background); 119 return new WINFOArtifact(uuid, hash, background, msg);
106 } 120 }
107 121
108 return new DefaultArtifact(uuid, hash, background); 122 return new DefaultArtifact(uuid, hash, background, msg);
123 }
124
125
126 public static List<CalculationMessage> parseBackgroundMessages(Document d) {
127 NodeList list = (NodeList) XMLUtils.xpath(
128 d, XPATH_BACKGROUND, XPathConstants.NODESET,
129 ArtifactNamespaceContext.INSTANCE);
130
131 int len = list != null ? list.getLength() : 0;
132
133 System.out.println("Found " + len + " background messages.");
134
135 List<CalculationMessage> res = new ArrayList<CalculationMessage>(len);
136
137 for (int i = 0; i < len; i++) {
138 CalculationMessage msg = parseBackgroundMessage(
139 (Element) list.item(i));
140
141 if (msg != null) {
142 res.add(msg);
143 }
144 }
145
146 return res;
147 }
148
149
150 public static CalculationMessage parseBackgroundMessage(Element e) {
151 String steps = e.getAttribute("art:steps");
152 String currentStep = e.getAttribute("art:currentStep");
153 String message = e.getTextContent();
154
155 int lenCurStep = currentStep != null ? currentStep.length() : 0;
156 int lenSteps = steps != null ? steps.length() : 0;
157 int lenMessage = message != null ? message.length() : 0;
158
159 if (lenSteps > 0 && lenMessage > 0 && lenCurStep > 0) {
160 try {
161 return new CalculationMessage(
162 Integer.parseInt(steps),
163 Integer.parseInt(currentStep),
164 message);
165
166 }
167 catch (NumberFormatException nfe) {
168 nfe.printStackTrace();
169 }
170 }
171
172 return null;
109 } 173 }
110 } 174 }
111 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 175 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org