KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > example2 > SubscriptionForm


1 /*
2  * Copyright 1999-2001,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
18 package org.apache.struts.webapp.example2;
19
20
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
27
28 /**
29  * Form bean for the user profile page. This form has the following fields,
30  * with default values in square brackets:
31  * <ul>
32  * <li><b>action</b> - The maintenance action we are performing (Create, Delete,
33  * or Edit).
34  * <li><b>host</b> - The mail host for this subscription. [REQUIRED]
35  * <li><b>password</b> - The password for this subscription. [REQUIRED]
36  * <li><b>type</b> - The subscription type (imap,pop3)
37        for this subscription. [REQUIRED]
38  * <li><b>username</b> - The username of this subscription. [REQUIRED]
39  * </ul>
40  *
41  * @author Craig R. McClanahan
42  * @version $Rev: 54934 $ $Date: 2004-10-16 18:07:50 +0100 (Sat, 16 Oct 2004) $
43  */

44
45 public final class SubscriptionForm extends ActionForm {
46
47
48     // --------------------------------------------------- Instance Variables
49

50
51     /**
52      * The maintenance action we are performing (Create or Edit).
53      */

54     private String JavaDoc action = "Create";
55
56
57     /**
58      * Should we auto-connect at startup time?
59      */

60     private boolean autoConnect = false;
61
62
63     /**
64      * The host name.
65      */

66     private String JavaDoc host = null;
67
68
69     /**
70      * The password.
71      */

72     private String JavaDoc password = null;
73
74
75     /**
76      * The subscription type.
77      */

78     private String JavaDoc type = null;
79
80
81     /**
82      * The username.
83      */

84     private String JavaDoc username = null;
85
86
87     // ----------------------------------------------------------- Properties
88

89
90     /**
91      * Return the maintenance action.
92      */

93     public String JavaDoc getAction() {
94
95     return (this.action);
96
97     }
98
99
100     /**
101      * Set the maintenance action.
102      *
103      * @param action The new maintenance action.
104      */

105     public void setAction(String JavaDoc action) {
106
107         this.action = action;
108
109     }
110
111
112     /**
113      * Return the auto-connect flag.
114      */

115     public boolean getAutoConnect() {
116
117         return (this.autoConnect);
118
119     }
120
121
122     /**
123      * Set the auto-connect flag.
124      *
125      * @param autoConnect The new auto-connect flag
126      */

127     public void setAutoConnect(boolean autoConnect) {
128
129         this.autoConnect = autoConnect;
130     }
131
132
133     /**
134      * Return the host name.
135      */

136     public String JavaDoc getHost() {
137
138     return (this.host);
139
140     }
141
142
143     /**
144      * Set the host name.
145      *
146      * @param host The host name
147      */

148     public void setHost(String JavaDoc host) {
149
150         this.host = host;
151
152     }
153
154
155     /**
156      * Return the password.
157      */

158     public String JavaDoc getPassword() {
159
160     return (this.password);
161
162     }
163
164
165     /**
166      * Set the password.
167      *
168      * @param password The new password
169      */

170     public void setPassword(String JavaDoc password) {
171
172         this.password = password;
173
174     }
175
176
177     /**
178      * Return the subscription type.
179      */

180     public String JavaDoc getType() {
181
182     return (this.type);
183
184     }
185
186
187     /**
188      * Set the subscription type.
189      *
190      * @param type The subscription type
191      */

192     public void setType(String JavaDoc type) {
193
194         this.type = type;
195
196     }
197
198
199     /**
200      * Return the username.
201      */

202     public String JavaDoc getUsername() {
203
204     return (this.username);
205
206     }
207
208
209     /**
210      * Set the username.
211      *
212      * @param username The new username
213      */

214     public void setUsername(String JavaDoc username) {
215
216         this.username = username;
217
218     }
219
220
221     // --------------------------------------------------------- Public Methods
222

223
224     /**
225      * Reset all properties to their default values.
226      *
227      * @param mapping The mapping used to select this instance
228      * @param request The servlet request we are processing
229      */

230     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
231
232         this.action = "Create";
233         this.autoConnect = false;
234         this.host = null;
235         this.password = null;
236         this.type = null;
237         this.username = null;
238
239     }
240
241
242     /**
243      * Validate the properties that have been set from this HTTP request,
244      * and return an <code>ActionErrors</code> object that encapsulates any
245      * validation errors that have been found. If no errors are found, return
246      * <code>null</code> or an <code>ActionErrors</code> object with no
247      * recorded error messages.
248      *
249      * @param mapping The mapping used to select this instance
250      * @param request The servlet request we are processing
251      */

252     public ActionErrors validate(ActionMapping mapping,
253                                  HttpServletRequest JavaDoc request) {
254
255         ActionErrors errors = new ActionErrors();
256
257     if ((host == null) || (host.length() < 1))
258             errors.add("host",
259                        new ActionError("error.host.required"));
260     if ((username == null) || (username.length() < 1))
261             errors.add("username",
262                        new ActionError("error.username.required"));
263     if ((password == null) || (password.length() < 1))
264             errors.add("password",
265                        new ActionError("error.password.required"));
266     if ((type == null) || (type.length() < 1))
267             errors.add("type",
268                        new ActionError("error.type.required"));
269     else if (!"imap".equals(type) && !"pop3".equals(type))
270             errors.add("type",
271                        new ActionError("error.type.invalid", type));
272
273     return (errors);
274
275     }
276
277
278 }
279
280
Popular Tags