View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.control.form;
16  
17  import org.figure8.join.control.JoinForm;
18  import org.figure8.join.control.JoinAction;
19  import org.figure8.join.control.action.UserActions;
20  import org.figure8.join.control.action.CreateUserAction;
21  
22  import org.apache.struts.action.ActionMapping;
23  
24  import javax.servlet.http.HttpServletRequest;
25  /**
26   * Form object used for manipulating Users into Join application.
27   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
28   * @version $Revision: 1.2 $
29   *
30   * @struts.form name="userForm"
31   */
32  public class UserForm extends JoinForm{
33  
34     // Attributes ---------------------------------------------------------------
35  
36     /** The current user login identifier */
37     private String login;
38     /** This user password */
39     private String password;
40     /** The current user password confirmation */
41     private String password2;
42     /** This user lastname */
43     private String lastname;
44     /** The current user firstname */
45     private String firstname;
46     /** This user mail address */
47     private String mail;
48     /** The current user phone number */
49     private String phone;
50     /** This user team description */
51     private String team;
52  
53  
54     // Constructors -------------------------------------------------------------
55  
56     /** Creates a new instance of UserForm */
57     public UserForm(){
58     }
59  
60  
61     // Public -------------------------------------------------------------------
62  
63     /** @return Login identifier of this user */
64     public String getLogin(){
65        return login;
66     }
67     /** @param login Login identifier of the current user */
68     public void setLogin(String login){
69        this.login = login;
70     }
71     /** @return Password for this user */
72     public String getPassword(){
73        return password;
74     }
75     /** @param password Password for the current user */
76     public void setPassword(String password){
77        this.password = password;
78     }
79     /** @return User password confirmation */
80     public String getPassword2(){
81        return password2;
82     }
83     /** @param cPassword User password confirmation */
84     public void setPassword2(String cPassword){
85        this.password2 = cPassword;
86     }
87     /** @return The current user lastname */
88     public String getLastname(){
89        return lastname;
90     }
91     /** @param lastname This user lastname */
92     public void setLastname(String lastname){
93        this.lastname = lastname;
94     }
95     /** @return This current user first name */
96     public String getFirstname(){
97        return firstname;
98     }
99     /** @param firstname This user firstname */
100    public void setFirstname(String firstname){
101       this.firstname = firstname;
102    }
103    /** @return This user mail address */
104    public String getMail(){
105       return mail;
106    }
107    /** @param mail New mail address for this user */
108    public void setMail(String mail){
109       this.mail = mail;
110    }
111    /** @return This user phone number */
112    public String getPhone(){
113       return phone;
114    }
115    /** @param phone New phone number to assign to user */
116    public void setPhone(String phone){
117       this.phone = phone;
118    }
119    /** @return This user team description */
120    public String getTeam(){
121       return team;
122    }
123    /** @param team This user team description */
124    public void setTeam(String team){
125       this.team = team;
126    }
127 
128 
129    // Implementation of JoinForm -----------------------------------------------
130 
131    /**
132     * Validation of the form attributes.
133     * @param operation String representing the operation to invoke on Action
134     * @param mapping Mapping between forwards name and path for this action
135     * @param request The servlet container request wrapper
136     */
137    public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
138 
139       if (UserActions.LOAD_OP.equals(operation)){
140          // Check and see if login is missing wether in request or in session.
141          if (login == null || login.length() == 0)
142             if (!JoinAction.isLoggedIn(request))
143                addActionError("errors.required", getGuiMessageResources().getMessage("label.user.login"));
144       }
145       else if (UserActions.SAVE_OP.equals(operation)
146               || CreateUserAction.CREATE_OP.equals(operation)){
147          // Check and see if login is missing.
148          if (login == null || login.length() == 0)
149             addActionError("errors.required", getGuiMessageResources().getMessage("label.user.login"));
150          // Check and see if password is missing.
151          if (password == null || password.length() == 0)
152             addActionError("errors.required", getGuiMessageResources().getMessage("label.user.password"));
153          // Check and see if password confirmation is missing.
154          if (password2 == null || password2.length() == 0)
155             addActionError("errors.required", getGuiMessageResources().getMessage("label.user.cpassword"));
156          else if (!password2.equals(password))
157             addActionError("errors.different", getGuiMessageResources().getMessage("label.user.cpassword"),
158                     getGuiMessageResources().getMessage("label.user.password"));
159          // Check and see if lastname is missing.
160          if (lastname == null || lastname.length() == 0)
161             addActionError("errors.required", getGuiMessageResources().getMessage("label.user.lastname"));
162          // Check and see if firstname is missing.
163          if (firstname == null || firstname.length() == 0)
164             addActionError("errors.required", getGuiMessageResources().getMessage("label.user.firstname"));
165       }
166    }
167 
168 
169    // Override of ActionForm ---------------------------------------------------
170 
171    /**
172     * Reset form attributes.
173     * @param mapping Mapping between forwards name and path for this action
174     * @param request The servlet container request wrapper
175     */
176    public void reset(ActionMapping mapping, HttpServletRequest request){
177       login = null;
178       password = null;
179       password2 = null;
180       lastname = null;
181       firstname = null;
182       mail = null;
183       phone = null;
184       team = null;
185    }
186 }