Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java @ 1655:d251e5929860
Extracted StringUtil.unbracket from WaterlevelSelectState.strip .
flys-artifacts/trunk@2849 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 28 Sep 2011 08:20:29 +0000 |
parents | 47ecf98f09eb |
children | 91d038c7aae5 |
comparison
equal
deleted
inserted
replaced
1654:33ade8153d74 | 1655:d251e5929860 |
---|---|
15 import de.intevation.flys.artifacts.FLYSArtifact; | 15 import de.intevation.flys.artifacts.FLYSArtifact; |
16 import de.intevation.flys.artifacts.model.CalculationResult; | 16 import de.intevation.flys.artifacts.model.CalculationResult; |
17 import de.intevation.flys.artifacts.model.WQKms; | 17 import de.intevation.flys.artifacts.model.WQKms; |
18 import de.intevation.flys.artifacts.resources.Resources; | 18 import de.intevation.flys.artifacts.resources.Resources; |
19 import de.intevation.flys.utils.FLYSUtils; | 19 import de.intevation.flys.utils.FLYSUtils; |
20 import de.intevation.flys.utils.StringUtil; | |
20 | 21 |
21 | 22 |
22 /** | 23 /** |
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
24 */ | 25 */ |
38 protected String getUIProvider() { | 39 protected String getUIProvider() { |
39 return "wsp_datacage_panel"; | 40 return "wsp_datacage_panel"; |
40 } | 41 } |
41 | 42 |
42 | 43 |
44 /** | |
45 * @param flys ignored | |
46 * @param cc ignrored | |
47 */ | |
43 @Override | 48 @Override |
44 public StateData transform( | 49 public StateData transform( |
45 FLYSArtifact flys, | 50 FLYSArtifact flys, |
46 CallContext cc, | 51 CallContext cc, |
47 String name, | 52 String name, |
50 if (!isValueValid(val)) { | 55 if (!isValueValid(val)) { |
51 logger.error("The given input string is not valid: '" + val + "'"); | 56 logger.error("The given input string is not valid: '" + val + "'"); |
52 return null; | 57 return null; |
53 } | 58 } |
54 | 59 |
55 return new DefaultStateData(name, null, null, strip(val)); | 60 return new DefaultStateData(name, null, null, StringUtil.unbracket(val)); |
56 } | 61 } |
57 | 62 |
58 | 63 |
59 @Override | 64 @Override |
60 public boolean validate(Artifact artifact) | 65 public boolean validate(Artifact artifact) |
98 | 103 |
99 return dataElement; | 104 return dataElement; |
100 } | 105 } |
101 | 106 |
102 | 107 |
108 /** | |
109 * Get name to display for selected watelerlevel (for example "Q=123") | |
110 * from the CalculationResult. | |
111 */ | |
103 public static String[] getLabels(CallContext cc, String value) { | 112 public static String[] getLabels(CallContext cc, String value) { |
104 String[] parts = value.split(SPLIT_CHAR); | 113 String[] parts = value.split(SPLIT_CHAR); |
105 | 114 |
106 FLYSArtifact artifact = FLYSUtils.getArtifact(parts[0], cc); | 115 FLYSArtifact artifact = FLYSUtils.getArtifact(parts[0], cc); |
107 | 116 |
122 | 131 |
123 return new String[] { wqkms[idx].getName() }; | 132 return new String[] { wqkms[idx].getName() }; |
124 } | 133 } |
125 | 134 |
126 | 135 |
127 public static String strip(String value) { | |
128 int start = value.indexOf("["); | |
129 int end = value.indexOf("]"); | |
130 | |
131 if (start < 0 || end < 0) { | |
132 return value; | |
133 } | |
134 | |
135 value = value.substring(start+1, end); | |
136 | |
137 return value; | |
138 } | |
139 | |
140 | |
141 /** | 136 /** |
142 * Validates the given String. A valid string for this state requires the | 137 * Validates the given String. A valid string for this state requires the |
143 * format: "UUID;FACETNAME;FACETINDEX". | 138 * format: "UUID;FACETNAME;FACETINDEX". |
144 * | 139 * |
145 * @param value The string value requires validation. | 140 * @param value The string value requires validation. |
148 * false. | 143 * false. |
149 */ | 144 */ |
150 public static boolean isValueValid(String value) { | 145 public static boolean isValueValid(String value) { |
151 logger.debug("Validate string: '" + value + "'"); | 146 logger.debug("Validate string: '" + value + "'"); |
152 | 147 |
153 value = strip(value); | 148 value = StringUtil.unbracket(value); |
154 | 149 |
155 logger.debug("Validate substring: '" + value + "'"); | 150 logger.debug("Validate substring: '" + value + "'"); |
156 | 151 |
157 if (value == null || value.length() == 0) { | 152 if (value == null || value.length() == 0) { |
158 return false; | 153 return false; |