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 java.text.ParseException;
15  import java.text.SimpleDateFormat;
16  
17  import javax.servlet.http.HttpServletRequest;
18  
19  import org.apache.regexp.RE;
20  import org.apache.struts.action.ActionError;
21  import org.apache.struts.action.ActionErrors;
22  import org.apache.struts.action.ActionForm;
23  import org.apache.struts.action.ActionMapping;
24  
25  /**
26   * @author Stephane Gauchet pour Hyphonem
27   * 
28   */
29  public class ModifyUserForm extends ActionForm {
30  	/**
31  	 * 
32  	 */
33  	private static final long serialVersionUID = 1L;
34  
35  	private String nom;
36  
37  	private String prenom;
38  
39  	private String email;
40  
41  	private boolean chief;
42  
43  	private String login;
44  
45  	private String password;
46  
47  	private boolean employee;
48  
49  	private String pays;
50  
51  	private String team;
52  
53  	private String entryDate;
54  
55  	private boolean dayoff1;
56  
57  	private boolean dayoff2;
58  
59  	private boolean dayoff3;
60  
61  	private boolean dayoff4;
62  
63  	private boolean dayoff5;
64  
65  	private boolean dayoff6;
66  
67  	private boolean dayoff7;
68  
69  	private boolean delete;
70  
71  	public ActionErrors validate(ActionMapping mapping,
72  			HttpServletRequest request) {
73  		ActionErrors errors = new ActionErrors();
74  
75  		if (login == null || login.equals("")) {
76  			errors.add("login.required", new ActionError("login.required"));
77  		}
78  		if (password == null || password.equals("")) {
79  			errors.add("password.required",
80  					new ActionError("password.required"));
81  		}
82  		if (nom == null || nom.equals("")) {
83  			errors.add("nom.required", new ActionError("nom.required"));
84  		}
85  		if (prenom == null || prenom.equals("")) {
86  			errors.add("prenom.required", new ActionError("prenom.required"));
87  		}
88  		if (email == null || email.equals("")) {
89  			errors.add("email.required", new ActionError("email.required"));
90  		}
91  		if (entryDate == null || entryDate.equals("")) {
92  			errors.add("entryDate.required", new ActionError(
93  					"entryDate.required"));
94  		}
95  
96  		try {
97  			new SimpleDateFormat("dd/MM/yyyy").parse(entryDate);
98  		} catch (ParseException e) {
99  			errors.add("error.date.format2", new ActionError(
100 					"error.date.format2"));
101 		}
102 
103 		RE regexp = new RE("^[a-zA-Z0-9]*$");
104 		if (!regexp.match(login)) {
105 			errors.add("error.alnum", new ActionError("error.alnum", "login"));
106 		}
107 		if (!regexp.match(password)) {
108 			errors.add("error.alnum",
109 					new ActionError("error.alnum", "password"));
110 		}
111 		if (!regexp.match(nom)) {
112 			errors.add("error.alnum", new ActionError("error.alnum", "nom"));
113 		}
114 		if (!regexp.match(prenom)) {
115 			errors.add("error.alnum", new ActionError("error.alnum", "prenom"));
116 		}
117 
118 		String emailPattern = "^[a-zA-Z]+[a-zA-Z0-9\\._-]*[a-zA-Z0-9]@[a-zA-Z]+"
119 				+ "[a-zA-Z0-9\\._-]*[a-zA-Z0-9]+\\.[a-zA-Z]{2,4}$";
120 		regexp = new RE(emailPattern);
121 		if (!regexp.match(email)) {
122 			errors.add("error.email", new ActionError("error.email", "email"));
123 		}
124 
125 		ModifyUserForm cu = new ModifyUserForm();
126 
127 		cu.setChief(chief);
128 		cu.setLogin(login);
129 		cu.setPassword(password);
130 		cu.setDayoff1(dayoff1);
131 		cu.setDayoff2(dayoff2);
132 		cu.setDayoff3(dayoff3);
133 		cu.setDayoff4(dayoff4);
134 		cu.setDayoff5(dayoff5);
135 		cu.setDayoff6(dayoff6);
136 		cu.setDayoff7(dayoff7);
137 		cu.setEmail(email);
138 		cu.setEmployee(employee);
139 		cu.setEntryDate(entryDate);
140 		cu.setNom(nom);
141 		cu.setPays(pays);
142 		cu.setPrenom(prenom);
143 		cu.setTeam(team);
144 		request.setAttribute("modifUserForm", cu);
145 
146 		return errors;
147 	}
148 
149 	/**
150 	 * @return email
151 	 */
152 	public String getEmail() {
153 		return email;
154 	}
155 
156 	/**
157 	 * @return nom
158 	 */
159 	public String getNom() {
160 		return nom;
161 	}
162 
163 	/**
164 	 * @return prenom
165 	 */
166 	public String getPrenom() {
167 		return prenom;
168 	}
169 
170 	/**
171 	 * @param string
172 	 */
173 	public void setEmail(String string) {
174 		email = string;
175 	}
176 
177 	/**
178 	 * @param string
179 	 */
180 	public void setNom(String string) {
181 		nom = string;
182 	}
183 
184 	/**
185 	 * @param string
186 	 */
187 	public void setPrenom(String string) {
188 		prenom = string;
189 	}
190 
191 	/**
192 	 * @return login
193 	 */
194 	public String getLogin() {
195 		return login;
196 	}
197 
198 	/**
199 	 * @return password
200 	 */
201 	public String getPassword() {
202 		return password;
203 	}
204 
205 	/**
206 	 * @param string
207 	 */
208 	public void setLogin(String string) {
209 		login = string;
210 	}
211 
212 	/**
213 	 * @param string
214 	 */
215 	public void setPassword(String string) {
216 		password = string;
217 	}
218 
219 	/**
220 	 * @return boolean
221 	 */
222 	public boolean isEmployee() {
223 		return employee;
224 	}
225 
226 	/**
227 	 * @param b
228 	 */
229 	public void setEmployee(boolean b) {
230 		employee = b;
231 	}
232 
233 	/**
234 	 * @return boolean
235 	 */
236 	public boolean isChief() {
237 		return chief;
238 	}
239 
240 	/**
241 	 * @param b
242 	 */
243 	public void setChief(boolean b) {
244 		chief = b;
245 	}
246 
247 	/**
248 	 * @return boolean
249 	 */
250 	public boolean isDelete() {
251 		return delete;
252 	}
253 
254 	/**
255 	 * @param b
256 	 */
257 	public void setDelete(boolean b) {
258 		delete = b;
259 	}
260 
261 	/**
262 	 * @return pays
263 	 */
264 	public String getPays() {
265 		return pays;
266 	}
267 
268 	/**
269 	 * @param string
270 	 */
271 	public void setPays(String string) {
272 		pays = string;
273 	}
274 
275 	/**
276 	 * @return team
277 	 */
278 	public String getTeam() {
279 		return team;
280 	}
281 
282 	/**
283 	 * @param string
284 	 */
285 	public void setTeam(String string) {
286 		team = string;
287 	}
288 
289 	/**
290 	 * @return Returns the entryDate.
291 	 */
292 	public String getEntryDate() {
293 		return entryDate;
294 	}
295 
296 	/**
297 	 * @param entryDate
298 	 *            The entryDate to set.
299 	 */
300 	public void setEntryDate(String entryDate) {
301 		this.entryDate = entryDate;
302 	}
303 
304 	public boolean isDayoff1() {
305 		return dayoff1;
306 	}
307 
308 	public void setDayoff1(boolean dayoff1) {
309 		this.dayoff1 = dayoff1;
310 	}
311 
312 	public boolean isDayoff2() {
313 		return dayoff2;
314 	}
315 
316 	public void setDayoff2(boolean dayoff2) {
317 		this.dayoff2 = dayoff2;
318 	}
319 
320 	public boolean isDayoff3() {
321 		return dayoff3;
322 	}
323 
324 	public void setDayoff3(boolean dayoff3) {
325 		this.dayoff3 = dayoff3;
326 	}
327 
328 	public boolean isDayoff4() {
329 		return dayoff4;
330 	}
331 
332 	public void setDayoff4(boolean dayoff4) {
333 		this.dayoff4 = dayoff4;
334 	}
335 
336 	public boolean isDayoff5() {
337 		return dayoff5;
338 	}
339 
340 	public void setDayoff5(boolean dayoff5) {
341 		this.dayoff5 = dayoff5;
342 	}
343 
344 	public boolean isDayoff6() {
345 		return dayoff6;
346 	}
347 
348 	public void setDayoff6(boolean dayoff6) {
349 		this.dayoff6 = dayoff6;
350 	}
351 
352 	public boolean isDayoff7() {
353 		return dayoff7;
354 	}
355 
356 	public void setDayoff7(boolean dayoff7) {
357 		this.dayoff7 = dayoff7;
358 	}
359 }