01: package dinamica.validators;
02:
03: import java.util.HashMap;
04: import javax.servlet.http.HttpServletRequest;
05: import dinamica.*;
06:
07: /**
08: * Generic validator for double value ranges (value-from - value-to).<br>
09: * Will return FALSE if value2 < value1, requires two custom attributes named "value1" and "value2",
10: * representing the field names of the two recordset fields to use
11: * in the validation logic. Returns TRUE if any of the parameters is null.
12: *
13: * <br>
14: * Creation date: 3/march/2004<br>
15: * Last Update: 3/march/2004<br>
16: * (c) 2004 Martin Cordova<br>
17: * This code is released under the LGPL license<br>
18: * @author Martin Cordova (dinamica@martincordova.com)
19: * */
20: public class DoubleRangeValidator extends AbstractValidator {
21:
22: /* (non-Javadoc)
23: * @see dinamica.AbstractValidator#isValid(javax.servlet.http.HttpServletRequest, dinamica.Recordset, java.util.HashMap)
24: */
25: public boolean isValid(HttpServletRequest req,
26: Recordset inputParams, HashMap<String, String> attribs)
27: throws Throwable {
28: String v1 = (String) attribs.get("value1");
29: String v2 = (String) attribs.get("value2");
30:
31: if (v1 == null || v2 == null)
32: throw new Throwable(
33: "Invalid attributes 'value1' or 'value2' - cannot be null.");
34:
35: if (inputParams.isNull(v1) || inputParams.isNull(v2))
36: return true;
37:
38: double d1 = inputParams.getDouble(v1);
39: double d2 = inputParams.getDouble(v2);
40:
41: if (Double.compare(d1, d2) > 0)
42: return false;
43: else
44: return true;
45:
46: }
47:
48: }
|