1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.webapp.example;
19
20
21 import javax.servlet.http.HttpServletRequest;
22 import org.apache.struts.action.ActionErrors;
23 import org.apache.struts.action.ActionMessage;
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: 421493 $ $Date: 2006-07-12 20:52:31 -0700 (Wed, 12 Jul 2006) $
43 */
44
45 public final class SubscriptionForm extends ActionForm {
46
47
48
49
50
51 /***
52 * The maintenance action we are performing (Create or Edit).
53 */
54 private String 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 host = null;
67
68
69 /***
70 * The password.
71 */
72 private String password = null;
73
74
75 /***
76 * The subscription type.
77 */
78 private String type = null;
79
80
81 /***
82 * The username.
83 */
84 private String username = null;
85
86
87
88
89
90 /***
91 * Return the maintenance action.
92 */
93 public String 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 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 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 host) {
149
150 this.host = host;
151
152 }
153
154
155 /***
156 * Return the password.
157 */
158 public String 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 password) {
171
172 this.password = password;
173
174 }
175
176
177 /***
178 * Return the subscription type.
179 */
180 public String 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 type) {
193
194 this.type = type;
195
196 }
197
198
199 /***
200 * Return the username.
201 */
202 public String 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 username) {
215
216 this.username = username;
217
218 }
219
220
221
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 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>ActionMessages</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>ActionMessages</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 request) {
254
255 ActionErrors errors = new ActionErrors();
256
257 if ((host == null) || (host.length() < 1))
258 errors.add("host",
259 new ActionMessage("error.host.required"));
260 if ((username == null) || (username.length() < 1))
261 errors.add("username",
262 new ActionMessage("error.username.required"));
263 if ((password == null) || (password.length() < 1))
264 errors.add("password",
265 new ActionMessage("error.password.required"));
266 if ((type == null) || (type.length() < 1))
267 errors.add("type",
268 new ActionMessage("error.type.required"));
269 else if (!"imap".equals(type) && !"pop3".equals(type))
270 errors.add("type",
271 new ActionMessage("error.type.invalid", type));
272
273 return (errors);
274
275 }
276
277
278 /***
279 * <p>Return a string representation of this form bean.</p>
280 */
281 public String toString() {
282
283 StringBuffer sb = new StringBuffer(super.toString());
284 sb.append(",action=");
285 sb.append(action);
286 sb.append(",autoConnect=");
287 sb.append(autoConnect);
288 sb.append(",host=");
289 sb.append(host);
290 sb.append(",password=");
291 sb.append(password);
292 sb.append(",type=");
293 sb.append(type);
294 sb.append(",username=");
295 sb.append(username);
296 return (sb.toString());
297
298 }
299
300
301 }
302