Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiIntArrayState.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 4bd3d8bbb60c |
children |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
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 import de.intevation.flys.utils.FLYSUtils; | |
16 | |
17 | |
18 /** | |
19 * State that holds minimun and maximum (for validation). | |
20 * | |
21 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
22 */ | |
23 public abstract class MultiIntArrayState extends DefaultState { | |
24 | |
25 private static final Logger logger = | |
26 Logger.getLogger(MultiIntArrayState.class); | |
27 | |
28 | |
29 @Override | |
30 protected void appendItems( | |
31 Artifact artifact, | |
32 ElementCreator creator, | |
33 String name, | |
34 CallContext context, | |
35 Element select | |
36 ) { | |
37 try { | |
38 creator.addAttr(select, "type", "intoptions", true); | |
39 | |
40 for (KVP kvp: getOptions(artifact, name)) { | |
41 Element item = creator.create("item"); | |
42 creator.addAttr(item, "label", kvp.getValue().toString(), true); | |
43 creator.addAttr(item, "value", kvp.getKey().toString(), true); | |
44 | |
45 select.appendChild(item); | |
46 } | |
47 } | |
48 catch (IllegalArgumentException iae) { | |
49 logger.warn("Illegal argument", iae); | |
50 } | |
51 } | |
52 | |
53 | |
54 @Override | |
55 protected Element createStaticData( | |
56 FLYSArtifact flys, | |
57 ElementCreator creator, | |
58 CallContext cc, | |
59 String name, | |
60 String value, | |
61 String type | |
62 ) { | |
63 Element data = creator.create("data"); | |
64 creator.addAttr(data, "name", name, true); | |
65 creator.addAttr(data, "type", type, true); | |
66 creator.addAttr(data, "label", | |
67 Resources.getMsg(cc.getMeta(), name, name), true); | |
68 | |
69 int[] values = FLYSUtils.intArrayFromString(value); | |
70 | |
71 for (int val: values) { | |
72 try { | |
73 Element item = creator.create("item"); | |
74 creator.addAttr(item, "value", String.valueOf(val), true); | |
75 creator.addAttr(item, "label", getLabelFor(cc, name, val), true); | |
76 | |
77 data.appendChild(item); | |
78 } | |
79 catch (IllegalArgumentException iae) { | |
80 logger.warn("Cannot append item: " + val, iae); | |
81 } | |
82 } | |
83 | |
84 return data; | |
85 } | |
86 | |
87 | |
88 protected abstract KVP<Integer, String>[] getOptions( | |
89 Artifact artifact, | |
90 String parameterName | |
91 ) | |
92 throws IllegalArgumentException; | |
93 | |
94 | |
95 protected abstract String getLabelFor( | |
96 CallContext cc, | |
97 String parameterName, | |
98 int value) | |
99 throws IllegalArgumentException; | |
100 } | |
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |