KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * UserManagementForm.java
3  *
4  */

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

20 public class UserManagementForm extends ActionForm
21 {
22
23     /** Holds value of property name. */
24     private String JavaDoc name;
25
26     /** Holds value of property password. */
27     private String JavaDoc password;
28
29     /** Holds value of property verifyPassword. */
30     private String JavaDoc verifyPassword;
31
32     /** Holds value of property submit. */
33     private String JavaDoc submit;
34
35     /** Holds value of property additionalInfo. */
36     private String JavaDoc additionalInfo;
37
38     /** Holds value of property belongsToGroups. */
39     private Object JavaDoc[] belongsToGroups;
40
41     /** Holds value of property ownsGroups. */
42     private Object JavaDoc[] ownsGroups;
43
44     /** Holds value of property fullName. */
45     private String JavaDoc fullName;
46
47     /** Holds value of property address. */
48     private String JavaDoc address;
49
50     /** Holds value of property unavailXferTo. */
51     private String JavaDoc unavailXferTo;
52
53     private static int MIN_PASSWORD_LENGTH = 4;
54
55     /** Holds value of property userGroups. */
56     private ArrayList userGroups = new ArrayList();
57
58     /** Holds value of property gatekeeper. */
59     private String JavaDoc gatekeeper;
60
61     /** Holds value of property domain. */
62     private String JavaDoc domain;
63
64     /** Creates a new instance of AccountManagementForm */
65     public UserManagementForm()
66     {
67         reset();
68     }
69
70     /**
71      * Getter for property name.
72      *
73      * @return Value of property name.
74      *
75      */

76     public String JavaDoc getName()
77     {
78         return this.name;
79     }
80
81     /**
82      * Setter for property name.
83      *
84      * @param name
85      * New value of property name.
86      *
87      */

88     public void setName(String JavaDoc name)
89     {
90         this.name = name.trim();
91     }
92
93     /**
94      * Getter for property password.
95      *
96      * @return Value of property password.
97      *
98      */

99     public String JavaDoc getPassword()
100     {
101         return this.password;
102     }
103
104     /**
105      * Setter for property password.
106      *
107      * @param password
108      * New value of property password.
109      *
110      */

111     public void setPassword(String JavaDoc password)
112     {
113         this.password = password;
114     }
115
116     /**
117      * Getter for property verifyPassword.
118      *
119      * @return Value of property verifyPassword.
120      *
121      */

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

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

145     public String JavaDoc getSubmit()
146     {
147         return this.submit;
148     }
149
150     /**
151      * Setter for property submit.
152      *
153      * @param submit
154      * New value of property submit.
155      *
156      */

157     public void setSubmit(String JavaDoc submit)
158     {
159         this.submit = submit;
160     }
161
162     /**
163      * Getter for property additionalInfo.
164      *
165      * @return Value of property additionalInfo.
166      *
167      */

168     public String JavaDoc getAdditionalInfo()
169     {
170         return this.additionalInfo;
171     }
172
173     /**
174      * Setter for property additionalInfo.
175      *
176      * @param additionalInfo
177      * New value of property additionalInfo.
178      *
179      */

180     public void setAdditionalInfo(String JavaDoc additionalInfo)
181     {
182         this.additionalInfo = additionalInfo.trim();
183     }
184
185     public ActionErrors validate(ActionMapping mapping,
186             HttpServletRequest JavaDoc request)
187     {
188         if ((submit.startsWith("Finished") == true)
189                 || (submit.startsWith("Cancel") == true))
190         {
191             return null;
192         }
193
194         // Check for mandatory data
195
ActionErrors errors = new ActionErrors();
196         try
197         {
198             if ((name == null) || (name.length() == 0))
199             {
200                 errors.add("name", new ActionError("error.user.no.name"));
201             }
202
203             if (DataCheckUtility.followsTableIdRules(name) == false)
204             {
205                 errors.add("name", new ActionError("error.user.invalid.id"));
206             }
207
208             // for create-specific options
209
if (submit.startsWith("Create") == true)
210             {
211                 if ((password == null) || (password.length() == 0))
212                 {
213                     errors.add("password", new ActionError(
214                             "error.user.no.password"));
215                 }
216                 else
217                 {
218                     validatePassword(password, errors);
219
220                     if (verifyPassword != null)
221                     {
222                         if (password.equals(verifyPassword) == false)
223                         {
224                             errors.add("password", new ActionError(
225                                     "error.user.password.mismatch"));
226                         }
227                     }
228                     else
229                     {
230                         errors.add("password", new ActionError(
231                                 "error.user.password.mismatch"));
232                     }
233                 }
234             }
235
236             // for modify-specific options
237
if (submit.equals("Modify") == true)
238             {
239                 if ((password != null) && (password.length() > 0))
240                 {
241                     validatePassword(password, errors);
242
243                     if (verifyPassword != null)
244                     {
245                         if (password.equals(verifyPassword) == false)
246                         {
247                             errors.add("password", new ActionError(
248                                     "error.user.password.mismatch"));
249                         }
250                     }
251                     else
252                     {
253                         errors.add("password", new ActionError(
254                                 "error.user.password.mismatch"));
255                     }
256                 }
257             }
258
259             // general checks for create/modify
260
if ((submit.startsWith("Create") == true)
261                     || (submit.equals("Modify") == true))
262             {
263                 // check owned vs. member groups, no overlap
264
if (ownsGroups != null)
265                 {
266                     if (belongsToGroups != null)
267                     {
268                         for (int i = 0; i < ownsGroups.length; i++)
269                         {
270                             String JavaDoc name = ownsGroups[i].toString();
271
272                             for (int j = 0; j < belongsToGroups.length; j++)
273                             {
274                                 if (belongsToGroups[j].toString().equals(name) == true)
275                                 {
276                                     errors
277                                             .add(
278                                                     "belongsToGroups",
279                                                     new ActionError(
280                                                             "error.user.groups.illegal"));
281                                     break;
282                                 }
283                             }
284                         }
285                     }
286                 }
287
288                 // check unavailable xfer-to != this user name
289
if (unavailXferTo != null)
290                 {
291                     if (unavailXferTo.equals(name) == true)
292                     {
293                         errors.add("unavailXferTo", new ActionError(
294                                 "error.user.unavail.invalid"));
295                     }
296                 }
297
298             }
299
300             if (errors.isEmpty() == false)
301             {
302                 GroupTable groups = new GroupTable();
303                 Connection c = (Connection) request.getSession().getAttribute(
304                         "connection");
305
306                 groups.setConnection(c);
307                 ArrayList group_list = groups.list(domain);
308
309                 if (group_list != null)
310                 {
311                     ArrayList list = new ArrayList();
312                     Iterator iter = group_list.iterator();
313
314                     while (iter.hasNext() == true)
315                     {
316                         String JavaDoc group = (String JavaDoc) iter.next();
317
318                         if (group.equals(domain) == false)
319                         {
320                             list.add(new LabelValueBean(group, URLEncoder
321                                     .encode(group, "UTF-8")));
322                         }
323                     }
324
325                     setUserGroups(list);
326                 }
327             }
328         }
329         catch (Exception JavaDoc e)
330         {
331             errors.add("unavailXferTo", new ActionError(
332             "error.internal.error"));
333         }
334         return errors;
335     }
336
337     public static void validatePassword(String JavaDoc password, ActionErrors errors)
338     {
339         password = password.trim();
340         if (password.length() == 0)
341         {
342             errors.add("password", new ActionError(
343                     "error.user.password.hasblanks"));
344         }
345         else
346         {
347             int len = password.length();
348
349             if (len < MIN_PASSWORD_LENGTH)
350             {
351                 errors.add("password", new ActionError(
352                         "error.user.password.tooshort", new Integer JavaDoc(
353                                 MIN_PASSWORD_LENGTH)));
354             }
355
356             // it must have both letters and digits
357
boolean letter = false;
358             boolean digit = false;
359
360             for (int i = 0; i < len; i++)
361             {
362                 char c = password.charAt(i);
363                 if (Character.isDigit(c) == true)
364                 {
365                     digit = true;
366                 }
367                 else if (Character.isLetter(c) == true)
368                 {
369                     letter = true;
370                 }
371                 else if (Character.isSpaceChar(c) == true)
372                 {
373                     errors.add("password", new ActionError(
374                             "error.user.password.hasblanks"));
375                 }
376             }
377
378             if ((letter == false) || (digit == false))
379             {
380                 errors.add("password", new ActionError(
381                         "error.user.password.content"));
382             }
383         }
384     }
385
386     public void reset()
387     {
388         belongsToGroups = null;
389         ownsGroups = null;
390         name = null;
391         password = null;
392         verifyPassword = null;
393         submit = "Find";
394         additionalInfo = null;
395         fullName = null;
396         address = null;
397         unavailXferTo = null;
398     }
399
400     /**
401      * Getter for property belongsToGroups.
402      *
403      * @return Value of property belongsToGroups.
404      *
405      */

406     public Object JavaDoc[] getBelongsToGroups()
407     {
408         return this.belongsToGroups;
409     }
410
411     /**
412      * Setter for property belongsToGroups.
413      *
414      * @param belongsToGroups
415      * New value of property belongsToGroups.
416      *
417      */

418     public void setBelongsToGroups(Object JavaDoc[] belongsToGroups)
419     {
420         this.belongsToGroups = belongsToGroups;
421     }
422
423     /**
424      * Getter for property ownsGroups.
425      *
426      * @return Value of property ownsGroups.
427      *
428      */

429     public Object JavaDoc[] getOwnsGroups()
430     {
431         return this.ownsGroups;
432     }
433
434     /**
435      * Setter for property ownsGroups.
436      *
437      * @param ownsGroups
438      * New value of property ownsGroups.
439      *
440      */

441     public void setOwnsGroups(Object JavaDoc[] ownsGroups)
442     {
443         this.ownsGroups = ownsGroups;
444     }
445
446     /**
447      * Getter for property fullName.
448      *
449      * @return Value of property fullName.
450      *
451      */

452     public String JavaDoc getFullName()
453     {
454         return this.fullName;
455     }
456
457     /**
458      * Setter for property fullName.
459      *
460      * @param fullName
461      * New value of property fullName.
462      *
463      */

464     public void setFullName(String JavaDoc fullName)
465     {
466         this.fullName = fullName.trim();
467     }
468
469     /**
470      * Getter for property address.
471      *
472      * @return Value of property address.
473      *
474      */

475     public String JavaDoc getAddress()
476     {
477         return this.address;
478     }
479
480     /**
481      * Setter for property address.
482      *
483      * @param address
484      * New value of property address.
485      *
486      */

487     public void setAddress(String JavaDoc address)
488     {
489         this.address = address.trim();
490     }
491
492     /**
493      * Getter for property unavailXferTo.
494      *
495      * @return Value of property unavailXferTo.
496      *
497      */

498     public String JavaDoc getUnavailXferTo()
499     {
500         return this.unavailXferTo;
501     }
502
503     /**
504      * Setter for property unavailXferTo.
505      *
506      * @param unavailXferTo
507      * New value of property unavailXferTo.
508      *
509      */

510     public void setUnavailXferTo(String JavaDoc unavailXferTo)
511     {
512         this.unavailXferTo = unavailXferTo.trim();
513     }
514
515     /**
516      * Getter for property usrGroups.
517      *
518      * @return Value of property usrGroups.
519      *
520      */

521     public ArrayList getUserGroups()
522     {
523         return this.userGroups;
524     }
525
526     /**
527      * Setter for property usrGroups.
528      *
529      * @param usrGroups
530      * New value of property usrGroups.
531      *
532      */

533     public void setUserGroups(ArrayList userGroups)
534     {
535         this.userGroups = userGroups;
536     }
537
538     /**
539      * Getter for property gatekeeper.
540      *
541      * @return Value of property gatekeeper.
542      *
543      */

544     public String JavaDoc getGatekeeper()
545     {
546         return this.gatekeeper;
547     }
548
549     /**
550      * Setter for property gatekeeper.
551      *
552      * @param gatekeeper
553      * New value of property gatekeeper.
554      *
555      */

556     public void setGatekeeper(String JavaDoc gatekeeper)
557     {
558         this.gatekeeper = gatekeeper;
559     }
560
561     /**
562      * Getter for property domain.
563      *
564      * @return Value of property domain.
565      *
566      */

567     public String JavaDoc getDomain()
568     {
569         return this.domain;
570     }
571
572     /**
573      * Setter for property domain.
574      *
575      * @param domain
576      * New value of property domain.
577      *
578      */

579     public void setDomain(String JavaDoc domain)
580     {
581         this.domain = domain;
582     }
583
584 }
Popular Tags