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 CreateUserForm extends ActionForm {
30  
31  	/**
32  	 * 
33  	 */
34  	private static final long serialVersionUID = 1L;
35  
36  	private String loginacreer;
37  
38  	private String passwordacreer;
39  
40  	private String nom;
41  
42  	private String prenom;
43  
44  	private String email;
45  
46  	private boolean chief;
47  
48  	private boolean employee;
49  
50  	private String pays;
51  
52  	private String team;
53  
54  	private String entryDate;
55  
56  	private boolean dayoff1;
57  
58  	private boolean dayoff2;
59  
60  	private boolean dayoff3;
61  
62  	private boolean dayoff4;
63  
64  	private boolean dayoff5;
65  
66  	private boolean dayoff6;
67  
68  	private boolean dayoff7;
69  
70  	/**
71  	 * Constructor for SmrBurLstParaForm.
72  	 */
73  	public CreateUserForm() {
74  		super();
75  		// resetFields();
76  	}
77  
78  	/**
79  	 * Reset all properties to their default values.
80  	 * 
81  	 * @param mapping
82  	 *            The mapping used to select this instance
83  	 * @param request
84  	 *            The servlet request we are processing
85  	 */
86  	public void reset(ActionMapping mapping, HttpServletRequest request) {
87  		resetFields();
88  	}
89  
90  	private void resetFields() {
91  		loginacreer = "";
92  		passwordacreer = "";
93  		nom = "";
94  		prenom = "";
95  		email = "";
96  		team = "";
97  		entryDate = "";
98  		// ne jamais mettre true pour ces 2 valeurs car cela bloque la checkbox
99  		// sur cette valeur
100 		chief = false;
101 		employee = false;
102 		dayoff1 = false;
103 		dayoff2 = false;
104 		dayoff3 = false;
105 		dayoff4 = false;
106 		dayoff5 = false;
107 		dayoff6 = false;
108 		dayoff7 = false;
109 	}
110 
111 	/**
112 	 * Validate the properties that have been set from this HTTP request, and
113 	 * return an <code>ActionErrors</code> object that encapsulates any
114 	 * validation errors that have been found. If no errors are found, return
115 	 * <code>null</code> or an <code>ActionErrors</code> object with no
116 	 * recorded error messages.
117 	 * 
118 	 * @param mapping
119 	 *            The mapping used to select this instance
120 	 * @param request
121 	 *            The servlet request we are processing
122 	 * @return ActionErrors
123 	 */
124 	public ActionErrors validate(ActionMapping mapping,
125 			HttpServletRequest request) {
126 
127 		ActionErrors errors = new ActionErrors();
128 
129 		if (loginacreer == null || loginacreer.equals("")) {
130 			errors.add("login.required", new ActionError("login.required"));
131 		}
132 		if (passwordacreer == null || passwordacreer.equals("")) {
133 			errors.add("password.required",
134 					new ActionError("password.required"));
135 		}
136 		if (nom == null || nom.equals("")) {
137 			errors.add("nom.required", new ActionError("nom.required"));
138 		}
139 		if (prenom == null || prenom.equals("")) {
140 			errors.add("prenom.required", new ActionError("prenom.required"));
141 		}
142 		if (email == null || email.equals("")) {
143 			errors.add("email.required", new ActionError("email.required"));
144 		}
145 		if (entryDate == null || entryDate.equals("")) {
146 			errors.add("entryDate.required", new ActionError(
147 					"entryDate.required"));
148 		}
149 
150 		RE regexp = new RE("^[a-zA-Z0-9]*$");
151 		if (!regexp.match(loginacreer)) {
152 			errors.add("error.alnum", new ActionError("error.alnum", "login"));
153 		}
154 		if (!regexp.match(passwordacreer)) {
155 			errors.add("error.alnum",
156 					new ActionError("error.alnum", "password"));
157 		}
158 		if (!regexp.match(nom)) {
159 			errors.add("error.alnum", new ActionError("error.alnum", "nom"));
160 		}
161 		if (!regexp.match(prenom)) {
162 			errors.add("error.alnum", new ActionError("error.alnum", "prenom"));
163 		}
164 
165 		try {
166 			new SimpleDateFormat("dd/MM/yyyy").parse(entryDate);
167 		} catch (ParseException e) {
168 			errors.add("error.date.format2", new ActionError(
169 					"error.date.format2"));
170 		}
171 
172 		String emailPattern = "^[a-zA-Z]+[a-zA-Z0-9\\._-]*[a-zA-Z0-9]@[a-zA-Z]+"
173 				+ "[a-zA-Z0-9\\._-]*[a-zA-Z0-9]+\\.[a-zA-Z]{2,4}$";
174 		regexp = new RE(emailPattern);
175 		if (!regexp.match(email)) {
176 			errors.add("error.email", new ActionError("error.email", "email"));
177 		}
178 
179 		CreateUserForm cu = new CreateUserForm();
180 
181 		cu.setChief(chief);
182 		cu.setLoginacreer(loginacreer);
183 		cu.setPasswordacreer(passwordacreer);
184 		cu.setDayoff1(dayoff1);
185 		cu.setDayoff2(dayoff2);
186 		cu.setDayoff3(dayoff3);
187 		cu.setDayoff4(dayoff4);
188 		cu.setDayoff5(dayoff5);
189 		cu.setDayoff6(dayoff6);
190 		cu.setDayoff7(dayoff7);
191 		cu.setEmail(email);
192 		cu.setEmployee(employee);
193 		cu.setEntryDate(entryDate);
194 		cu.setNom(nom);
195 		cu.setPays(pays);
196 		cu.setPrenom(prenom);
197 		cu.setTeam(team);
198 		request.setAttribute("createUserForm", cu);
199 
200 		return errors;
201 	}
202 
203 	/**
204 	 * @return boolean
205 	 */
206 	public boolean isChief() {
207 		return chief;
208 	}
209 
210 	/**
211 	 * @return email
212 	 */
213 	public String getEmail() {
214 		return email;
215 	}
216 
217 	/**
218 	 * @return boolean
219 	 */
220 	public boolean isEmployee() {
221 		return employee;
222 	}
223 
224 	/**
225 	 * @return login
226 	 */
227 	public String getLoginacreer() {
228 		return loginacreer;
229 	}
230 
231 	/**
232 	 * @return nom
233 	 */
234 	public String getNom() {
235 		return nom;
236 	}
237 
238 	/**
239 	 * @return password
240 	 */
241 	public String getPasswordacreer() {
242 		return passwordacreer;
243 	}
244 
245 	/**
246 	 * @return prenom
247 	 */
248 	public String getPrenom() {
249 		return prenom;
250 	}
251 
252 	/**
253 	 * @param b
254 	 */
255 	public void setChief(boolean b) {
256 		chief = b;
257 	}
258 
259 	/**
260 	 * @param string
261 	 */
262 	public void setEmail(String string) {
263 		email = string;
264 	}
265 
266 	/**
267 	 * @param b
268 	 */
269 	public void setEmployee(boolean b) {
270 		employee = b;
271 	}
272 
273 	/**
274 	 * @param string
275 	 */
276 	public void setLoginacreer(String string) {
277 		loginacreer = string;
278 	}
279 
280 	/**
281 	 * @param string
282 	 */
283 	public void setNom(String string) {
284 		nom = string;
285 	}
286 
287 	/**
288 	 * @param string
289 	 */
290 	public void setPasswordacreer(String string) {
291 		passwordacreer = string;
292 	}
293 
294 	/**
295 	 * @param string
296 	 */
297 	public void setPrenom(String string) {
298 		prenom = string;
299 	}
300 
301 	/**
302 	 * @return pays
303 	 */
304 	public String getPays() {
305 		return pays;
306 	}
307 
308 	/**
309 	 * @param string
310 	 */
311 	public void setPays(String string) {
312 		pays = string;
313 	}
314 
315 	/**
316 	 * @return team
317 	 */
318 	public String getTeam() {
319 		return team;
320 	}
321 
322 	/**
323 	 * @param string
324 	 */
325 	public void setTeam(String string) {
326 		team = string;
327 	}
328 
329 	/**
330 	 * @return Returns the entryDate.
331 	 */
332 	public String getEntryDate() {
333 		return entryDate;
334 	}
335 
336 	/**
337 	 * @param entryDate
338 	 *            The entryDate to set.
339 	 */
340 	public void setEntryDate(String entryDate) {
341 		this.entryDate = entryDate;
342 	}
343 
344 	public boolean isDayoff1() {
345 		return dayoff1;
346 	}
347 
348 	public void setDayoff1(boolean dayoff1) {
349 		this.dayoff1 = dayoff1;
350 	}
351 
352 	public boolean isDayoff2() {
353 		return dayoff2;
354 	}
355 
356 	public void setDayoff2(boolean dayoff2) {
357 		this.dayoff2 = dayoff2;
358 	}
359 
360 	public boolean isDayoff3() {
361 		return dayoff3;
362 	}
363 
364 	public void setDayoff3(boolean dayoff3) {
365 		this.dayoff3 = dayoff3;
366 	}
367 
368 	public boolean isDayoff4() {
369 		return dayoff4;
370 	}
371 
372 	public void setDayoff4(boolean dayoff4) {
373 		this.dayoff4 = dayoff4;
374 	}
375 
376 	public boolean isDayoff5() {
377 		return dayoff5;
378 	}
379 
380 	public void setDayoff5(boolean dayoff5) {
381 		this.dayoff5 = dayoff5;
382 	}
383 
384 	public boolean isDayoff6() {
385 		return dayoff6;
386 	}
387 
388 	public void setDayoff6(boolean dayoff6) {
389 		this.dayoff6 = dayoff6;
390 	}
391 
392 	public boolean isDayoff7() {
393 		return dayoff7;
394 	}
395 
396 	public void setDayoff7(boolean dayoff7) {
397 		this.dayoff7 = dayoff7;
398 	}
399 }