2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.validator.faces;
19
20 import java.util.Iterator;
21 import java.util.LinkedHashMap;
22 import java.util.Map;
23
24 import javax.faces.validator.Validator;
25 import javax.servlet.jsp.JspException;
26
27 import org.apache.shale.util.Tags;
28 import org.apache.shale.validator.CommonsValidator;
29
30 /***
31 * The tag class for the <code>s:commonsValidator</code> tag.
32 *
33 * $Id: ValidatorTag.java 481413 2006-12-01 21:48:06Z rahul $
34 */
35 public class ValidatorTag extends javax.faces.webapp.ValidatorTag {
36
37 /***
38 * Serial version UID.
39 */
40 private static final long serialVersionUID = -5007063635477571688L;
41
42
43 /***
44 * <p>The <code>type</code> attribute.
45 */
46 private String type;
47
48
49 /***
50 * <p>The <code>min</code> attribute.
51 */
52 private String min;
53
54
55 /***
56 * <p>The <code>max</code> attribute.
57 */
58 private String max;
59
60
61 /***
62 * <p>The <code>minlength</code> attribute.
63 */
64 private String minlength;
65
66
67 /***
68 * <p>The <code>maxlength</code> attribute.
69 */
70 private String maxlength;
71
72
73 /***
74 * <p>The <code>datePatternStrict</code> attribute.
75 */
76 private String datePatternStrict;
77
78
79 /***
80 * <p>The <code>mask</code> attribute.
81 */
82 private String mask;
83
84
85 /***
86 * <p>The <code>message</code> attribute.
87 */
88 private String message;
89
90
91 /***
92 * <p>The <code>arg</code> attribute.
93 */
94 private String arg;
95
96
97 /***
98 * <p>The <code>client</code> attribute.
99 */
100 private String client;
101
102
103 /***
104 * <p>The <code>server</code> attribute.
105 */
106 private String server;
107
108
109 /***
110 * <p>The parameters to pass to the validator.</p>
111 */
112 private LinkedHashMap params;
113
114
115 /***
116 * <p>This constructor obtains a reference to the
117 * tag utility object, which is a JSF managed bean.
118 */
119 public ValidatorTag() {
120 setValidatorId("org.apache.shale.CommonsValidator");
121 }
122
123
124 /***
125 * <p>Setter method for the <code>type</code> attribute.
126 *
127 * @param newValue the new attribute value
128 */
129 public void setType(String newValue) {
130 type = newValue;
131 }
132
133
134 /***
135 * <p>Setter method for the <code>min</code> attribute.
136 *
137 * @param newValue the new attribute value
138 */
139 public void setMin(String newValue) {
140 min = newValue;
141 }
142
143
144 /***
145 * <p>Setter method for the <code>max</code> attribute.
146 *
147 * @param newValue the new attribute value
148 */
149 public void setMax(String newValue) {
150 max = newValue;
151 }
152
153
154 /***
155 * <p>Setter method for the <code>minlength</code> attribute.
156 *
157 * @param newValue the new attribute value
158 */
159 public void setMinlength(String newValue) {
160 minlength = newValue;
161 }
162
163
164 /***
165 * <p>Setter method for the <code>maxlength</code> attribute.
166 *
167 * @param newValue the new attribute value
168 */
169 public void setMaxlength(String newValue) {
170 maxlength = newValue;
171 }
172
173
174 /***
175 * <p>Setter method for the <code>setDatePatternStrict</code> attribute.
176 *
177 * @param newValue the new attribute value
178 */
179 public void setDatePatternStrict(String newValue) {
180 datePatternStrict = newValue;
181 }
182
183
184 /***
185 * <p>Setter method for the <code>mask</code> attribute.
186 *
187 * @param newValue the new attribute value
188 */
189 public void setMask(String newValue) {
190 mask = newValue;
191 }
192
193
194 /***
195 * <p>Setter method for the <code>message</code> attribute.
196 *
197 * @param newValue the new attribute value
198 */
199 public void setMessage(String newValue) {
200 message = newValue;
201 }
202
203
204 /***
205 * <p>Setter method for the <code>arg</code> attribute.
206 *
207 * @param newValue the new attribute value
208 */
209 public void setArg(String newValue) {
210 arg = newValue;
211 }
212
213
214 /***
215 * <p>Setter method for the <code>client</code> attribute.
216 *
217 * @param newValue the new attribute value
218 */
219 public void setClient(String newValue) {
220 client = newValue;
221 }
222
223
224 /***
225 * <p>Setter method for the <code>server</code> attribute.
226 *
227 * @param newValue the new attribute value
228 */
229 public void setServer(String newValue) {
230 server = newValue;
231 }
232
233
234 /***
235 * <p>Adds a parameter to pass to the Commons Validator that will be
236 * used.</p>
237 *
238 * @param name the name of the parameter to pass to the validator.
239 * @param value the value of the parameter to pass to the validator.
240 */
241 public void addParam(String name, String value) {
242 params.put(name, value);
243 }
244
245 /***
246 * <p>Overridden to prevent the call to {@link #createValidator} from
247 * occurring here.</p>
248 *
249 * @return EVAL_BODY_INCLUDE
250 */
251 public int doStartTag() throws JspException {
252
253 params = new LinkedHashMap();
254 return EVAL_BODY_INCLUDE;
255 }
256
257
258 /***
259 * <p>Executes the code that was skipped in the <code>doStartTag()</code>
260 * override.</p>
261 *
262 * @exception JspException if a JSP processing error occurs
263 */
264 public int doEndTag() throws JspException {
265 super.doStartTag();
266 return super.doEndTag();
267 }
268
269
270 /***
271 * <p>Create a validator by calling <code>super.createValidator()</code>.
272 * This method initializes that validator with the tag's attribute
273 * values.
274 *
275 * @exception JspException if a JSP processing error occurs
276 */
277 public Validator createValidator() throws JspException {
278 CommonsValidator validator = (CommonsValidator) super.createValidator();
279
280
281 if (min != null) {
282 validator.setMin(min);
283 }
284 if (max != null) {
285 validator.setMax(max);
286 }
287 if (minlength != null) {
288 validator.setMinLength(minlength);
289 }
290 if (maxlength != null) {
291 validator.setMaxLength(maxlength);
292 }
293 if (datePatternStrict != null) {
294 validator.setDatePatternStrict(datePatternStrict);
295 }
296 if (mask != null) {
297 validator.setMask(mask);
298 }
299 if (arg != null) {
300 validator.setArg(arg);
301 }
302
303 Tags tagUtils = new Tags();
304
305
306 validator.setType(tagUtils.evalString(type));
307 validator.setMessage(tagUtils.evalString(message));
308 validator.setClient(tagUtils.evalBoolean(client));
309 validator.setServer(tagUtils.evalBoolean(server));
310
311 tagUtils = null;
312
313
314
315
316 if (params != null) {
317 for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
318 Map.Entry e = (Map.Entry) iterator.next();
319 Object key = e.getKey();
320 Object value = e.getValue();
321 validator.getVars().put(key, value);
322 }
323 }
324
325 return validator;
326 }
327
328
329 /***
330 * <p>Sets all instance objects representing tag attribute values
331 * to <code>null</code>.
332 */
333 public void release() {
334 type = null;
335 params = null;
336 min = null;
337 max = null;
338 minlength = null;
339 maxlength = null;
340 datePatternStrict = null;
341 mask = null;
342 message = null;
343 arg = null;
344 client = null;
345 server = null;
346 }
347
348 }