2
* Copyright 1999-2001,2004 The Apache Software Foundation.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.struts.webapp.example2;
21
import javax.servlet.http.HttpServletRequest;
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;
29
* Form bean for the user profile page. This form has the following fields,
30
* with default values in square brackets:
32
* <li><b>action</b> - The maintenance action we are performing (Create, Delete,
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]
41
* @author Craig R. McClanahan
42
* @version $Rev: 54934 $ $Date: 2004-10-16 18:07:50 +0100 (Sat, 16 Oct 2004) $
45
public final class SubscriptionForm extends ActionForm {
48
// --------------------------------------------------- Instance Variables
52
* The maintenance action we are performing (Create or Edit).
54
private String action = "Create";
58
* Should we auto-connect at startup time?
60
private boolean autoConnect = false;
66
private String host = null;
72
private String password = null;
76
* The subscription type.
78
private String type = null;
84
private String username = null;
87
// ----------------------------------------------------------- Properties
91
* Return the maintenance action.
93
public String getAction() {
101
* Set the maintenance action.
103
* @param action The new maintenance action.
105
public void setAction(String action) {
107
this.action = action;
113
* Return the auto-connect flag.
115
public boolean getAutoConnect() {
117
return (this.autoConnect);
123
* Set the auto-connect flag.
125
* @param autoConnect The new auto-connect flag
127
public void setAutoConnect(boolean autoConnect) {
129
this.autoConnect = autoConnect;
134
* Return the host name.
136
public String getHost() {
146
* @param host The host name
148
public void setHost(String host) {
156
* Return the password.
158
public String getPassword() {
160
return (this.password);
168
* @param password The new password
170
public void setPassword(String password) {
172
this.password = password;
178
* Return the subscription type.
180
public String getType() {
188
* Set the subscription type.
190
* @param type The subscription type
192
public void setType(String type) {
200
* Return the username.
202
public String getUsername() {
204
return (this.username);
212
* @param username The new username
214
public void setUsername(String username) {
216
this.username = username;
221
// --------------------------------------------------------- Public Methods
225
* Reset all properties to their default values.
227
* @param mapping The mapping used to select this instance
228
* @param request The servlet request we are processing
230
public void reset(ActionMapping mapping, HttpServletRequest request) {
232
this.action = "Create";
233
this.autoConnect = false;
235
this.password = null;
237
this.username = null;
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.
249
* @param mapping The mapping used to select this instance
250
* @param request The servlet request we are processing
252
public ActionErrors validate(ActionMapping mapping,
253
HttpServletRequest request) {
255
ActionErrors errors = new ActionErrors();
257
if ((host == null) || (host.length() < 1))
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))
268
new ActionError("error.type.required"));
269
else if (!"imap".equals(type) && !"pop3".equals(type))
271
new ActionError("error.type.invalid", type));