KickJava   Java API By Example, From Geeks To Geeks.

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


1
2 package com.quikj.application.communicator.applications.webtalk.controller;
3
4 import javax.servlet.http.HttpServletRequest JavaDoc;
5 import org.apache.struts.action.*;
6 import java.util.*;
7
8 /**
9  *
10  * @author bhm
11  */

12 public class RestrictedAccessUserManagementForm extends ActionForm
13 {
14     
15     /** Holds value of property name. */
16     private String JavaDoc name;
17     
18     /** Holds value of property password. */
19     private String JavaDoc password;
20     
21     /** Holds value of property verifyPassword. */
22     private String JavaDoc verifyPassword;
23     
24     /** Holds value of property submit. */
25     private String JavaDoc submit;
26     
27     /** Holds value of property additionalInfo. */
28     private String JavaDoc additionalInfo;
29     
30     /** Holds value of property fullName. */
31     private String JavaDoc fullName;
32     
33     /** Holds value of property email. */
34     private String JavaDoc email;
35     
36     /** Holds value of property infoParms. */
37     private HashMap infoParms;
38     
39     private static int MIN_PASSWORD_LENGTH = 4;
40     
41     
42     /** Creates a new instance of RestrictedAccessUserManagementForm */
43     public RestrictedAccessUserManagementForm()
44     {
45         reset();
46     }
47     
48     /** Getter for property name.
49      * @return Value of property name.
50      *
51      */

52     public String JavaDoc getName()
53     {
54         return this.name;
55     }
56     
57     /** Setter for property name.
58      * @param name New value of property name.
59      *
60      */

61     public void setName(String JavaDoc name)
62     {
63         this.name = name.trim();
64     }
65     
66     /** Getter for property password.
67      * @return Value of property password.
68      *
69      */

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

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

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

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

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

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

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

133     public void setAdditionalInfo(String JavaDoc additionalInfo)
134     {
135         this.additionalInfo = additionalInfo.trim();
136     }
137     
138     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request)
139     {
140         // Check for mandatory data
141
ActionErrors errors = new ActionErrors();
142         
143         if ((name == null) || (name.length() == 0))
144         {
145             errors.add("name", new ActionError("error.restr.accessuser.no.name"));
146         }
147         
148         if (DataCheckUtility.followsTableIdRules(name) == false)
149         {
150             errors.add("name", new ActionError("error.restr.accessuser.invalid.id"));
151         }
152         
153         // for create-specific options
154
if (submit.equals("Create") == true)
155         {
156             if ((password == null) || (password.length() == 0))
157             {
158                 errors.add("password", new ActionError("error.user.no.password"));
159             }
160             else
161             {
162                 UserManagementForm.validatePassword(password, errors);
163                 
164                 if (verifyPassword != null)
165                 {
166                     if (password.equals(verifyPassword) == false)
167                     {
168                         errors.add("password", new ActionError("error.user.password.mismatch"));
169                     }
170                 }
171                 else
172                 {
173                     errors.add("password", new ActionError("error.user.password.mismatch"));
174                 }
175             }
176         }
177         
178         // for modify-specific options
179
if (submit.equals("Modify") == true)
180         {
181             if ((password != null) && (password.length() > 0))
182             {
183                 UserManagementForm.validatePassword(password, errors);
184                 
185                 if (verifyPassword != null)
186                 {
187                     if (password.equals(verifyPassword) == false)
188                     {
189                         errors.add("password", new ActionError("error.user.password.mismatch"));
190                     }
191                 }
192                 else
193                 {
194                     errors.add("password", new ActionError("error.user.password.mismatch"));
195                 }
196             }
197         }
198         
199         if ((submit.equals("Create") == true) || (submit.equals("Modify") == true))
200         {
201             // validate additional info input, convert to infoParms
202
processAdditionalInfo(getAdditionalInfo(), errors);
203             
204         }
205         
206         return errors;
207     }
208     
209     private void processAdditionalInfo(String JavaDoc info, ActionErrors errors)
210     {
211         /*
212          * USER INPUT RULES:
213          *
214          * zero or more pairs of: key = value (spaces around '=' doesn't matter)
215          * if one pair, key must be 'info'
216          * if > one pair, pairs must be separated by <CR> or newline
217          * <CR> or newline not allowed in any key or any value
218          * no duplicate keys allowed
219          * if key or value contains: =, it must be escaped as: &eq;
220          * if key or value contains: &, it must be escaped as: &amp;
221          *
222          */

223         
224         if (info != null)
225         {
226             info = info.trim();
227             if (info.length() > 0)
228             {
229                 StringTokenizer strtok = new StringTokenizer(info, "\n");
230                 int num_pairs = strtok.countTokens();
231                 
232                 infoParms = new HashMap();
233                 
234                 for (int i = 0; i < num_pairs; i++)
235                 {
236                     String JavaDoc pair = strtok.nextToken();
237                     
238                     StringTokenizer pairtok = new StringTokenizer(pair, "=", true);
239                     int num_subparms = pairtok.countTokens();
240                     
241                     if (num_subparms != 3)
242                     {
243                         errors.add("additionalInfo", new ActionError("error.restr.accessuser.info.pairtokens",
244                         new Integer JavaDoc(i + 1)));
245                         
246                         continue;
247                     }
248                     
249                     String JavaDoc input_key = pairtok.nextToken().trim();
250                     pairtok.nextToken();
251                     String JavaDoc input_value = pairtok.nextToken().trim();
252                     
253                     if (num_pairs == 1)
254                     {
255                         if (input_key.equals("info") == false)
256                         {
257                             errors.add("additionalInfo", new ActionError("error.restr.accessuser.info.singlepairkey"));
258                             
259                             continue;
260                         }
261                     }
262                     
263                     String JavaDoc key = Utilities.deEscapeEqual(input_key);
264                     String JavaDoc value = Utilities.deEscapeEqual(input_value);
265                     
266                     if (infoParms.containsKey(key) == true)
267                     {
268                         errors.add("additionalInfo", new ActionError("error.restr.accessuser.info.duplicatekey",
269                         new Integer JavaDoc(i + 1)));
270                         
271                         continue;
272                     }
273                     
274                     infoParms.put(key, value);
275                 }
276             }
277         }
278     }
279     
280     public void reset()
281     {
282         name = null;
283         password = null;
284         verifyPassword = null;
285         submit = "Find";
286         additionalInfo = null;
287         fullName = null;
288         email = null;
289     }
290     
291     /** Getter for property fullName.
292      * @return Value of property fullName.
293      *
294      */

