Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/MinMaxDateState.java @ 796:a5526908f92f
Added javadoc in state package.
gnv-artifacts/trunk@878 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 01 Apr 2010 09:15:36 +0000 |
parents | 7b81d563c8c0 |
children | 499cfbbb61bc |
comparison
equal
deleted
inserted
replaced
795:cdade5005cba | 796:a5526908f92f |
---|---|
23 import org.apache.log4j.Logger; | 23 import org.apache.log4j.Logger; |
24 | 24 |
25 import org.w3c.dom.Document; | 25 import org.w3c.dom.Document; |
26 | 26 |
27 /** | 27 /** |
28 * This state handles date input. The resulting describe document of this state | |
29 * contains two fields in the user interface description to define a time range. | |
30 * | |
28 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
29 */ | 32 */ |
30 public class MinMaxDateState extends MinMaxState { | 33 public class MinMaxDateState extends MinMaxState { |
31 | 34 |
32 | 35 |
36 /** | |
37 * | |
38 */ | |
33 public static final String EXCEPTION_DATE_REQUIRED = | 39 public static final String EXCEPTION_DATE_REQUIRED = |
34 "input.is.not.valid.date.required"; | 40 "input.is.not.valid.date.required"; |
35 | 41 |
42 /** | |
43 * | |
44 */ | |
36 public static final String EXCEPTION_START_AFTER_END = | 45 public static final String EXCEPTION_START_AFTER_END = |
37 "start.date.after.end.date"; | 46 "start.date.after.end.date"; |
38 | 47 |
48 /** | |
49 * | |
50 */ | |
39 public static final String EXCEPTION_DATE_OUT_OF_RANGE = | 51 public static final String EXCEPTION_DATE_OUT_OF_RANGE = |
40 "date.out.of.range"; | 52 "date.out.of.range"; |
41 | 53 |
54 /** | |
55 * | |
56 */ | |
42 public static final String EXCEPTION_MISSING_DATE = | 57 public static final String EXCEPTION_MISSING_DATE = |
43 "missing.data.field"; | 58 "missing.data.field"; |
44 | 59 |
45 private static Logger logger = Logger.getLogger(MinMaxDateState.class); | 60 private static Logger logger = Logger.getLogger(MinMaxDateState.class); |
46 | 61 |
47 | 62 |
63 /** | |
64 * | |
65 */ | |
48 public MinMaxDateState() { | 66 public MinMaxDateState() { |
49 super(); | 67 super(); |
50 } | 68 } |
51 | 69 |
52 | 70 |
53 /** | 71 /** |
54 * @see de.intevation.gnv.state.StateBase#feed(java.util.Collection, | 72 * This feed method needs a collection of two InputData objects. These |
55 * java.lang.String) | 73 * objects' values need to be a datetime string which is turned into a Date |
74 * object. Afterwards, the given dates are validated. Min and max date need | |
75 * to be in range of the min and max date retrieved by | |
76 * {@link #getDescibeData(java.lang.String)}. | |
56 */ | 77 */ |
57 @Override | 78 @Override |
79 @SuppressWarnings({"static-access", "static-access", "static-access"}) | |
58 public Document feed( | 80 public Document feed( |
59 CallContext context, | 81 CallContext context, |
60 Collection<InputData> inputData, | 82 Collection<InputData> inputData, |
61 String uuid) | 83 String uuid) |
62 throws StateException { | 84 throws StateException { |
69 String msg = "No input data given."; | 91 String msg = "No input data given."; |
70 logger.warn(msg); | 92 logger.warn(msg); |
71 return feedFailure(msg); | 93 return feedFailure(msg); |
72 } | 94 } |
73 | 95 |
74 InputValidator iv = new InputValidator(); | |
75 Iterator iter = inputData.iterator(); | 96 Iterator iter = inputData.iterator(); |
76 | 97 |
77 MinMaxDescribeData data = | 98 MinMaxDescribeData data = |
78 (MinMaxDescribeData) getDescibeData(uuid).get(0); | 99 (MinMaxDescribeData) getDescibeData(uuid).get(0); |
79 Object min = data.getMinValue(); | 100 Object min = data.getMinValue(); |
93 String msg = "Input data not expected here. Data will be ignored."; | 114 String msg = "Input data not expected here. Data will be ignored."; |
94 logger.warn(msg); | 115 logger.warn(msg); |
95 return feedFailure(msg); | 116 return feedFailure(msg); |
96 } | 117 } |
97 | 118 |
98 if (!iv.isInputValid(value, type)) { | 119 if (!InputValidator.isInputValid(value, type)) { |
99 String msg = resFactory.getRessource( | 120 String msg = resFactory.getRessource( |
100 locale, EXCEPTION_DATE_REQUIRED, EXCEPTION_DATE_REQUIRED); | 121 locale, EXCEPTION_DATE_REQUIRED, EXCEPTION_DATE_REQUIRED); |
101 logger.error(msg); | 122 logger.error(msg); |
102 return feedFailure(msg); | 123 return feedFailure(msg); |
103 } | 124 } |
132 logger.debug("Date to validate: " + d.toString()); | 153 logger.debug("Date to validate: " + d.toString()); |
133 logger.debug("Lower date bound: " + lower.toString()); | 154 logger.debug("Lower date bound: " + lower.toString()); |
134 logger.debug("Upper date bound: " + upper.toString()); | 155 logger.debug("Upper date bound: " + upper.toString()); |
135 } | 156 } |
136 | 157 |
137 if (!iv.isDateValid(d, lower, upper)) { | 158 if (!InputValidator.isDateValid(d, lower, upper)) { |
138 String msg = resFactory.getRessource( | 159 String msg = resFactory.getRessource( |
139 locale, | 160 locale, |
140 EXCEPTION_DATE_OUT_OF_RANGE, | 161 EXCEPTION_DATE_OUT_OF_RANGE, |
141 EXCEPTION_DATE_OUT_OF_RANGE); | 162 EXCEPTION_DATE_OUT_OF_RANGE); |
142 logger.error(msg); | 163 logger.error(msg); |
151 if (name.equals(MAXVALUEFIELDNAME)) { | 172 if (name.equals(MAXVALUEFIELDNAME)) { |
152 tmpMax = value; | 173 tmpMax = value; |
153 } | 174 } |
154 | 175 |
155 if (tmpMin != null && tmpMax != null) { | 176 if (tmpMin != null && tmpMax != null) { |
156 if (!iv.isInputValid((String) tmpMin, (String) tmpMax, type)) { | 177 if (!InputValidator.isInputValid((String) tmpMin, (String) tmpMax, type)) { |
157 String msg = resFactory.getRessource( | 178 String msg = resFactory.getRessource( |
158 locale, | 179 locale, |
159 EXCEPTION_START_AFTER_END, | 180 EXCEPTION_START_AFTER_END, |
160 EXCEPTION_START_AFTER_END); | 181 EXCEPTION_START_AFTER_END); |
161 logger.error(msg); | 182 logger.error(msg); |
170 this.inputData.put(dataName, new DefaultInputData(dataName, values)); | 191 this.inputData.put(dataName, new DefaultInputData(dataName, values)); |
171 | 192 |
172 return feedSuccess(); | 193 return feedSuccess(); |
173 } | 194 } |
174 } | 195 } |
175 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 196 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |