KickJava   Java API By Example, From Geeks To Geeks.

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


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

18
19
20 package org.apache.struts.webapp.example;
21
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.action.ActionMessage;
29
30
31 /**
32  * Form bean for the user profile page. This form has the following fields,
33  * with default values in square brackets:
34  * <ul>
35  * <li><b>action</b> - The maintenance action we are performing (Create, Delete,
36  * or Edit).
37  * <li><b>host</b> - The mail host for this subscription. [REQUIRED]
38  * <li><b>password</b> - The password for this subscription. [REQUIRED]
39  * <li><b>type</b> - The subscription type (imap,pop3)
40        for this subscription. [REQUIRED]
41  * <li><b>username</b> - The username of this subscription. [REQUIRED]
42  * </ul>
43  *
44  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
45  */

46
47 public final class SubscriptionForm extends ActionForm {
48
49
50     // --------------------------------------------------- Instance Variables
51

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

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

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

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

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

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

86     private String JavaDoc username = null;
87
88
89     // ----------------------------------------------------------- Properties
90

91
92     /**
93      * Return the maintenance action.
94      */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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