KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > users > RoleForm


1 /*
2  * Copyright 2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.webapp.admin.users;
18
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import org.apache.struts.action.ActionError;
22 import org.apache.struts.action.ActionErrors;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionMapping;
25
26
27 /**
28  * Form bean for the individual role page.
29  *
30  * @author Craig R. McClanahan
31  * @version $Revision: 1.3 $ $Date: 2004/02/27 14:59:05 $
32  * @since 4.1
33  */

34
35 public final class RoleForm extends BaseForm {
36
37
38     // ----------------------------------------------------- Instance Variables
39

40
41     // ------------------------------------------------------------- Properties
42

43
44     /**
45      * The description of this role.
46      */

47     private String JavaDoc description = null;
48
49     public String JavaDoc getDescription() {
50         return (this.description);
51     }
52
53     public void setDescription(String JavaDoc description) {
54         this.description = description;
55     }
56
57
58     /**
59      * The rolename of this role.
60      */

61     private String JavaDoc rolename = null;
62
63     public String JavaDoc getRolename() {
64         return (this.rolename);
65     }
66
67     public void setRolename(String JavaDoc rolename) {
68         this.rolename = rolename;
69     }
70
71
72     // --------------------------------------------------------- Public Methods
73

74
75     /**
76      * Reset all properties to their default values.
77      *
78      * @param mapping The mapping used to select this instance
79      * @param request The servlet request we are processing
80      */

81     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
82
83         super.reset(mapping, request);
84         description = null;
85         rolename = null;
86
87     }
88
89
90     /**
91      * Validate the properties that have been set from this HTTP request,
92      * and return an <code>ActionErrors</code> object that encapsulates any
93      * validation errors that have been found. If no errors are found, return
94      * <code>null</code> or an <code>ActionErrors</code> object with no
95      * recorded error messages.
96      *
97      * @param mapping The mapping used to select this instance
98      * @param request The servlet request we are processing
99      */

100     public ActionErrors validate(ActionMapping mapping,
101     HttpServletRequest JavaDoc request) {
102
103         ActionErrors errors = new ActionErrors();
104
105         String JavaDoc submit = request.getParameter("submit");
106         //if (submit != null) {
107

108             // rolename is a required field
109
if ((rolename == null) || (rolename.length() < 1)) {
110                 errors.add("rolename",
111                            new ActionError("users.error.rolename.required"));
112             }
113
114             // Quotes not allowed in rolename
115
if ((rolename != null) && (rolename.indexOf('"') >= 0)) {
116                 errors.add("rolename",
117                            new ActionError("users.error.quotes"));
118             }
119
120             // Quotes not allowed in description
121
if ((description != null) && (description.indexOf('"') > 0)) {
122                 errors.add("description",
123                            new ActionError("users.error.quotes"));
124             }
125
126         //}
127

128         return (errors);
129
130     }
131
132
133 }
134
Popular Tags