Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/clra/web/ApplyMemberShipForm.java


1   /*
2    * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3    * Distributed under the GPL license. See doc/COPYING.
4    * $RCSfile: ApplyMemberShipForm.java,v $
5    * $Date: 2003/02/26 03:38:46 $
6    * $Revision: 1.4 $
7    */
8   
9   package com.clra.web;
10  
11  import java.util.Collection;
12  import java.util.Iterator;
13  import java.util.NoSuchElementException;
14  import javax.servlet.http.HttpServletRequest;
15  import org.apache.log4j.Category;
16  import org.apache.struts.action.ActionError;
17  import org.apache.struts.action.ActionErrors;
18  import org.apache.struts.action.ActionForm;
19  import org.apache.struts.action.ActionMapping;
20  
21  /**
22   * @author <a href="mailto:donaldzhu@sympatico.ca">Angela Yue</a>
23   * @version $Revision: 1.4 $ $Date: 2003/02/26 03:38:46 $
24   */
25  
26  public final class ApplyMemberShipForm extends ActionForm  {
27  
28      private final static String base = ApplyMemberShipForm.class.getName();
29      private final static Category theLog = Category.getInstance( base );
30  
31      private String name_last = null;
32      private String name_first = null;
33      private String name_middle = null;
34      private String name_suffix = null;
35      private String email = null;
36      private String password = null;
37      private String confirm_password = null;
38      private String tel_evening = null;
39      private String tel_day = null;
40      private String tel_other = null;
41      private String tel_evening_areacode = null;
42      private String tel_evening_exchange = null;
43      private String tel_evening_local = null;
44      private String tel_evening_ext = null;
45      private String tel_day_areacode = null;
46      private String tel_day_exchange = null;
47      private String tel_day_local = null;
48      private String tel_day_ext = null;
49      private String tel_other_areacode = null;
50      private String tel_other_exchange = null;
51      private String tel_other_local = null;
52      private String tel_other_ext = null;
53      private String address_street1 = null;
54      private String address_street2 = null;
55      private String address_city = null;
56      private String address_state = null;
57      private String address_zip = null;
58      private String experience_year = null;
59      private String recent_year = null;
60      private int birthday_day = -1;
61      private int birthday_month = -1;
62      private int birthday_year = -1;
63      private String sex = null;
64  
65      public String getName_last() {
66        return (this.name_last);
67      }
68  
69      public void setName_last(String name_last) {
70          this.name_last = name_last;
71      }
72  
73      public String getName_first() {
74        return (this.name_first);
75      }
76  
77      public void setName_first(String name_first) {
78          this.name_first = name_first;
79      }
80  
81      public String getName_middle() {
82        if (this.name_middle.length() == 0)
83          return null;
84        else
85          return (this.name_middle);
86      }
87  
88      public void setName_middle(String name_middle) {
89          this.name_middle = name_middle;
90      }
91  
92      public String getName_suffix() {
93        if (this.name_suffix.length() == 0)
94          return null;
95        else
96      return (this.name_suffix);
97      }
98  
99      public void setName_suffix(String name_suffix) {
100         this.name_suffix = name_suffix;
101     }
102 
103     public String getPassword() {
104   return (this.password);
105     }
106 
107     public void setPassword(String password) {
108         this.password = password;
109     }
110 
111     public String getConfirm_password() {
112   return (this.confirm_password);
113     }
114 
115     public void setConfirm_password(String password) {
116         this.confirm_password = password;
117     }
118 
119     public String getEmail() {
120       if (this.email.length() == 0)
121         return null;
122       else
123     return (this.email);
124     }
125 
126     public void setEmail(String email) {
127         this.email = email;
128     }
129 
130     public String getTel_evening_areacode() {
131       return (this.tel_evening_areacode);
132     }
133 
134     public void setTel_evening_areacode(String code) {
135         this.tel_evening_areacode = code;
136     }
137 
138     public String getTel_evening_exchange() {
139       return (this.tel_evening_exchange);
140     }
141 
142     public void setTel_evening_exchange(String code) {
143         this.tel_evening_exchange = code;
144     }
145 
146     public String getTel_evening_local() {
147       return (this.tel_evening_local);
148     }
149 
150     public void setTel_evening_local(String code) {
151         this.tel_evening_local = code;
152     }
153 
154     public String getTel_evening_ext() {
155       return (this.tel_evening_ext);
156     }
157 
158     public String getTel_day_areacode() {
159       return (this.tel_day_areacode);
160     }
161 
162     public void setTel_day_areacode(String code) {
163         this.tel_day_areacode = code;
164     }
165 
166     public String getTel_day_exchange() {
167       return (this.tel_day_exchange);
168     }
169 
170     public void setTel_day_exchange(String code) {
171         this.tel_day_exchange = code;
172     }
173 
174     public String getTel_day_local() {
175       return (this.tel_day_local);
176     }
177 
178     public void setTel_day_local(String code) {
179         this.tel_day_local = code;
180     }
181 
182     public String getTel_day_ext() {
183       return (this.tel_day_ext);
184     }
185 
186     public void setTel_day_ext(String code) {
187         this.tel_day_ext = code;
188     }
189 
190     public String getTel_other_areacode() {
191       return (this.tel_other_areacode);
192     }
193 
194     public void setTel_other_areacode(String code) {
195         this.tel_other_areacode = code;
196     }
197 
198     public String getTel_other_exchange() {
199       return (this.tel_other_exchange);
200     }
201 
202     public void setTel_other_exchange(String code) {
203         this.tel_other_exchange = code;
204     }
205 
206     public String getTel_other_local() {
207       return (this.tel_other_local);
208     }
209 
210     public void setTel_other_local(String code) {
211         this.tel_other_local = code;
212     }
213 
214     public String getTel_other_ext() {
215       return (this.tel_other_ext);
216     }
217 
218     public String getTel_evening() {
219       this.tel_evening = "(" + this.tel_evening_areacode + ")" + this.tel_evening_exchange
220                          + "-" + this.tel_evening_local;
221       if (this.tel_evening_ext != null && this.tel_evening_ext.length() > 0)
222          this.tel_evening = this.tel_evening + "Ext." + this.tel_evening_ext;
223   return (this.tel_evening);
224     }
225 
226     public String getTel_day() {
227       if (this.tel_day_areacode == null || this.tel_day_areacode.length() == 0)
228         return null;
229         
230       this.tel_day = "(" + this.tel_day_areacode + ")" + this.tel_day_exchange
231                          + "-" + this.tel_day_local;
232       if (this.tel_day_ext != null && this.tel_day_ext.length() > 0)
233          this.tel_day = this.tel_day + "Ext." + this.tel_day_ext;
234   return (this.tel_day);
235     }
236 
237     public String getTel_other() {
238       if (this.tel_other_areacode == null || this.tel_other_areacode.length() == 0)
239         return null;
240 
241       this.tel_other = "(" + this.tel_other_areacode + ")" + this.tel_other_exchange
242                          + "-" + this.tel_other_local;
243       if (this.tel_other_ext != null && this.tel_other_ext.length() > 0)
244          this.tel_other = this.tel_other + "Ext." + this.tel_other_ext;
245   return (this.tel_other);
246     }
247 
248     public String getAddress_street1() {
249   return (this.address_street1);
250     }
251 
252     public void setAddress_street1(String address) {
253         this.address_street1 = address;
254     }
255 
256     public String getAddress_street2() {
257       if (this.address_street2.length() == 0)
258         return null;
259       else
260     return (this.address_street2);
261     }
262 
263     public void setAddress_street2(String address) {
264         this.address_street2 = address;
265     }
266 
267     public String getAddress_city() {
268   return (this.address_city);
269     }
270 
271     public void setAddress_city(String city) {
272         this.address_city = city;
273     }
274 
275     public String getAddress_state() {
276   return (this.address_state);
277     }
278 
279     public void setAddress_state(String state) {
280         this.address_state = state;
281     }
282 
283     public String getAddress_zip() {
284   return (this.address_zip);
285     }
286 
287     public void setAddress_zip(String zip) {
288         this.address_zip = zip;
289     }
290 
291     public int getBirthday_day() {
292   return (this.birthday_day);
293     }
294 
295     public void setBirthday_day(int day) {
296         this.birthday_day = day;
297     }
298 
299     public int getBirthday_month() {
300   return (this.birthday_month);
301     }
302 
303     public void setBirthday_month(int month) {
304         this.birthday_month = month;
305     }
306 
307     public int getBirthday_year() {
308   return (this.birthday_year);
309     }
310 
311     public void setBirthday_year(int year) {
312         this.birthday_year = year;
313     }
314 
315     public String getExperience_year() {
316   return (this.experience_year);
317     }
318 
319     public void setExperience_year(String year) {
320         this.experience_year = year;
321     }
322 
323     public String getRecent_year() {
324   return (this.recent_year);
325     }
326 
327     public void setRecent_year(String year) {
328         this.recent_year = year;
329     }
330 
331     public String getSex() {
332   return (this.sex);
333     }
334 
335     public void setSex(String sex) {
336         this.sex = sex;
337     }
338 
339   /**
340    * Validate the properties that have been set from this HTTP request,
341    * and return an <code>ActionErrors</code> object that encapsulates any
342    * validation errors that have been found.  If no errors are found, return
343    * <code>null</code> or an <code>ActionErrors</code> object with no
344    * recorded error messages.
345    *
346    * @param mapping The mapping used to select this instance
347    * @param request The servlet request we are processing
348   */
349   public ActionErrors validate(ActionMapping mapping,
350                            HttpServletRequest request) {
351 
352     ActionErrors errors = new ActionErrors();
353 
354     if (name_last.length() == 0)
355         errors.add("name_last",
356                    new ActionError("error.name_last"));
357 
358     if (name_first.length() == 0)
359         errors.add("name_first",
360                    new ActionError("error.name_first"));
361 
362     if (email.length() == 0)
363         errors.add("email",
364                    new ActionError("error.email.format"));
365 
366     int phonenumber = tel_evening_areacode.length() + tel_evening_exchange.length() 
367                     + tel_evening_local.length();
368     if (phonenumber == 0)
369         errors.add("tel_evening", new ActionError("error.tel_evening"));
370     else if (phonenumber != 10)
371         errors.add("tel_evening",
372                    new ActionError("error.tel_format"));
373 
374     phonenumber = tel_day_areacode.length() + tel_day_exchange.length() 
375                     + tel_day_local.length();
376     if (phonenumber != 10 && phonenumber != 0)
377         errors.add("tel_day",
378                    new ActionError("error.tel_day"));
379 
380     phonenumber = tel_other_areacode.length() + tel_other_exchange.length() 
381                     + tel_other_local.length();
382     if (phonenumber != 10 && phonenumber != 0)
383         errors.add("tel_other",
384                    new ActionError("error.tel_other"));
385 
386     if (address_street1.length() == 0)
387         errors.add("addr_street1",
388                    new ActionError("error.addr_street1"));
389 
390     if (address_city.length() == 0)
391         errors.add("addr_city",
392                    new ActionError("error.addr_city"));
393 
394     if (address_zip.length() == 0)
395         errors.add("addr_zip",
396                    new ActionError("error.addr_zip"));
397 
398     if (experience_year.length() == 0)
399         errors.add("experience_year",
400                    new ActionError("error.experience_year"));
401 
402     if (recent_year.length() == 0)
403         errors.add("recent_year",
404                    new ActionError("error.recent_year"));
405 
406     if (sex.length() == 0)
407         errors.add("sex",
408                    new ActionError("error.sex"));
409 
410     if (!password.equals(confirm_password))
411         errors.add("confirm_password",
412                    new ActionError("error.password.match"));
413 
414     if (email.length() != 0 && email.indexOf('@') <0)
415         errors.add("email_format",
416                    new ActionError("error.email.format"));
417                    
418     // check birthday
419     switch (this.birthday_month) {
420       case 4:
421       case 6:
422       case 9:
423       case 11: if (this.birthday_day > 30)
424                  errors.add("birthday", new ActionError("error.birthday"));
425                break;
426       case 2: if (this.birthday_year % 4 == 0) {
427           if (this.birthday_day > 29)
428             errors.add("birthday", new ActionError("error.birthday"));
429               } else
430                 if (this.birthday_day > 28)
431                   errors.add("birthday", new ActionError("error.birthday"));
432               break;
433     }
434 
435     return (errors);
436   }
437 
438 } // MemberRegisterForm
439