01: package dinamica.validators;
02:
03: import java.util.HashMap;
04: import javax.servlet.http.HttpServletRequest;
05: import dinamica.*;
06:
07: /**
08: * Generic validator to test if an array based parameter
09: * is empty. Returns false if empty. Requires a custom attribute
10: * called "parameter-name".
11: * <br><br>
12: * Creation date: feb/10/2004<br>
13: * Last Update: feb/10/2004<br>
14: * (c) 2004 Martin Cordova<br>
15: * This code is released under the LGPL license<br>
16: * @author Martin Cordova (dinamica@martincordova.com)
17: * */
18: public class ArrayNotEmptyValidator extends AbstractValidator {
19:
20: /* (non-Javadoc)
21: * @see dinamica.AbstractValidator#isValid(javax.servlet.http.HttpServletRequest, dinamica.Recordset, java.util.HashMap)
22: */
23: public boolean isValid(HttpServletRequest req,
24: Recordset inputParams, HashMap<String, String> attribs)
25: throws Throwable {
26:
27: boolean flag = true;
28:
29: //validate plugin configuration
30: boolean b = attribs.containsKey("parameter-name");
31: if (!b)
32: throw new Throwable(
33: "Bad configuration - 'parameter-name' attribute not found.");
34:
35: //get name of the parameter representing the array of values
36: String paramName = (String) attribs.get("parameter-name");
37:
38: //read values
39: String value[] = req.getParameterValues(paramName);
40:
41: //test
42: if (value == null)
43: flag = false;
44:
45: return flag;
46:
47: }
48:
49: }
|