Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java @ 1028:41234fcf4c7e
Some Bugfixes which prevent Exceptions executing the Examples in the config-manual
gnv-artifacts/trunk@1052 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 04 May 2010 12:40:21 +0000 |
parents | 22c18083225e |
children | f953c9a559d8 |
comparison
equal
deleted
inserted
replaced
874:f08908d4df50 | 1028:41234fcf4c7e |
---|---|
1 package de.intevation.gnv.artifacts.fis; | 1 package de.intevation.gnv.artifacts.fis; |
2 | |
3 import java.io.IOException; | |
4 import java.io.OutputStream; | |
5 import java.util.Collection; | |
6 import java.util.HashMap; | |
7 import java.util.Iterator; | |
8 import java.util.Map; | |
9 | |
10 import javax.xml.xpath.XPathConstants; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 import org.w3c.dom.Document; | |
14 import org.w3c.dom.Element; | |
15 import org.w3c.dom.Node; | |
16 import org.w3c.dom.NodeList; | |
2 | 17 |
3 import de.intevation.artifactdatabase.ProxyArtifact; | 18 import de.intevation.artifactdatabase.ProxyArtifact; |
4 import de.intevation.artifactdatabase.XMLUtils; | 19 import de.intevation.artifactdatabase.XMLUtils; |
5 | |
6 import de.intevation.artifacts.Artifact; | 20 import de.intevation.artifacts.Artifact; |
7 import de.intevation.artifacts.ArtifactFactory; | 21 import de.intevation.artifacts.ArtifactFactory; |
8 import de.intevation.artifacts.ArtifactNamespaceContext; | 22 import de.intevation.artifacts.ArtifactNamespaceContext; |
9 import de.intevation.artifacts.CallContext; | 23 import de.intevation.artifacts.CallContext; |
10 import de.intevation.artifacts.CallMeta; | 24 import de.intevation.artifacts.CallMeta; |
11 | |
12 import de.intevation.gnv.artifacts.GNVArtifactBase; | 25 import de.intevation.gnv.artifacts.GNVArtifactBase; |
13 import de.intevation.gnv.artifacts.GNVDefaultArtifact; | 26 import de.intevation.gnv.artifacts.GNVDefaultArtifact; |
14 import de.intevation.gnv.artifacts.GNVProductArtifactFactory; | 27 import de.intevation.gnv.artifacts.GNVProductArtifactFactory; |
15 import de.intevation.gnv.artifacts.PreSettingArtifact; | 28 import de.intevation.gnv.artifacts.PreSettingArtifact; |
16 | |
17 import de.intevation.gnv.artifacts.fis.product.Product; | 29 import de.intevation.gnv.artifacts.fis.product.Product; |
18 | |
19 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | 30 import de.intevation.gnv.artifacts.ressource.RessourceFactory; |
20 | |
21 import de.intevation.gnv.state.DefaultInputData; | 31 import de.intevation.gnv.state.DefaultInputData; |
22 import de.intevation.gnv.state.InputData; | 32 import de.intevation.gnv.state.InputData; |
23 | |
24 import java.io.IOException; | |
25 import java.io.OutputStream; | |
26 | |
27 import java.util.Collection; | |
28 import java.util.HashMap; | |
29 import java.util.Iterator; | |
30 import java.util.Map; | |
31 | |
32 import javax.xml.xpath.XPathConstants; | |
33 | |
34 import org.apache.log4j.Logger; | |
35 | |
36 import org.w3c.dom.Document; | |
37 import org.w3c.dom.Element; | |
38 import org.w3c.dom.Node; | |
39 import org.w3c.dom.NodeList; | |
40 | 33 |
41 /** | 34 /** |
42 * This artifact is used to handle to input/output at the beginning of a | 35 * This artifact is used to handle to input/output at the beginning of a |
43 * parameterization when no product has been selected so far. After the user | 36 * parameterization when no product has been selected so far. After the user |
44 * having selected a product, this artifact is replaced by a concrete product | 37 * having selected a product, this artifact is replaced by a concrete product |
384 protected void appendProducts( | 377 protected void appendProducts( |
385 Document document, | 378 Document document, |
386 Node parent, | 379 Node parent, |
387 Object context | 380 Object context |
388 ) { | 381 ) { |
389 Iterator iter = products.values().iterator(); | 382 if (products != null && !products.isEmpty()){ |
390 | 383 Iterator iter = products.values().iterator(); |
391 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | 384 |
392 document, | 385 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
393 ArtifactNamespaceContext.NAMESPACE_URI, | 386 document, |
394 ArtifactNamespaceContext.NAMESPACE_PREFIX | 387 ArtifactNamespaceContext.NAMESPACE_URI, |
395 ); | 388 ArtifactNamespaceContext.NAMESPACE_PREFIX |
396 | 389 ); |
397 while(iter.hasNext()) { | 390 |
398 Product prod = (Product) iter.next(); | 391 while(iter.hasNext()) { |
399 String name = prod.getName(); | 392 Product prod = (Product) iter.next(); |
400 | 393 String name = prod.getName(); |
401 Element current = creator.create("state"); | 394 |
402 creator.addAttr(current, "name", name); | 395 Element current = creator.create("state"); |
403 creator.addAttr(current, "description", name); | 396 creator.addAttr(current, "name", name); |
404 parent.appendChild(current); | 397 creator.addAttr(current, "description", name); |
398 parent.appendChild(current); | |
399 } | |
405 } | 400 } |
406 } | 401 } |
407 | 402 |
408 | 403 |
409 /** | 404 /** |
439 ); | 434 ); |
440 | 435 |
441 Element choiceNode = creator.create("choices"); | 436 Element choiceNode = creator.create("choices"); |
442 selectNode.appendChild(lableNode); | 437 selectNode.appendChild(lableNode); |
443 selectNode.appendChild(choiceNode); | 438 selectNode.appendChild(choiceNode); |
444 | 439 if (products != null && !products.isEmpty()){ |
445 Iterator it = products.values().iterator(); | 440 Iterator it = products.values().iterator(); |
446 while (it.hasNext()) { | 441 while (it.hasNext()) { |
447 Product p = (Product) it.next(); | 442 Product p = (Product) it.next(); |
448 Element itemNode = creator.create("item"); | 443 Element itemNode = creator.create("item"); |
449 Element choiceLableNode = creator.create("label"); | 444 Element choiceLableNode = creator.create("label"); |
450 choiceLableNode.setTextContent(ressource.getRessource( | 445 choiceLableNode.setTextContent(ressource.getRessource( |
451 callMeta.getLanguages(), | 446 callMeta.getLanguages(), |
452 p.getName(), | 447 p.getName(), |
453 p.getName() | 448 p.getName() |
454 )); | 449 )); |
455 itemNode.appendChild(choiceLableNode); | 450 itemNode.appendChild(choiceLableNode); |
456 | 451 |
457 Element choiceValueNode = creator.create("value"); | 452 Element choiceValueNode = creator.create("value"); |
458 choiceValueNode.setTextContent(p.getName()); | 453 choiceValueNode.setTextContent(p.getName()); |
459 itemNode.appendChild(choiceValueNode); | 454 itemNode.appendChild(choiceValueNode); |
460 choiceNode.appendChild(itemNode); | 455 choiceNode.appendChild(itemNode); |
456 } | |
461 } | 457 } |
462 | 458 |
463 node.appendChild(selectNode); | 459 node.appendChild(selectNode); |
464 } | 460 } |
465 | 461 |