01: package dinamica.validators;
02:
03: import java.util.HashMap;
04: import javax.servlet.http.HttpServletRequest;
05: import dinamica.*;
06:
07: /**
08: * Returns TRUE if value1.equals(value2).<br>
09: * value1 and value2 must be of type String. Requires two custom
10: * attributes named "value1" and "value2" representing the names
11: * of the fields to compare.
12: * <br><br>
13: * Creation date: 5/03/2004<br>
14: * Last Update: 5/03/2004<br>
15: * (c) 2004 Martin Cordova<br>
16: * This code is released under the LGPL license<br>
17: * @author Martin Cordova (dinamica@martincordova.com)
18: * */
19: public class MatchEqualValidator extends AbstractValidator {
20:
21: /* (non-Javadoc)
22: * @see dinamica.AbstractValidator#isValid(javax.servlet.http.HttpServletRequest, dinamica.Recordset, java.util.HashMap)
23: */
24: public boolean isValid(HttpServletRequest req,
25: Recordset inputParams, HashMap<String, String> attribs)
26: throws Throwable {
27:
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: String d1 = inputParams.getString(v1);
39: String d2 = inputParams.getString(v2);
40:
41: if (!d1.equals(d2))
42: return false;
43: else
44: return true;
45:
46: }
47:
48: }
|