Coverage Report - us.daveread.utility.formatcheck.format.EmailDataType
 
Classes in this File Line Coverage Branch Coverage Complexity
EmailDataType
100%
11/11
100%
2/2
2
 
 1  
 package us.daveread.utility.formatcheck.format;
 2  
 
 3  
 import org.apache.log4j.Logger;
 4  
 
 5  
 /**
 6  
  * <p>Title: EmailDataType
 7  
  * <p>Description: Represents a data type that may hold an email address
 8  
  * <p>Copyright: Copyright (c) 2005
 9  
  * <p>This program is free software; you can redistribute it and/or modify
 10  
  * it under the terms of the GNU General Public License as published by
 11  
  * the Free Software Foundation; either version 2 of the License, or
 12  
  * (at your option) any later version.
 13  
  * <p>This program is distributed in the hope that it will be useful,
 14  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16  
  * GNU General Public License for more details.
 17  
  * <p>You should have received a copy of the GNU General Public License
 18  
  * along with this program; if not, write to the Free Software
 19  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 20  
  * </p>
 21  
  *
 22  
  * @author David Read
 23  
  * @version $Id: EmailDataType.java,v 1.2 2006/06/14 23:32:14 daveread Exp $
 24  
  */
 25  
 public class EmailDataType extends DataType {
 26  
 
 27  
     /** Regular expression matching a valid email address
 28  
      * Source: http://www.regexlib.com/REDetails.aspx?regexp_id=295 */
 29  
     private final static String EMAILREGEX =
 30  
             "^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\\-+)|([A-Za-z0-9]+\\.+)|" +
 31  
             "([A-Za-z0-9]+\\++))*[A-Za-z0-9]+@((\\w+\\-+)|(\\w+\\.))*" +
 32  
             "\\w{1,63}\\.[a-zA-Z]{2,6}$";
 33  
 
 34  
     /** Logger */
 35  2
     private static final Logger logger = Logger.getLogger(EmailDataType.class);
 36  
 
 37  
     /**
 38  
      * Creates an Email/SSO data type with the supplied description.
 39  
      *
 40  
      * @param aDescription String The display description for this date type
 41  
      */
 42  
     public EmailDataType(String aDescription) {
 43  4
         super(null, aDescription);
 44  4
         setTypeName("Email");
 45  
 
 46  4
         logger.info("Create email data type:aDescription[" +
 47  
                     aDescription + "] typeName[" + getTypeName() + "]");
 48  4
     }
 49  
 
 50  
     /**
 51  
      * Tests whether the field value is a proper email address or SSO id.
 52  
      *
 53  
      * @param fieldValue String The value being checked
 54  
      *
 55  
      * @return boolean True if the field is valid, false otherwise
 56  
      */
 57  
     public boolean isValid(String fieldValue) {
 58  
         boolean okay;
 59  
 
 60  3
         okay = false;
 61  
 
 62  3
         fieldValue = fieldValue.trim();
 63  
 
 64  3
         if (fieldValue != null) {
 65  3
             if (fieldValue.matches(EMAILREGEX)) {
 66  1
                 okay = true;
 67  
             }
 68  
         }
 69  
 
 70  3
         return okay;
 71  
     }
 72  
 }