295     public String JavaDoc getFullName()
296     {
297         return this.fullName;
298     }
299     
300     /** Setter for property fullName.
301      * @param fullName New value of property fullName.
302      *
303      */

304     public void setFullName(String JavaDoc fullName)
305     {
306         this.fullName = fullName.trim();
307     }
308     
309     /** Getter for property address.
310      * @return Value of property address.
311      *
312      */

313     public String JavaDoc getEmail()
314     {
315         return this.email;
316     }
317     
318     /** Setter for property address.
319      * @param address New value of property address.
320      *
321      */

322     public void setEmail(String JavaDoc email)
323     {
324         this.email = email.trim();
325     }
326     
327     /** Getter for property infoParms.
328      * @return Value of property infoParms.
329      *
330      */

331     public HashMap getInfoParms()
332     {
333         return this.infoParms;
334     }
335     
336     /** Setter for property infoParms.
337      * @param infoParms New value of property infoParms.
338      *
339      */

340     public void setInfoParms(HashMap info_parms)
341     {
342         infoParms = info_parms;
343         additionalInfo = null;
344         
345         if (infoParms != null)
346         {
347             Set key_set = infoParms.keySet();
348             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
349             
350             for (Iterator i = key_set.iterator(); i.hasNext();)
351             {
352                 String JavaDoc key = (String JavaDoc) i.next();
353                 String JavaDoc value = (String JavaDoc) infoParms.get(key);
354                 
355                 buf.append(Utilities.escapeEqual(key) + "=" + Utilities.escapeEqual(value));
356                 if (i.hasNext() == true)
357                 {
358                     buf.append('\n');
359                 }
360             }
361             
362             additionalInfo = buf.toString();
363         }
364     }
365     
366 }
367
Popular Tags