Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java @ 59:2c5d8f5bced1
Outputs integrated in describe and XForms integrated
gnv-artifacts/trunk@41 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 08 Sep 2009 16:21:46 +0000 |
parents | f31343d80d53 |
children | 5f47881f7c97 |
comparison
equal
deleted
inserted
replaced
58:f31343d80d53 | 59:2c5d8f5bced1 |
---|---|
9 import java.util.Iterator; | 9 import java.util.Iterator; |
10 import java.util.Map; | 10 import java.util.Map; |
11 | 11 |
12 import org.apache.log4j.Logger; | 12 import org.apache.log4j.Logger; |
13 import org.w3c.dom.Document; | 13 import org.w3c.dom.Document; |
14 import org.w3c.dom.Element; | |
14 import org.w3c.dom.Node; | 15 import org.w3c.dom.Node; |
15 import org.w3c.dom.NodeList; | 16 import org.w3c.dom.NodeList; |
16 | 17 |
17 import de.intevation.artifactdatabase.Config; | 18 import de.intevation.artifactdatabase.Config; |
18 import de.intevation.gnv.artifacts.GNVArtifactBase; | 19 import de.intevation.gnv.artifacts.GNVArtifactBase; |
29 public abstract class TransitionBase implements Transition { | 30 public abstract class TransitionBase implements Transition { |
30 /** | 31 /** |
31 * the logger, used to log exceptions and additonaly information | 32 * the logger, used to log exceptions and additonaly information |
32 */ | 33 */ |
33 private static Logger log = Logger.getLogger(GNVArtifactBase.class); | 34 private static Logger log = Logger.getLogger(GNVArtifactBase.class); |
35 | |
36 public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; | |
37 public static final String XFORM_PREFIX = "xform"; | |
34 | 38 |
35 private String id = null; | 39 private String id = null; |
36 | 40 |
37 private String description = null; | 41 private String description = null; |
38 | 42 |
145 InputData tmpItem = it.next(); | 149 InputData tmpItem = it.next(); |
146 InputValue inputValue = this.inputValues.get(tmpItem.getName()); | 150 InputValue inputValue = this.inputValues.get(tmpItem.getName()); |
147 if (inputValue != null){ | 151 if (inputValue != null){ |
148 if (this.inputData == null){ | 152 if (this.inputData == null){ |
149 this.inputData = new HashMap<String,InputData>(inputData.size()); | 153 this.inputData = new HashMap<String,InputData>(inputData.size()); |
150 // TODO validate Value; und Valueconcatenieren | |
151 this.inputData.put(tmpItem.getName(),tmpItem); | |
152 } | 154 } |
155 // TODO validate Value; und Valueconcatenieren | |
156 this.inputData.put(tmpItem.getName(),tmpItem); | |
153 | 157 |
154 }else{ | 158 }else{ |
155 String errMsg = "No Inputvalue given for Inputdata "+ tmpItem.getName(); | 159 String errMsg = "No Inputvalue given for Inputdata "+ tmpItem.getName(); |
156 log.warn(errMsg+ "Value will be ignored"); | 160 log.warn(errMsg+ "Value will be ignored"); |
157 throw new TransitionException(errMsg); | |
158 | 161 |
159 } | 162 } |
160 } | 163 } |
161 }else{ | 164 }else{ |
162 log.warn("No Inputdata given"); | 165 log.warn("No Inputdata given"); |
189 try { | 192 try { |
190 String[] filterValues = new String[this.inputValueNames.size()]; | 193 String[] filterValues = new String[this.inputValueNames.size()]; |
191 Iterator<String> it = this.inputValueNames.iterator(); | 194 Iterator<String> it = this.inputValueNames.iterator(); |
192 int i = 0; | 195 int i = 0; |
193 while (it.hasNext()){ | 196 while (it.hasNext()){ |
194 filterValues[i++] = this.inputData.get(it.next()).getValue(); | 197 String value = it.next(); |
198 InputData data = this.inputData.get(value); | |
199 filterValues[i++] = data.getValue(); | |
195 } | 200 } |
196 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); | 201 QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); |
197 Collection<Result> result = queryExecutor.executeQuery(this.queryID, filterValues); | 202 Collection<Result> result = queryExecutor.executeQuery(this.queryID, filterValues); |
198 if (this.descibeData == null){ | 203 if (this.descibeData == null){ |
199 this.descibeData = new ArrayList<Object>(); | 204 this.descibeData = new ArrayList<Object>(); |
202 } catch (QueryException e) { | 207 } catch (QueryException e) { |
203 log.error(e,e); | 208 log.error(e,e); |
204 throw new TransitionException(e); | 209 throw new TransitionException(e); |
205 } | 210 } |
206 } | 211 } |
212 | |
213 /** | |
214 * @see de.intevation.gnv.transition.Transition#describe(org.w3c.dom.Document, org.w3c.dom.Node) | |
215 */ | |
216 public void describe(Document document, Node rootNode) { | |
217 | |
218 if(this.descibeData != null){ | |
219 Iterator<Object> it = this.descibeData.iterator(); | |
220 while (it.hasNext()){ | |
221 Element selectNode = this.createXFormElement(document,"select"); | |
222 // TODO: HACK: | |
223 // BESSERE LÖSUNG FINDEN | |
224 Object[] names = this.inputValueNames.toArray(); | |
225 String name = names[names.length-1].toString(); | |
226 | |
227 selectNode.setAttribute("ref", name); | |
228 | |
229 Element lableNode = this.createXFormElement(document, "label"); | |
230 lableNode.setTextContent(name); | |
231 Element choiceNode = this.createXFormElement(document, "choices"); | |
232 | |
233 | |
234 Object o = it.next(); | |
235 if (o instanceof Collection<?>){ | |
236 Collection<Result> values = (Collection)o; | |
237 Iterator<Result> resultIt = values.iterator(); | |
238 while (resultIt.hasNext()){ | |
239 Result result = resultIt.next(); | |
240 Element itemNode = this.createXFormElement(document, "item"); | |
241 String lableName = result.getResultDescriptor().getColumnName(1); | |
242 String valueName = result.getResultDescriptor().getColumnName(0); | |
243 | |
244 Element choiceLableNode = this.createXFormElement(document, "label"); | |
245 choiceLableNode.setTextContent(result.getString(lableName)); | |
246 itemNode.appendChild(choiceLableNode); | |
247 | |
248 Element choicValueNode = this.createXFormElement(document, "value"); | |
249 choicValueNode.setTextContent(result.getString(valueName)); | |
250 itemNode.appendChild(choicValueNode); | |
251 | |
252 choiceNode.appendChild(itemNode); | |
253 } | |
254 } | |
255 selectNode.appendChild(lableNode); | |
256 selectNode.appendChild(choiceNode); | |
257 rootNode.appendChild(selectNode); | |
258 } | |
259 } | |
260 | |
261 } | |
262 | |
263 private Element createXFormElement(Document document, String name) { | |
264 Element node = document.createElementNS(XFORM_URL, name); | |
265 node.setPrefix(XFORM_PREFIX); | |
266 return node; | |
267 } | |
207 | 268 |
208 /** | 269 /** |
209 * @see de.intevation.gnv.transition.Transition#getDescibeData() | 270 * @see de.intevation.gnv.transition.Transition#getDescibeData() |
210 */ | 271 */ |
211 public Collection<Object> getDescibeData() { | 272 public Collection<Object> getDescibeData() { |
217 */ | 278 */ |
218 public void setDescibeData(Collection<Object> descibeData) { | 279 public void setDescibeData(Collection<Object> descibeData) { |
219 this.descibeData = descibeData; | 280 this.descibeData = descibeData; |
220 | 281 |
221 } | 282 } |
283 | |
284 /** | |
285 * @see de.intevation.gnv.transition.Transition#getInputData() | |
286 */ | |
287 public Collection<InputData> getInputData() throws TransitionException { | |
288 return this.inputData.values(); | |
289 } | |
222 } | 290 } |