KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > validators > UpperCaseTransformer


1 package dinamica.validators;
2
3 import java.util.HashMap JavaDoc;
4 import javax.servlet.http.HttpServletRequest JavaDoc;
5 import dinamica.*;
6
7 /**
8  * This validator does not validate but transforms the value of the target parameter
9  * by transforming its contents to upper case characters. It is
10  * used to create SQL search search expressions against data that is stored in upper case,
11  * without programming effort and without SQL expression tricks like value = UPPER('MyLastName...').
12  * It is configured as a validator but works as a parameter value transformer.
13  * <br><br>
14  * <br><br>
15  * Requires the following custom attributes:<br>
16  * <ul>
17  * <li> parameter: Name of the request parameter to transform. This parameter
18  * MUST be defined in validator.xml and must be of type VARCHAR.
19  * </ul>
20  * Creation date: 22/04/2005
21  * (c) 2005 Martin Cordova<br>
22  * This code is released under the LGPL license<br>
23  * Dinamica Framework - http://www.martincordova.com<br>
24  * @author Martin Cordova (dinamica@martincordova.com)
25  */

26 public class UpperCaseTransformer extends AbstractValidator
27 {
28
29     /* (non-Javadoc)
30      * @see dinamica.AbstractValidator#isValid(javax.servlet.http.HttpServletRequest, dinamica.Recordset, java.util.HashMap)
31      */

32     public boolean isValid(HttpServletRequest JavaDoc req, Recordset inputParams,
33             HashMap JavaDoc attribs) throws Throwable JavaDoc
34     {
35
36         boolean bParam = attribs.containsKey("parameter");
37         if (!bParam)
38             throw new Throwable JavaDoc("[" + this.getClass().getName() + "] Missing attribute [parameter] in validator.xml");
39         
40         String JavaDoc paramName = (String JavaDoc)attribs.get("parameter");
41         if (!inputParams.isNull(paramName))
42         {
43             String JavaDoc value = inputParams.getString(paramName);
44             value = value.toUpperCase();
45             inputParams.setValue(paramName, value);
46         }
47         
48         return true;
49         
50     }
51
52 }
53
Popular Tags