View Javadoc

1   /*Copyright (C) 2004-... Stephane Gauchet for Hyphonem
2   
3    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
4   
5    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6   
7    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8    
9    Written by St�phane Gauchet
10   mail me at : sgauchet@free.fr
11   */
12  package fr.hyphonem.conges.forms;
13  
14  import javax.servlet.http.HttpServletRequest;
15  
16  import org.apache.regexp.RE;
17  import org.apache.struts.action.ActionError;
18  import org.apache.struts.action.ActionErrors;
19  import org.apache.struts.action.ActionForm;
20  import org.apache.struts.action.ActionMapping;
21  
22  /**
23   * @author Stephane Gauchet pour Hyphonem
24   * 
25   */
26  public class LoginForm extends ActionForm {
27  	/**
28  	 * 
29  	 */
30  	private static final long serialVersionUID = 1L;
31  
32  	private String login;
33  
34  	private String password;
35  
36  	/**
37  	 * Constructor for AbsForm.
38  	 */
39  	public LoginForm() {
40  		super();
41  		resetFields();
42  	}
43  
44  	/**
45  	 * Reset all properties to their default values.
46  	 * 
47  	 * @param mapping
48  	 *            The mapping used to select this instance
49  	 * @param request
50  	 *            The servlet request we are processing
51  	 */
52  	public void reset(ActionMapping mapping, HttpServletRequest request) {
53  		resetFields();
54  	}
55  
56  	private void resetFields() {
57  		login = "";
58  		password = "";
59  	}
60  
61  	public ActionErrors validate(ActionMapping mapping,
62  			HttpServletRequest request) {
63  		ActionErrors errors = new ActionErrors();
64  
65  		if (login == null || login.equals("")) {
66  			errors.add("login.required", new ActionError("login.required"));
67  		}
68  		if (password == null || password.equals("")) {
69  			errors.add("password.required",
70  					new ActionError("password.required"));
71  		}
72  
73  		// test sur le contenu des champs via regexp
74  		RE regexp = new RE("^[a-zA-Z0-9]*$");
75  		if (!regexp.match(login)) {
76  			errors.add("error.alnum", new ActionError("error.alnum", "login"));
77  		}
78  		if (!regexp.match(password)) {
79  			errors.add("error.alnum",
80  					new ActionError("error.alnum", "password"));
81  		}
82  
83  		request.setAttribute("loginForm", this);
84  		return errors;
85  	}
86  
87  	/**
88  	 * @return login
89  	 */
90  	public String getLogin() {
91  		return login;
92  	}
93  
94  	/**
95  	 * @return password
96  	 */
97  	public String getPassword() {
98  		return password;
99  	}
100 
101 	/**
102 	 * @param string
103 	 */
104 	public void setLogin(String string) {
105 		login = string;
106 	}
107 
108 	/**
109 	 * @param string
110 	 */
111 	public void setPassword(String string) {
112 		password = string;
113 	}
114 
115 }