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 Stephane 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 ValidPeriodParamForm extends ActionForm {
27  
28  	/**
29  	 * 
30  	 */
31  	private static final long serialVersionUID = 4403846273476714068L;
32  
33  	private String code;
34  
35  	private String label;
36  
37  	/**
38  	 * Constructor for AbsForm.
39  	 */
40  	public ValidPeriodParamForm() {
41  		super();
42  		resetFields();
43  	}
44  
45  	/**
46  	 * Reset all properties to their default values.
47  	 * 
48  	 * @param mapping
49  	 *            The mapping used to select this instance
50  	 * @param request
51  	 *            The servlet request we are processing
52  	 */
53  	public void reset(ActionMapping mapping, HttpServletRequest request) {
54  		resetFields();
55  
56  	}
57  
58  	private void resetFields() {
59  		code = "";
60  		label = "";
61  	}
62  
63  	public ActionErrors validate(ActionMapping mapping,
64  			HttpServletRequest request) {
65  		ActionErrors errors = new ActionErrors();
66  		if (code == null || code.trim().equals("")) {
67  			errors.add("error.code.required", new ActionError(
68  					"error.code.required"));
69  		}
70  		if (label == null || label.trim().equals("")) {
71  			errors.add("error.label.required", new ActionError(
72  					"error.label.required"));
73  		}
74  
75  		RE regexp = new RE("^[0-9]*$");
76  
77  		if (!regexp.match(code)) {
78  			errors.add("error.num.format", new ActionError("error.num.format",
79  					"code"));
80  		} else if (code != null && !code.trim().equals("")
81  				&& new Integer(code).intValue() > 182) {
82  			errors.add("error.max.period", new ActionError("error.max.period",
83  					"code"));
84  		}
85  		return errors;
86  	}
87  
88  	public String getCode() {
89  		return code;
90  	}
91  
92  	public void setCode(String code) {
93  		this.code = code;
94  	}
95  
96  	public String getLabel() {
97  		return label;
98  	}
99  
100 	public void setLabel(String label) {
101 		this.label = label;
102 	}
103 
104 }