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

Quick Search    Search Deep

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


1   /*
2    * Copyright (c) Carnegie Lake Rowing Association 2002. All rights reserved.
3    * Distributed under the GPL license. See doc/COPYING.
4    * $RCSfile: ValidateMemberPhoneNumbers.java,v $
5    * $Date: 2003/02/26 03:38:46 $
6    * $Revision: 1.4 $
7    */
8   
9   package com.clra.web;
10  
11  import com.clra.member.Telephone;
12  import org.apache.struts.action.ActionError;
13  import org.apache.struts.action.ActionErrors;
14  
15  /**
16   * Checks whether the member has included at least an evening phone number
17   * and whether all included phone numbers seem reasonable.
18   *
19   * @version $Id: ValidateMemberPhoneNumbers.java,v 1.4 2003/02/26 03:38:46 rphall Exp $
20   * @author <a href="mailto:rphall@pluto.njcc.com">Rick Hall</a>
21   */
22  class ValidateMemberPhoneNumbers extends ValidateMember {
23  
24    public final static String PROPERTY_PHONE = "phone";
25  
26    ValidateMemberPhoneNumbers( MemberInfoForm f ) {
27      super( f );
28    }
29  
30    /**
31     * Checks whether the member has included at least an evening phone number
32     * and whether all included phone numbers seem reasonable.
33     */
34    void validate( ActionErrors errors ) {
35      if ( errors == null ) {
36        throw new IllegalArgumentException( "null action errors" );
37      }
38  
39      ActionError ae = null;
40  
41      // Evening phone
42      String areacode  = this.form.getPhoneEveningAreaCode();
43      String exchange  = this.form.getPhoneEveningExchange();
44      String local     = this.form.getPhoneEveningLocal();
45      String extension = this.form.getPhoneEveningExt();
46      if ( isPhoneCompletelyBlank(areacode,exchange,local,extension) ) {
47        ae = new ActionError( "validate.member.phone.evening.missing" );
48        errors.add( PROPERTY_PHONE, ae );
49      }
50      else {
51        if ( !Telephone.isValidAreaCode(areacode) ) {
52          ae = new ActionError("validate.member.phone.evening.areacode",areacode);
53          errors.add( PROPERTY_PHONE, ae );
54        }
55        if ( !Telephone.isValidExchange(exchange) ) {
56          ae = new ActionError("validate.member.phone.evening.exchange",exchange);
57          errors.add( PROPERTY_PHONE, ae );
58        }
59        if ( !Telephone.isValidLocal(local) ) {
60          ae = new ActionError("validate.member.phone.evening.local",local);
61          errors.add( PROPERTY_PHONE, ae );
62        }
63        if ( !Telephone.isValidExtension(extension) ) {
64          ae=new ActionError("validate.member.phone.evening.extension",extension);
65          errors.add( PROPERTY_PHONE, ae );
66        }
67      }
68  
69      // Day phone
70      areacode  = this.form.getPhoneDayAreaCode();
71      exchange  = this.form.getPhoneDayExchange();
72      local     = this.form.getPhoneDayLocal();
73      extension = this.form.getPhoneDayExt();
74      if ( !isPhoneCompletelyBlank(areacode,exchange,local,extension) ) {
75        if ( !Telephone.isValidAreaCode(areacode) ) {
76          ae = new ActionError("validate.member.phone.day.areacode",areacode);
77          errors.add( PROPERTY_PHONE, ae );
78        }
79        if ( !Telephone.isValidExchange(exchange) ) {
80          ae = new ActionError("validate.member.phone.day.exchange",exchange);
81          errors.add( PROPERTY_PHONE, ae );
82        }
83        if ( !Telephone.isValidLocal(local) ) {
84          ae = new ActionError("validate.member.phone.day.local",local);
85          errors.add( PROPERTY_PHONE, ae );
86        }
87        if ( !Telephone.isValidExtension(extension) ) {
88          ae=new ActionError("validate.member.phone.day.extension",extension);
89          errors.add( PROPERTY_PHONE, ae );
90        }
91      }
92  
93      // Other phone
94      areacode  = this.form.getPhoneOtherAreaCode();
95      exchange  = this.form.getPhoneOtherExchange();
96      local     = this.form.getPhoneOtherLocal();
97      extension = this.form.getPhoneOtherExt();
98      if ( !isPhoneCompletelyBlank(areacode,exchange,local,extension) ) {
99        if ( !Telephone.isValidAreaCode(areacode) ) {
100         ae = new ActionError("validate.member.phone.other.areacode",areacode);
101         errors.add( PROPERTY_PHONE, ae );
102       }
103       if ( !Telephone.isValidExchange(exchange) ) {
104         ae = new ActionError("validate.member.phone.other.exchange",exchange);
105         errors.add( PROPERTY_PHONE, ae );
106       }
107       if ( !Telephone.isValidLocal(local) ) {
108         ae = new ActionError("validate.member.phone.other.local",local);
109         errors.add( PROPERTY_PHONE, ae );
110       }
111       if ( !Telephone.isValidExtension(extension) ) {
112         ae=new ActionError("validate.member.phone.other.extension",extension);
113         errors.add( PROPERTY_PHONE, ae );
114       }
115     }
116 
117   }
118 
119   private static boolean
120   isPhoneCompletelyBlank(String s0, String s1, String s2, String s3 ) {
121 
122     boolean retVal = true;
123 
124     retVal = retVal && ( s0 == null || s0.trim().length() == 0 );
125     retVal = retVal && ( s1 == null || s1.trim().length() == 0 );
126     retVal = retVal && ( s2 == null || s2.trim().length() == 0 );
127     retVal = retVal && ( s3 == null || s3.trim().length() == 0 );
128 
129     return retVal;
130   } // isPhoneCompletelyBlank(..)
131 
132 } // ValidateMemberPhoneNumbers
133 
134 /*
135  * $Log: ValidateMemberPhoneNumbers.java,v $
136  * Revision 1.4  2003/02/26 03:38:46  rphall
137  * Added copyright and GPL license
138  *
139  * Revision 1.3  2003/02/21 15:09:17  rphall
140  * More fixes to blank extension bug
141  *
142  * Revision 1.2  2003/02/19 03:32:21  rphall
143  * Implemented validation; removed stubbing
144  *
145  * Revision 1.1  2003/02/11 21:13:15  rphall
146  * Separate class for specific validation task; stubbed implementation
147  *
148  */
149