View Javadoc
1   /*
2    * $Id$
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  
23  package org.apache.struts.webapp.example2;
24  
25  
26  import jakarta.servlet.http.HttpServletRequest;
27  import org.apache.struts.action.ActionMessage;
28  import org.apache.struts.action.ActionErrors;
29  import org.apache.struts.action.ActionForm;
30  import org.apache.struts.action.ActionMapping;
31  
32  
33  /**
34   * Form bean for the user profile page.  This form has the following fields,
35   * with default values in square brackets:
36   * <ul>
37   * <li><b>action</b> - The maintenance action we are performing (Create, Delete,
38   *     or Edit).
39   * <li><b>host</b> - The mail host for this subscription.  [REQUIRED]
40   * <li><b>password</b> - The password for this subscription.  [REQUIRED]
41   * <li><b>type</b> - The subscription type (imap,pop3)
42         for this subscription.  [REQUIRED]
43   * <li><b>username</b> - The username of this subscription.  [REQUIRED]
44   * </ul>
45   *
46   * @author Craig R. McClanahan
47   * @version $Rev$ $Date$
48   */
49  
50  public final class SubscriptionForm extends ActionForm  {
51      private static final long serialVersionUID = -5919986074684776364L;
52  
53  
54      // --------------------------------------------------- Instance Variables
55  
56  
57      /**
58       * The maintenance action we are performing (Create or Edit).
59       */
60      private String action = "Create";
61  
62  
63      /**
64       * Should we auto-connect at startup time?
65       */
66      private boolean autoConnect = false;
67  
68  
69      /**
70       * The host name.
71       */
72      private String host = null;
73  
74  
75      /**
76       * The password.
77       */
78      private String password = null;
79  
80  
81      /**
82       * The subscription type.
83       */
84      private String type = null;
85  
86  
87      /**
88       * The username.
89       */
90      private String username = null;
91  
92  
93      // ----------------------------------------------------------- Properties
94  
95  
96      /**
97       * Return the maintenance action.
98       */
99      public String getAction() {
100 
101     return (this.action);
102 
103     }
104 
105 
106     /**
107      * Set the maintenance action.
108      *
109      * @param action The new maintenance action.
110      */
111     public void setAction(String action) {
112 
113         this.action = action;
114 
115     }
116 
117 
118     /**
119      * Return the auto-connect flag.
120      */
121     public boolean getAutoConnect() {
122 
123         return (this.autoConnect);
124 
125     }
126 
127 
128     /**
129      * Set the auto-connect flag.
130      *
131      * @param autoConnect The new auto-connect flag
132      */
133     public void setAutoConnect(boolean autoConnect) {
134 
135         this.autoConnect = autoConnect;
136     }
137 
138 
139     /**
140      * Return the host name.
141      */
142     public String getHost() {
143 
144     return (this.host);
145 
146     }
147 
148 
149     /**
150      * Set the host name.
151      *
152      * @param host The host name
153      */
154     public void setHost(String host) {
155 
156         this.host = host;
157 
158     }
159 
160 
161     /**
162      * Return the password.
163      */
164     public String getPassword() {
165 
166     return (this.password);
167 
168     }
169 
170 
171     /**
172      * Set the password.
173      *
174      * @param password The new password
175      */
176     public void setPassword(String password) {
177 
178         this.password = password;
179 
180     }
181 
182 
183     /**
184      * Return the subscription type.
185      */
186     public String getType() {
187 
188     return (this.type);
189 
190     }
191 
192 
193     /**
194      * Set the subscription type.
195      *
196      * @param type The subscription type
197      */
198     public void setType(String type) {
199 
200         this.type = type;
201 
202     }
203 
204 
205     /**
206      * Return the username.
207      */
208     public String getUsername() {
209 
210     return (this.username);
211 
212     }
213 
214 
215     /**
216      * Set the username.
217      *
218      * @param username The new username
219      */
220     public void setUsername(String username) {
221 
222         this.username = username;
223 
224     }
225 
226 
227     // --------------------------------------------------------- Public Methods
228 
229 
230     /**
231      * Reset all properties to their default values.
232      *
233      * @param mapping The mapping used to select this instance
234      * @param request The servlet request we are processing
235      */
236     public void reset(ActionMapping mapping, HttpServletRequest request) {
237 
238         this.action = "Create";
239         this.autoConnect = false;
240         this.host = null;
241         this.password = null;
242         this.type = null;
243         this.username = null;
244 
245     }
246 
247 
248     /**
249      * Validate the properties that have been set from this HTTP request,
250      * and return an <code>ActionErrors</code> object that encapsulates any
251      * validation errors that have been found.  If no errors are found, return
252      * <code>null</code> or an <code>ActionErrors</code> object with no
253      * recorded error messages.
254      *
255      * @param mapping The mapping used to select this instance
256      * @param request The servlet request we are processing
257      */
258     public ActionErrors validate(ActionMapping mapping,
259                                  HttpServletRequest request) {
260 
261         ActionErrors errors = new ActionErrors();
262 
263     if ((host == null) || (host.length() < 1))
264             errors.add("host",
265                        new ActionMessage("error.host.required"));
266     if ((username == null) || (username.length() < 1))
267             errors.add("username",
268                        new ActionMessage("error.username.required"));
269     if ((password == null) || (password.length() < 1))
270             errors.add("password",
271                        new ActionMessage("error.password.required"));
272     if ((type == null) || (type.length() < 1))
273             errors.add("type",
274                        new ActionMessage("error.type.required"));
275     else if (!"imap".equals(type) && !"pop3".equals(type))
276             errors.add("type",
277                        new ActionMessage("error.type.invalid", type));
278 
279     return (errors);
280 
281     }
282 
283 
284 }
285