KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.net.URLDecoder JavaDoc;
20 import javax.management.MBeanServer JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import org.apache.struts.action.ActionError;
23 import org.apache.struts.action.ActionErrors;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionMapping;
26 import org.apache.webapp.admin.ApplicationServlet;
27 import org.apache.webapp.admin.TomcatTreeBuilder;
28
29 /**
30  * Form bean for the individual group page.
31  *
32  * @author Craig R. McClanahan
33  * @version $Revision: 1.5 $ $Date: 2004/10/18 06:37:55 $
34  * @since 4.1
35  */

36
37 public final class GroupForm extends BaseForm {
38
39
40     // ----------------------------------------------------- Instance Variables
41

42    /**
43      * The MBeanServer we will be interacting with.
44      */

45     private MBeanServer JavaDoc mserver = null;
46     
47
48     // ------------------------------------------------------------- Properties
49

50
51     /**
52      * The description of this group.
53      */

54     private String JavaDoc description = null;
55
56     public String JavaDoc getDescription() {
57         return (this.description);
58     }
59
60     public void setDescription(String JavaDoc description) {
61         this.description = description;
62     }
63
64
65     /**
66      * The groupname of this group.
67      */

68     private String JavaDoc groupname = null;
69
70     public String JavaDoc getGroupname() {
71         return (this.groupname);
72     }
73
74     public void setGroupname(String JavaDoc groupname) {
75         this.groupname = groupname;
76     }
77
78
79     /**
80      * The MBean Names of the roles associated with this group.
81      */

82     private String JavaDoc roles[] = new String JavaDoc[0];
83
84     public String JavaDoc[] getRoles() {
85         return (this.roles);
86     }
87
88     public void setRoles(String JavaDoc roles[]) {
89         if (roles == null) {
90             roles = new String JavaDoc[0];
91         }
92         this.roles = roles;
93     }
94
95
96     // --------------------------------------------------------- Public Methods
97

98
99     /**
100      * Reset all properties to their default values.
101      *
102      * @param mapping The mapping used to select this instance
103      * @param request The servlet request we are processing
104      */

105     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
106
107         super.reset(mapping, request);
108         description = null;
109         groupname = null;
110         roles = new String JavaDoc[0];
111
112     }
113
114
115     /**
116      * Validate the properties that have been set from this HTTP request,
117      * and return an <code>ActionErrors</code> object that encapsulates any
118      * validation errors that have been found. If no errors are found, return
119      * <code>null</code> or an <code>ActionErrors</code> object with no
120      * recorded error messages.
121      *
122      * @param mapping The mapping used to select this instance
123      * @param request The servlet request we are processing
124      */

125     public ActionErrors validate(ActionMapping mapping,
126     HttpServletRequest JavaDoc request) {
127         
128         try {
129             // Look up the components we will be using as needed
130
if (mserver == null) {
131                 mserver = ((ApplicationServlet) getServlet()).getServer();
132             }
133          
134             // Set up beans containing all possible groups and roles
135
String JavaDoc databaseName =
136                 URLDecoder.decode(request.getParameter("databaseName"),TomcatTreeBuilder.URL_ENCODING);
137             request.setAttribute("rolesForm",
138                                  UserUtils.getRolesForm(mserver,
139                                                         databaseName));
140         } catch (Exception JavaDoc e) {
141             // do nothing since the form returns validation error
142
}
143         
144         ActionErrors errors = new ActionErrors();
145
146         String JavaDoc submit = request.getParameter("submit");
147         //if (submit != null) {
148

149             // groupname is a required field
150
if ((groupname == null) || (groupname.length() < 1)) {
151                 errors.add("groupname",
152                            new ActionError("users.error.groupname.required"));
153             }
154
155             // Quotes not allowed in groupname
156
if ((groupname != null) && (groupname.indexOf('"') >= 0)) {
157                 errors.add("groupname",
158                            new ActionError("users.error.quotes"));
159             }
160
161             // Quotes not allowed in description
162
if ((description != null) && (description.indexOf('"') > 0)) {
163                 errors.add("description",
164                            new ActionError("users.error.quotes"));
165             }
166
167         //}
168

169         return (errors);
170
171     }
172
173
174 }
175
Popular Tags