1 package dinamica.validators; 2 3 import java.util.HashMap ; 4 import javax.servlet.http.HttpServletRequest ; 5 import dinamica.*; 6 7 8 30 public class SQLPatternTransformer extends AbstractValidator { 31 32 35 public boolean isValid(HttpServletRequest req, Recordset inputParams, 36 HashMap attribs) throws Throwable { 37 38 boolean bParam = attribs.containsKey("parameter"); 39 if (!bParam) 40 throw new Throwable ("[" + this.getClass().getName() + "] Missing attribute [parameter] in validator.xml"); 41 42 boolean bRule = attribs.containsKey("rule"); 43 if (!bRule) 44 throw new Throwable ("[" + this.getClass().getName() + "] Missing attribute [rule] in validator.xml"); 45 46 String rule = (String )attribs.get("rule"); 47 48 if (!rule.equalsIgnoreCase("like") && !rule.equalsIgnoreCase("contains")) 49 throw new Throwable ("[" + this.getClass().getName() + "] Invalid attribute value [rule] in validator.xml: " + rule + " - Accepted values are 'like' or 'contains'"); 50 51 String paramName = (String )attribs.get("parameter"); 52 if (!inputParams.isNull(paramName)) 53 { 54 String value = inputParams.getString(paramName); 55 value = StringUtil.replace(value, "%", ""); 56 if (rule.equalsIgnoreCase("like")) 57 value = value + "%"; 58 if (rule.equalsIgnoreCase("contains")) 59 value = "%" + value + "%"; 60 inputParams.setValue(paramName, value); 61 } 62 63 return true; 64 } 65 66 } 67
| Popular Tags
|