KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > validators > MatchEqualValidator


1 package dinamica.validators;
2
3 import java.util.HashMap JavaDoc;
4 import javax.servlet.http.HttpServletRequest JavaDoc;
5 import dinamica.*;
6
7 /**
8  * Returns TRUE if value1.equals(value2).<br>
9  * 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
22     /* (non-Javadoc)
23      * @see dinamica.AbstractValidator#isValid(javax.servlet.http.HttpServletRequest, dinamica.Recordset, java.util.HashMap)
24      */

25     public boolean isValid(
26         HttpServletRequest JavaDoc req,
27         Recordset inputParams,
28         HashMap JavaDoc attribs)
29         throws Throwable JavaDoc
30     {
31         
32         String JavaDoc v1 = (String JavaDoc)attribs.get("value1");
33         String JavaDoc v2 = (String JavaDoc)attribs.get("value2");
34         
35         if (v1==null || v2==null)
36             throw new Throwable JavaDoc("Invalid attributes 'value1' or 'value2' - cannot be null.");
37         
38         if (inputParams.isNull(v1) || inputParams.isNull(v2))
39             return true;
40             
41         String JavaDoc d1 = inputParams.getString(v1);
42         String JavaDoc d2 = inputParams.getString(v2);
43         
44         if ( !d1.equals(d2) )
45             return false;
46         else
47             return true;
48             
49     }
50
51 }
52
Popular Tags