001: /*
002: * $Id: SubscriptionForm.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.webapp.example2;
023:
024: import javax.servlet.http.HttpServletRequest;
025: import org.apache.struts.action.ActionMessage;
026: import org.apache.struts.action.ActionErrors;
027: import org.apache.struts.action.ActionForm;
028: import org.apache.struts.action.ActionMapping;
029:
030: /**
031: * Form bean for the user profile page. This form has the following fields,
032: * with default values in square brackets:
033: * <ul>
034: * <li><b>action</b> - The maintenance action we are performing (Create, Delete,
035: * or Edit).
036: * <li><b>host</b> - The mail host for this subscription. [REQUIRED]
037: * <li><b>password</b> - The password for this subscription. [REQUIRED]
038: * <li><b>type</b> - The subscription type (imap,pop3)
039: for this subscription. [REQUIRED]
040: * <li><b>username</b> - The username of this subscription. [REQUIRED]
041: * </ul>
042: *
043: * @author Craig R. McClanahan
044: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
045: */
046:
047: public final class SubscriptionForm extends ActionForm {
048:
049: // --------------------------------------------------- Instance Variables
050:
051: /**
052: * The maintenance action we are performing (Create or Edit).
053: */
054: private String action = "Create";
055:
056: /**
057: * Should we auto-connect at startup time?
058: */
059: private boolean autoConnect = false;
060:
061: /**
062: * The host name.
063: */
064: private String host = null;
065:
066: /**
067: * The password.
068: */
069: private String password = null;
070:
071: /**
072: * The subscription type.
073: */
074: private String type = null;
075:
076: /**
077: * The username.
078: */
079: private String username = null;
080:
081: // ----------------------------------------------------------- Properties
082:
083: /**
084: * Return the maintenance action.
085: */
086: public String getAction() {
087:
088: return (this .action);
089:
090: }
091:
092: /**
093: * Set the maintenance action.
094: *
095: * @param action The new maintenance action.
096: */
097: public void setAction(String action) {
098:
099: this .action = action;
100:
101: }
102:
103: /**
104: * Return the auto-connect flag.
105: */
106: public boolean getAutoConnect() {
107:
108: return (this .autoConnect);
109:
110: }
111:
112: /**
113: * Set the auto-connect flag.
114: *
115: * @param autoConnect The new auto-connect flag
116: */
117: public void setAutoConnect(boolean autoConnect) {
118:
119: this .autoConnect = autoConnect;
120: }
121:
122: /**
123: * Return the host name.
124: */
125: public String getHost() {
126:
127: return (this .host);
128:
129: }
130:
131: /**
132: * Set the host name.
133: *
134: * @param host The host name
135: */
136: public void setHost(String host) {
137:
138: this .host = host;
139:
140: }
141:
142: /**
143: * Return the password.
144: */
145: public String getPassword() {
146:
147: return (this .password);
148:
149: }
150:
151: /**
152: * Set the password.
153: *
154: * @param password The new password
155: */
156: public void setPassword(String password) {
157:
158: this .password = password;
159:
160: }
161:
162: /**
163: * Return the subscription type.
164: */
165: public String getType() {
166:
167: return (this .type);
168:
169: }
170:
171: /**
172: * Set the subscription type.
173: *
174: * @param type The subscription type
175: */
176: public void setType(String type) {
177:
178: this .type = type;
179:
180: }
181:
182: /**
183: * Return the username.
184: */
185: public String getUsername() {
186:
187: return (this .username);
188:
189: }
190:
191: /**
192: * Set the username.
193: *
194: * @param username The new username
195: */
196: public void setUsername(String username) {
197:
198: this .username = username;
199:
200: }
201:
202: // --------------------------------------------------------- Public Methods
203:
204: /**
205: * Reset all properties to their default values.
206: *
207: * @param mapping The mapping used to select this instance
208: * @param request The servlet request we are processing
209: */
210: public void reset(ActionMapping mapping, HttpServletRequest request) {
211:
212: this .action = "Create";
213: this .autoConnect = false;
214: this .host = null;
215: this .password = null;
216: this .type = null;
217: this .username = null;
218:
219: }
220:
221: /**
222: * Validate the properties that have been set from this HTTP request,
223: * and return an <code>ActionErrors</code> object that encapsulates any
224: * validation errors that have been found. If no errors are found, return
225: * <code>null</code> or an <code>ActionErrors</code> object with no
226: * recorded error messages.
227: *
228: * @param mapping The mapping used to select this instance
229: * @param request The servlet request we are processing
230: */
231: public ActionErrors validate(ActionMapping mapping,
232: HttpServletRequest request) {
233:
234: ActionErrors errors = new ActionErrors();
235:
236: if ((host == null) || (host.length() < 1))
237: errors
238: .add("host", new ActionMessage(
239: "error.host.required"));
240: if ((username == null) || (username.length() < 1))
241: errors.add("username", new ActionMessage(
242: "error.username.required"));
243: if ((password == null) || (password.length() < 1))
244: errors.add("password", new ActionMessage(
245: "error.password.required"));
246: if ((type == null) || (type.length() < 1))
247: errors
248: .add("type", new ActionMessage(
249: "error.type.required"));
250: else if (!"imap".equals(type) && !"pop3".equals(type))
251: errors.add("type", new ActionMessage("error.type.invalid",
252: type));
253:
254: return (errors);
255:
256: }
257:
258: }
|