~ubuntu-branches/ubuntu/lucid/libstruts1.2-java/lucid

« back to all changes in this revision

Viewing changes to contrib/struts-faces/src/example2/org/apache/struts/webapp/example2/SubscriptionForm.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-04-24 12:14:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060424121423-naev53qigqgks0sa
Tags: 1.2.9-1
New upstream  release Fixes  three security  problems: CVE-2006-1546,
CVE-2006-1547,  CVE-2006-1548  (closes:  #360551),  thanks  to  Moritz
Muehlenhoff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
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 $Revision: 1.2 $ $Date: 2004/03/08 02:49:53 $
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 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
 
    // ----------------------------------------------------------- Properties
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
 
    // --------------------------------------------------------- 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 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 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