Clover Coverage Report - Atlassian XWork(Aggregated)
Coverage timestamp: Wed Jul 27 2011 23:39:31 CDT
12   41   5   12
8   24   0.42   1
1     5  
1    
 
 
  CommaSeparatedEmailValidator       Line # 15 12 5 100% 1.0
 
  (7)
 
1    /**
2    *
3    */
4    package com.atlassian.xwork.validator.validators;
5   
6    import com.opensymphony.util.TextUtils;
7    import com.opensymphony.xwork.validator.ValidationException;
8    import com.opensymphony.xwork.validator.validators.FieldValidatorSupport;
9   
10    /**
11    * Validate that a field contains comma separated e-mail addresses.
12    *
13    * @author Paul Curren
14    */
 
15    public class CommaSeparatedEmailValidator extends FieldValidatorSupport {
16   
 
17  7 toggle public void validate(Object object) throws ValidationException {
18  7 String fieldName = getFieldName();
19  7 String value = (String) getFieldValue(fieldName, object);
20   
21  7 if (value == null) {
22  1 return;
23    }
24   
25  6 value = value.trim();
26   
27  6 if (value.length() == 0) {
28  1 return;
29    }
30   
31  5 String[] emails = value.split("\\s*,\\s*"); // split on comma surrounded by option whitespace
32   
33    // now validate each e-mail address
34  9 for (int i=0; i < emails.length; i++) {
35  7 if (!TextUtils.verifyEmail(emails[i])) {
36  3 addFieldError(fieldName, object);
37  3 break;
38    }
39    }
40    }
41    }