Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java @ 322:448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
flys-artifacts/trunk@1716 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 18 Apr 2011 12:36:08 +0000 |
parents | 89bd0417418f |
children | ed3325a0232a |
comparison
equal
deleted
inserted
replaced
321:9581b88f2920 | 322:448d0dc64357 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | |
3 import java.util.Map; | |
2 | 4 |
3 import org.apache.log4j.Logger; | 5 import org.apache.log4j.Logger; |
4 | 6 |
5 import org.w3c.dom.Element; | 7 import org.w3c.dom.Element; |
6 | 8 |
19 import de.intevation.flys.artifacts.resources.Resources; | 21 import de.intevation.flys.artifacts.resources.Resources; |
20 | 22 |
21 /** | 23 /** |
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
23 */ | 25 */ |
24 public class LocationDistanceSelect extends DefaultState { | 26 public class LocationDistanceSelect extends RangeState { |
25 | 27 |
26 /** The logger used in this class.*/ | 28 /** The logger used in this class.*/ |
27 private static Logger logger = Logger.getLogger(LocationDistanceSelect.class); | 29 private static Logger logger = Logger.getLogger(LocationDistanceSelect.class); |
28 | 30 |
29 | 31 |
30 /** The default step width.*/ | 32 /** The default step width.*/ |
31 public static final String DEFAULT_STEP = "100"; | 33 public static final String DEFAULT_STEP = "100"; |
34 | |
35 /** The name of the 'from' field. */ | |
36 public static final String FROM = "ld_from"; | |
37 | |
38 /** The name of the 'to' field. */ | |
39 public static final String TO = "ld_to"; | |
40 | |
41 /** The name of the 'step' field. */ | |
42 public static final String STEP = "ld_step"; | |
32 | 43 |
33 /** | 44 /** |
34 * The default constructor that initializes an empty State object. | 45 * The default constructor that initializes an empty State object. |
35 */ | 46 */ |
36 public LocationDistanceSelect() { | 47 public LocationDistanceSelect() { |
137 | 148 |
138 River river = RiverFactory.getRiver(name); | 149 River river = RiverFactory.getRiver(name); |
139 | 150 |
140 return river != null ? river.determineMinMaxDistance() : null; | 151 return river != null ? river.determineMinMaxDistance() : null; |
141 } | 152 } |
153 | |
154 | |
155 @Override | |
156 public boolean validate(Artifact artifact, CallContext context) | |
157 throws IllegalArgumentException | |
158 { | |
159 logger.debug("LocationDistanceSelect.validate"); | |
160 | |
161 Map<String, StateData> data = getData(); | |
162 | |
163 String fromStr = (String) data.get(FROM).getValue(); | |
164 String toStr = (String) data.get(TO).getValue(); | |
165 String stepStr = (String) data.get(STEP).getValue(); | |
166 | |
167 try { | |
168 double from = Double.parseDouble(fromStr); | |
169 double to = Double.parseDouble(toStr); | |
170 double step = Double.parseDouble(stepStr); | |
171 | |
172 double[] minmaxDist = getMinMaxDistance(artifact); | |
173 | |
174 return validateRange(minmaxDist[0], minmaxDist[1], from, to, step); | |
175 } | |
176 catch (NumberFormatException nfe) { | |
177 throw new IllegalArgumentException("error_feed_number_format"); | |
178 } | |
179 } | |
142 } | 180 } |
143 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 181 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |