KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > admin > controller > AccountManagementForm


1 /*
2  * AccountManagementForm.java
3  *
4  * Created on May 2, 2003, 11:09 AM
5  */

6
7 package com.quikj.application.communicator.admin.controller;
8
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import org.apache.struts.action.*;
11 import java.util.*;
12
13 import com.quikj.application.communicator.admin.model.*;
14
15 /**
16  *
17  * @author bhm
18  */

19 public class AccountManagementForm extends ActionForm
20 {
21     
22     /** Holds value of property name. */
23     private String JavaDoc name;
24     
25     /** Holds value of property password. */
26     private String JavaDoc password;
27     
28     /** Holds value of property verifyPassword. */
29     private String JavaDoc verifyPassword;
30     
31     /** Holds value of property submit. */
32     private String JavaDoc submit;
33     
34     /** Holds value of property additionalInfo. */
35     private String JavaDoc additionalInfo;
36     
37     /** Holds value of property level. */
38     private int level;
39     
40     /** Holds value of property featureList. */
41     private String JavaDoc[] featureList;
42     
43     /** Holds value of property assignedFeatures. */
44     private Object JavaDoc[] assignedFeatures;
45     
46     private static int MIN_PASSWORD_LENGTH = 4;
47     
48     /** Holds value of property domain. */
49     private String JavaDoc domain;
50     
51     /** Creates a new instance of AccountManagementForm */
52     public AccountManagementForm()
53     {
54         ArrayList configured_features = AdminConfig.getInstance().getApplications();
55         featureList = new String JavaDoc[configured_features.size()];
56         // todo - get application att userInfo, only include features there too
57

58         int count = 0;
59         for (Iterator i = configured_features.iterator(); i.hasNext(); count++)
60         {
61             featureList[count] = ((ApplicationElement)i.next()).getDisplayName();
62         }
63         
64         reset();
65     }
66     
67     /** Getter for property name.
68      * @return Value of property name.
69      *
70      */

71     public String JavaDoc getName()
72     {
73         return this.name;
74     }
75     
76     /** Setter for property name.
77      * @param name New value of property name.
78      *
79      */

80     public void setName(String JavaDoc name)
81     {
82         this.name = name.trim();
83     }
84     
85     /** Getter for property password.
86      * @return Value of property password.
87      *
88      */

89     public String JavaDoc getPassword()
90     {
91         return this.password;
92     }
93     
94     /** Setter for property password.
95      * @param password New value of property password.
96      *
97      */

98     public void setPassword(String JavaDoc password)
99     {
100         this.password = password;
101     }
102     
103     /** Getter for property verifyPassword.
104      * @return Value of property verifyPassword.
105      *
106      */

107     public String JavaDoc getVerifyPassword()
108     {
109         return this.verifyPassword;
110     }
111     
112     /** Setter for property verifyPassword.
113      * @param verifyPassword New value of property verifyPassword.
114      *
115      */

116     public void setVerifyPassword(String JavaDoc verifyPassword)
117     {
118         this.verifyPassword = verifyPassword;
119     }
120     
121     /** Getter for property submit.
122      * @return Value of property submit.
123      *
124      */

125     public String JavaDoc getSubmit()
126     {
127         return this.submit;
128     }
129     
130     /** Setter for property submit.
131      * @param submit New value of property submit.
132      *
133      */

134     public void setSubmit(String JavaDoc submit)
135     {
136         this.submit = submit;
137     }
138     
139     /** Getter for property additionalInfo.
140      * @return Value of property additionalInfo.
141      *
142      */

143     public String JavaDoc getAdditionalInfo()
144     {
145         return this.additionalInfo;
146     }
147     
148     /** Setter for property additionalInfo.
149      * @param additionalInfo New value of property additionalInfo.
150      *
151      */

152     public void setAdditionalInfo(String JavaDoc additionalInfo)
153     {
154         this.additionalInfo = additionalInfo.trim();
155     }
156     
157     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request)
158     {
159         // Check for mandatory data
160
ActionErrors errors = new ActionErrors();
161         
162         if ((name == null) || (name.length() == 0))
163         {
164             errors.add("name", new ActionError("error.account.no.name"));
165         }
166
167         // for create-specific options
168
if (submit.equals("Create") == true)
169         {
170             if ((password == null) || (password.length() == 0))
171             {
172                 errors.add("password", new ActionError("error.account.no.password"));
173             }
174             else
175             {
176                 validatePassword(password, errors, "password");
177                 
178                 if (verifyPassword != null)
179                 {
180                     if (password.equals(verifyPassword) == false)
181                     {
182                         errors.add("password", new ActionError("error.account.password.mismatch"));
183                     }
184                 }
185                 else
186                 {
187                     errors.add("password", new ActionError("error.account.password.mismatch"));
188                 }
189             }
190         }
191         
192         // for modify-specific options
193
if (submit.equals("Modify") == true)
194         {
195             if ((password != null) && (password.length() > 0))
196             {
197                 validatePassword(password, errors, "password");
198                 
199                 if (verifyPassword != null)
200                 {
201                     if (password.equals(verifyPassword) == false)
202                     {
203                         errors.add("password", new ActionError("error.account.password.mismatch"));
204                     }
205                 }
206                 else
207                 {
208                     errors.add("password", new ActionError("error.account.password.mismatch"));
209                 }
210             }
211         }
212         
213         // general checks for create/modify
214
if ((submit.equals("Modify") == true) || (submit.equals("Create") == true))
215         {
216             // verify domain specified for all customer level users
217
if (level == AccountElement.LEVEL_CUSTOMER)
218             {
219                 if ((domain == null) || (domain.length() == 0))
220                 {
221                     errors.add("domain", new ActionError("error.account.no.domain"));
222                 }
223             }
224             
225         }
226
227         return errors;
228     }
229     
230     public static void validatePassword(String JavaDoc password, ActionErrors errors, String JavaDoc fieldname)
231     {
232         password = password.trim();
233         if (password.length() == 0)
234         {
235             errors.add(fieldname, new ActionError("error.account.password.hasblanks"));
236         }
237         else
238         {
239             int len = password.length();
240             
241             if (len < MIN_PASSWORD_LENGTH)
242             {
243                 errors.add(fieldname, new ActionError("error.account.password.tooshort", new Integer JavaDoc(MIN_PASSWORD_LENGTH)));
244             }
245             
246             // it must have both letters and digits
247
boolean letter = false;
248             boolean digit = false;
249             
250             for (int i = 0; i < len; i++)
251             {
252                 char c = password.charAt(i);
253                 if (Character.isDigit(c) == true)
254                 {
255                     digit = true;
256                 }
257                 else if (Character.isLetter(c) == true)
258                 {
259                     letter = true;
260                 }
261                 else if (Character.isSpaceChar(c) == true)
262                 {
263                     errors.add(fieldname, new ActionError("error.account.password.hasblanks"));
264                 }
265             }
266             
267             if ((letter == false) || (digit == false))
268             {
269                 errors.add(fieldname, new ActionError("error.account.password.content"));
270             }
271         }
272     }
273     
274     public void reset()
275     {
276         password = null;
277         verifyPassword = null;
278         submit = "Find";
279         additionalInfo = null;
280         level = AccountElement.LEVEL_CUSTOMER;
281         assignedFeatures = new Object JavaDoc[featureList.length];
282         domain = null;
283         
284     }
285     
286     /** Getter for property level.
287      * @return Value of property level.
288      *
289      */

