Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiStringArrayState.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 4bd3d8bbb60c |
children | 33bfc01410fb |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import org.w3c.dom.Element; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import de.intevation.artifacts.Artifact; | |
8 import de.intevation.artifacts.CallContext; | |
9 | |
10 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
11 import de.intevation.artifacts.common.model.KVP; | |
12 | |
13 import de.intevation.flys.artifacts.FLYSArtifact; | |
14 import de.intevation.flys.artifacts.resources.Resources; | |
15 | |
16 | |
17 /** | |
18 * | |
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
20 */ | |
21 public abstract class MultiStringArrayState extends DefaultState { | |
22 | |
23 private static final Logger logger = | |
24 Logger.getLogger(MultiStringArrayState.class); | |
25 | |
26 | |
27 @Override | |
28 protected void appendItems( | |
29 Artifact artifact, | |
30 ElementCreator creator, | |
31 String name, | |
32 CallContext context, | |
33 Element select | |
34 ) { | |
35 try { | |
36 creator.addAttr(select, "type", "options", true); | |
37 | |
38 for (KVP kvp: getOptions(artifact, name)) { | |
39 Element item = creator.create("item"); | |
40 creator.addAttr(item, "label", kvp.getValue().toString(), true); | |
41 creator.addAttr(item, "value", kvp.getKey().toString(), true); | |
42 | |
43 select.appendChild(item); | |
44 } | |
45 } | |
46 catch (IllegalArgumentException iae) { | |
47 logger.warn("Illegal argument", iae); | |
48 } | |
49 } | |
50 | |
51 | |
52 @Override | |
53 protected Element createStaticData( | |
54 FLYSArtifact flys, | |
55 ElementCreator creator, | |
56 CallContext cc, | |
57 String name, | |
58 String value, | |
59 String type | |
60 ) { | |
61 Element data = creator.create("data"); | |
62 creator.addAttr(data, "name", name, true); | |
63 creator.addAttr(data, "type", type, true); | |
64 creator.addAttr(data, "label", | |
65 Resources.getMsg(cc.getMeta(), name, name), true); | |
66 | |
67 String[] values = value.split(";"); | |
68 | |
69 for (String val: values) { | |
70 Element item = creator.create("item"); | |
71 creator.addAttr(item, "value", val, true); | |
72 creator.addAttr(item, "label", getLabelFor(cc, name, val), true); | |
73 | |
74 data.appendChild(item); | |
75 } | |
76 | |
77 return data; | |
78 } | |
79 | |
80 | |
81 protected abstract KVP<String, String>[] getOptions( | |
82 Artifact artifact, | |
83 String parameterName | |
84 ) | |
85 throws IllegalArgumentException; | |
86 | |
87 | |
88 protected abstract String getLabelFor( | |
89 CallContext cc, | |
90 String parameterName, | |
91 String value | |
92 ) | |
93 throws IllegalArgumentException; | |
94 } | |
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |