01: package dinamica.validators;
02:
03: import java.util.HashMap;
04: import javax.servlet.http.HttpServletRequest;
05: import dinamica.*;
06:
07: /**
08: * This validator does not validate but transforms the value of the target parameter
09: * 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: /* (non-Javadoc)
29: * @see dinamica.AbstractValidator#isValid(javax.servlet.http.HttpServletRequest, dinamica.Recordset, java.util.HashMap)
30: */
31: public boolean isValid(HttpServletRequest req,
32: Recordset inputParams, HashMap<String, String> attribs)
33: throws Throwable {
34:
35: boolean bParam = attribs.containsKey("parameter");
36: if (!bParam)
37: throw new Throwable(
38: "["
39: + this .getClass().getName()
40: + "] Missing attribute [parameter] in validator.xml");
41:
42: String paramName = (String) attribs.get("parameter");
43: if (!inputParams.isNull(paramName)) {
44: String value = inputParams.getString(paramName);
45: value = value.toUpperCase();
46: inputParams.setValue(paramName, value);
47: }
48:
49: return true;
50:
51: }
52:
53: }
|