290     public int getLevel()
291     {
292         return this.level;
293     }
294     
295     /** Setter for property level.
296      * @param level New value of property level.
297      *
298      */

299     public void setLevel(int level)
300     {
301         this.level = level;
302     }
303     
304     /** Getter for property featureList.
305      * @return Value of property featureList.
306      *
307      */

308     public String JavaDoc[] getFeatureList()
309     {
310         return this.featureList;
311     }
312     
313     /** Getter for property assignedFeatures.
314      * @return Value of property assignedFeatures.
315      *
316      */

317     public Object JavaDoc[] getAssignedFeatures()
318     {
319         return this.assignedFeatures;
320     }
321
322     /** Setter for property assignedFeatures.
323      * @param assignedFeatures New value of property assignedFeatures.
324      *
325      */

326     public void setAssignedFeatures(Object JavaDoc[] assignedFeatures)
327     {
328         this.assignedFeatures = assignedFeatures;
329     }
330     
331     /** Getter for property domain.
332      * @return Value of property domain.
333      *
334      */

335     public String JavaDoc getDomain()
336     {
337         return this.domain;
338     }
339     
340     /** Setter for property domain.
341      * @param domain New value of property domain.
342      *
343      */

344     public void setDomain(String JavaDoc domain)
345     {
346         this.domain = domain.trim();
347     }
348     
349 }
350
Popular Tags