KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > controller > GroupWizardValidator


1 /*
2  * GroupWizardValidator.java
3  *
4  * Created on March 6, 2004, 11:05 PM
5  */

6
7 package com.quikj.application.communicator.applications.webtalk.controller;
8
9 import javax.servlet.http.*;
10 import org.apache.struts.action.*;
11 import org.apache.struts.validator.*;
12 import org.apache.commons.validator.*;
13
14 /**
15  *
16  * @author bhm
17  */

18 public class GroupWizardValidator
19 {
20     
21     /** Creates a new instance of GroupWizardValidator */
22     public GroupWizardValidator()
23     {
24     }
25     
26     public static boolean validateCompanyNickname(
27     Object JavaDoc bean,
28     ValidatorAction va,
29     Field field,
30     ActionErrors errors,
31     HttpServletRequest request)
32     {
33         DynaValidatorForm form = (DynaValidatorForm)bean;
34         
35         // Get the submit value that requires this field to be validated
36
String JavaDoc validate_if = field.getVarValue("submit");
37         
38         // See if the form submit equals that
39
if (((String JavaDoc)form.get("submit")).equals(validate_if) == true)
40         {
41             // Get the name of the field being validated
42
String JavaDoc name = field.getProperty();
43             
44             if (name.equals("companyNickname") == false)
45             {
46                 return false;
47             }
48             
49             // Get the data in the field
50
String JavaDoc value = ((String JavaDoc)form.get(name)).trim();
51             
52             if (value.equals("all") == true)
53             {
54                 // cannot have a group with name = 'all'
55
errors.add(field.getKey(), Resources.getActionError(request, va, field));
56                 
57                 return false;
58             }
59             
60             if (DataCheckUtility.followsTableIdRules(value) == false)
61             {
62                 errors.add(field.getKey(), Resources.getActionError(request, va, field));
63                 
64                 return false;
65             }
66         }
67         
68         return true;
69     }
70     
71     
72     public static boolean validateCompanyUrl(
73     Object JavaDoc bean,
74     ValidatorAction va,
75     Field field,
76     ActionErrors errors,
77     HttpServletRequest request)
78     {
79         DynaValidatorForm form = (DynaValidatorForm)bean;
80         
81         // Get the submit value that requires this field to be validated
82
String JavaDoc validate_if = field.getVarValue("submit");
83         
84         // See if the form submit equals that
85
if (((String JavaDoc)form.get("submit")).equals(validate_if) == true)
86         {
87             // Get the name of the field being validated
88
String JavaDoc name = field.getProperty();
89             
90             if (name.equals("companyUrl") == false)
91             {
92                 return false;
93             }
94             
95             // Get the data in the field
96
String JavaDoc value = ((String JavaDoc)form.get(name)).trim();
97             
98             if (value.length() < ("http://".length() + 5))
99             {
100                 errors.add(field.getKey(), Resources.getActionError(request, va, field));
101                 
102                 return false;
103             }
104         }
105         
106         return true;
107     }
108     
109     public static boolean validateGroupName(
110     Object JavaDoc bean,
111     ValidatorAction va,
112     Field field,
113     ActionErrors errors,
114     HttpServletRequest request)
115     {
116         DynaValidatorForm form = (DynaValidatorForm)bean;
117         
118         // Get the submit value that requires this field to be validated
119
String JavaDoc validate_if = field.getVarValue("submit");
120         
121         // See if the form submit equals that
122
if (((String JavaDoc)form.get("submit")).equals(validate_if) == true)
123         {
124             // Get the name of the field being validated
125
String JavaDoc name = field.getProperty();
126             
127             if (name.equals("groupName") == false)
128             {
129                 return false;
130             }
131             
132             // Get the data in the field
133
String JavaDoc value = ((String JavaDoc)form.get(name)).trim();
134             
135             if (DataCheckUtility.followsTableIdRules(value) == false)
136             {
137                 errors.add(field.getKey(), Resources.getActionError(request, va, field));
138                 
139                 return false;
140             }
141         }
142         
143         return true;
144     }
145     
146     
147     public static boolean validateFeatureMaximums(
148     Object JavaDoc bean,
149     ValidatorAction va,
150     Field field,
151     ActionErrors errors,
152     HttpServletRequest request)
153     {
154         DynaValidatorForm form = (DynaValidatorForm)bean;
155         
156         // Get the submit value that requires this field to be validated
157
String JavaDoc validate_if = field.getVarValue("submit");
158         
159         // See if the form submit equals that
160
if (((String JavaDoc)form.get("submit")).equals(validate_if) == true)
161         {
162             // Get the data in the field being checked
163
Integer JavaDoc value = (Integer JavaDoc)form.get(field.getProperty());
164             
165             if (value == null)
166             {
167                 errors.add(field.getKey(), Resources.getActionError(request, va, field));
168                 return false;
169             }
170             
171             if (value.intValue() <= 0)
172             {
173                 errors.add(field.getKey(), Resources.getActionError(request, va, field));
174                 return false;
175             }
176             
177         }
178         
179         return true;
180     }
181     
182 }
183
Popular Tags