View Javadoc

1   /***
2    *  The contents of this file are subject to the Mozilla Public
3    *  License Version 1.1 (the "License"); you may not use this file
4    *  except in compliance with the License. You may obtain a copy of
5    *  the License at http://www.mozilla.org/MPL/
6    *
7    *  Software distributed under the License is distributed on an "AS
8    *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9    *  implied. See the License for the specific language governing
10   *  rights and limitations under the License.
11   *
12   *  The Original Code is pow2toolkit library.
13   *
14   *  The Initial Owner of the Original Code is
15   *  Power Of Two S.R.L. (www.pow2.com)
16   *
17   *  Portions created by Power Of Two S.R.L. are
18   *  Copyright (C) Power Of Two S.R.L.
19   *  All Rights Reserved.
20   *
21   * Contributor(s):
22   */
23  package com.pow2.struts.forms;
24  
25  import javax.servlet.http.*;
26  
27  import org.apache.log4j.Category;
28  import org.apache.struts.action.*;
29  
30  import com.pow2.user.User;
31  import com.pow2.user.UserManager;
32  import com.pow2.user.dao.UserDAO;
33  import com.pow2.user.dao.UserDAOFactory;
34  
35  import com.pow2.util.Util;
36  
37  /***
38   *  Struts RegistrationForm class.
39   *
40   * @author  Massimiliano Farnea
41   * @created  4 maggio 2002
42   */
43  public class RegistrationForm extends ActionForm
44  {
45    private Category cat = Category.getInstance(this.getClass());
46  
47    private String city = "";
48    private String email = "";
49    private String fax = "";
50    private String firstName = "";
51    private String id = "-1";
52    private String lastName = "";
53    private String login = "";
54    private String mobile = "";
55    private String passwd = "";
56    private String passwdConfirm = "";
57    private String phone = "";
58    private String state = "";
59    private String street = "";
60    private String zipCode = "";
61  
62  
63    /***  Default constructor. */
64    public RegistrationForm()
65    {
66    }
67  
68  
69    /***
70     *  Gets the city attribute of the RegistrationForm object
71     *
72     * @return  The city value
73     */
74    public String getCity()
75    {
76      return city;
77    }
78  
79  
80    /***
81     *  Gets the email attribute of the RegistrationForm object
82     *
83     * @return  The email value
84     */
85    public String getEmail()
86    {
87      return email;
88    }
89  
90  
91    /***
92     *  Gets the fax attribute of the RegistrationForm object
93     *
94     * @return  The fax value
95     */
96    public String getFax()
97    {
98      return fax;
99    }
100 
101 
102   /***
103    *  Gets the firstName attribute of the RegistrationForm object
104    *
105    * @return  The firstName value
106    */
107   public String getFirstName()
108   {
109     return firstName;
110   }
111 
112 
113   /***
114    *  Gets the id attribute of the RegistrationForm object
115    *
116    * @return  The id value
117    */
118   public String getId()
119   {
120     return id;
121   }
122 
123 
124   /***
125    *  Gets the lastName attribute of the RegistrationForm object
126    *
127    * @return  The lastName value
128    */
129   public String getLastName()
130   {
131     return lastName;
132   }
133 
134 
135   /***
136    *  Gets the login attribute of the RegistrationForm object
137    *
138    * @return  The login value
139    */
140   public String getLogin()
141   {
142     return login;
143   }
144 
145 
146   /***
147    *  Gets the mobile attribute of the RegistrationForm object
148    *
149    * @return  The mobile value
150    */
151   public String getMobile()
152   {
153     return mobile;
154   }
155 
156 
157   /***
158    *  Gets the passwd attribute of the RegistrationForm object
159    *
160    * @return  The passwd value
161    */
162   public String getPasswd()
163   {
164     return passwd;
165   }
166 
167 
168   /***
169    *  Gets the passwdConfirm attribute of the RegistrationForm object
170    *
171    * @return  The passwdConfirm value
172    */
173   public String getPasswdConfirm()
174   {
175     return passwdConfirm;
176   }
177 
178 
179   /***
180    *  Gets the phone attribute of the RegistrationForm object
181    *
182    * @return  The phone value
183    */
184   public String getPhone()
185   {
186     return phone;
187   }
188 
189 
190   /***
191    *  Gets the state attribute of the RegistrationForm object
192    *
193    * @return  The state value
194    */
195   public String getState()
196   {
197     return state;
198   }
199 
200 
201   /***
202    *  Gets the street attribute of the RegistrationForm object
203    *
204    * @return  The street value
205    */
206   public String getStreet()
207   {
208     return street;
209   }
210 
211 
212   /***
213    *  Gets the zipCode attribute of the RegistrationForm object
214    *
215    * @return  The zipCode value
216    */
217   public String getZipCode()
218   {
219     return zipCode;
220   }
221 
222 
223   /***
224    *  Reset all bean properties to their default state.
225    *  This method is called before the properties are repopulated by the controller servlet.
226    *  <br>
227    *  The form bean is always filled with the data of the current user in session.
228    *  In this way I can use the bean for upgrading actions.
229    *
230    * @param  mapping The mapping used to select this instance
231    * @param  request The servlet request we are processing
232    */
233   public void reset(ActionMapping mapping, HttpServletRequest request)
234   {
235     User user = UserManager.instance().getUser(request);
236 
237     // refactoring... use BeanUtils introspection methods to
238     // exchange data between the two beans...
239     if (user != null)
240     {
241       id            = user.getId();
242       login         = user.getLogin();
243       passwd        = user.getPasswd();
244       passwdConfirm = user.getPasswd();
245       firstName     = user.getFirstName();
246       lastName      = user.getLastName();
247       email         = user.getEmail();
248       street        = user.getStreet();
249       city          = user.getCity();
250       zipCode       = user.getZipCode();
251       state         = user.getState();
252       phone         = user.getPhone();
253       mobile        = user.getMobile();
254       fax           = user.getFax();
255     }
256   }
257 
258 
259   /***
260    *  Sets the city attribute of the RegistrationForm object
261    *
262    * @param  v The new city value
263    */
264   public void setCity(String v)
265   {
266     this.city = v;
267   }
268 
269 
270   /***
271    *  Sets the email attribute of the RegistrationForm object
272    *
273    * @param  v The new email value
274    */
275   public void setEmail(String v)
276   {
277     this.email = v;
278   }
279 
280 
281   /***
282    *  Sets the fax attribute of the RegistrationForm object
283    *
284    * @param  v The new fax value
285    */
286   public void setFax(String v)
287   {
288     this.fax = v;
289   }
290 
291 
292   /***
293    *  Sets the firstName attribute of the RegistrationForm object
294    *
295    * @param  v The new firstName value
296    */
297   public void setFirstName(String v)
298   {
299     this.firstName = v;
300   }
301 
302 
303   /***
304    *  Sets the id attribute of the RegistrationForm object
305    *
306    * @param  id The new id value
307    */
308   public void setId(String id)
309   {
310     this.id = id;
311   }
312 
313 
314   /***
315    *  Sets the lastName attribute of the RegistrationForm object
316    *
317    * @param  v The new lastName value
318    */
319   public void setLastName(String v)
320   {
321     this.lastName = v;
322   }
323 
324 
325   /***
326    *  Sets the login attribute of the RegistrationForm object
327    *
328    * @param  v The new login value
329    */
330   public void setLogin(String v)
331   {
332     this.login = v;
333   }
334 
335 
336   /***
337    *  Sets the mobile attribute of the RegistrationForm object
338    *
339    * @param  v The new mobile value
340    */
341   public void setMobile(String v)
342   {
343     this.mobile = v;
344   }
345 
346 
347   /***
348    *  Sets the passwd attribute of the RegistrationForm object
349    *
350    * @param  v The new passwd value
351    */
352   public void setPasswd(String v)
353   {
354     this.passwd = v;
355   }
356 
357 
358   /***
359    *  Sets the passwdConfirm attribute of the RegistrationForm object
360    *
361    * @param  v The new passwdConfirm value
362    */
363   public void setPasswdConfirm(String v)
364   {
365     this.passwdConfirm = v;
366   }
367 
368 
369   /***
370    *  Sets the phone attribute of the RegistrationForm object
371    *
372    * @param  v The new phone value
373    */
374   public void setPhone(String v)
375   {
376     this.phone = v;
377   }
378 
379 
380   /***
381    *  Sets the state attribute of the RegistrationForm object
382    *
383    * @param  v The new state value
384    */
385   public void setState(String v)
386   {
387     this.state = v;
388   }
389 
390 
391   /***
392    *  Sets the street attribute of the RegistrationForm object
393    *
394    * @param  v The new street value
395    */
396   public void setStreet(String v)
397   {
398     this.street = v;
399   }
400 
401 
402   /***
403    *  Sets the zipCode attribute of the RegistrationForm object
404    *
405    * @param  v The new zipCode value
406    */
407   public void setZipCode(String v)
408   {
409     this.zipCode = v;
410   }
411 
412 
413 
414   /***
415    *  Description of the Method
416    *
417    * @param  mapping Description of the Parameter
418    * @param  request Description of the Parameter
419    * @return  Description of the Return Value
420    */
421   public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
422   {
423     ActionErrors errors = new ActionErrors();
424 
425     if (Util.isNull(login))
426       errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.username.invalid"));
427 
428     if ((Util.isNull(passwd)) || !passwd.equals(passwdConfirm))
429       errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.passwd.invalid"));
430 
431     if (Util.isNull(email))
432       errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.email.invalid"));
433 
434     // check if the given login already exists into the user database;
435     try
436     {
437       UserDAO dao = UserDAOFactory.instance().getUserDAO();
438 
439       //if (dao.loginExists(login))
440       //{
441       //  errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.username.exists"));
442       //  cat.warn("::validate - login name used by another user");
443       //}
444     }
445     catch (Exception e)
446     {
447       cat.error("::validate - error in UserDAO.testLogin", e);
448     }
449 
450     return (errors.size() > 0) ? errors : null;
451   }
452 }