Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/shared/validators/EmailValidator.java

Diff revisions: vs.
  @@ -1,17 +1,18 @@
1 1 package com.temp.shared.validators;
2 2
3 - import com.temp.shared.ValueValidator;
4 - import org.litesoft.core.util.externalization.E13nData;
5 - import com.temp.shared.utils.StringUtils;
3 + import org.litesoft.core.util.externalization.*;
4 +
5 + import com.temp.shared.*;
6 + import com.temp.shared.utils.*;
6 7
7 8 /**
8 9 * Email Address Validator, that requires at a minimum that an email address
9 10 * consists of at least: an addressee, an at sign ('@'), and a domain.
10 - *
11 + * <p/>
11 12 * Specifically, no spaces or control characters are allowed, addresses can not
12 13 * be empty, and the domain must consist of at least two levels separated by
13 14 * periods ('.').
14 - *
15 + * <p/>
15 16 * The resulting format for the email is:<br />
16 17 * <ul>
17 18 * (addressee)@[((domain).)*](secondary domain).(primary domain)
  @@ -40,73 +41,71 @@
40 41 protected EmailValidator() {
41 42 }
42 43
43 - public boolean isValid(String email) {
44 - return (null == checkValue(email));
44 + public boolean isValid( String email ) {
45 + return (null == checkValue( email ));
45 46 }
46 47
47 48 @Override
48 - public E13nData checkValue(String email) {
49 - email = StringUtils.noEmpty(email);
50 - if (email == null) {
51 - return new E13nData(ErrorTemplateIdCode.EmailEmpty);
49 + public E13nData checkValue( String email ) {
50 + email = StringUtils.noEmpty( email );
51 + if ( email == null ) {
52 + return new E13nData( ErrorTemplateIdCode.EmailEmpty );
52 53 }
53 - int at = email.indexOf(' ');
54 - if (at != -1) {
55 - return new E13nData(ErrorTemplateIdCode.EmailNoSpacesAllowed);
54 + int at = email.indexOf( ' ' );
55 + if ( at != -1 ) {
56 + return new E13nData( ErrorTemplateIdCode.EmailNoSpacesAllowed );
56 57 }
57 - at = StringUtils.indexOfControlCharacter(email);
58 - if (at != -1) {
59 - return new E13nData(ErrorTemplateIdCode.EmailNoCtrlCharsAllowed);
58 + at = StringUtils.indexOfControlCharacter( email );
59 + if ( at != -1 ) {
60 + return new E13nData( ErrorTemplateIdCode.EmailNoCtrlCharsAllowed );
60 61 }
61 - at = email.indexOf('@');
62 - if (at == -1) {
63 - return new E13nData(ErrorTemplateIdCode.EmailNoAtSign);
62 + at = email.indexOf( '@' );
63 + if ( at == -1 ) {
64 + return new E13nData( ErrorTemplateIdCode.EmailNoAtSign );
64 65 }
65 - String addressee = email.substring(0, at);
66 - String domain = email.substring(at + 1);
67 - if (domain.indexOf('.') == -1) {
68 - return new E13nData(ErrorTemplateIdCode.EmailNoSecondaryDomain);
66 + String addressee = email.substring( 0, at );
67 + String domain = email.substring( at + 1 );
68 + if ( domain.indexOf( '.' ) == -1 ) {
69 + return new E13nData( ErrorTemplateIdCode.EmailNoSecondaryDomain );
69 70 }
70 - if (!domainOK(domain)) {
71 - return new E13nData(ErrorTemplateIdCode.EmailInvalidDomainFormat);
71 + if ( !domainOK( domain ) ) {
72 + return new E13nData( ErrorTemplateIdCode.EmailInvalidDomainFormat );
72 73 }
73 - if (addressee.length() == 0) {
74 - return new E13nData(ErrorTemplateIdCode.EmailNoAddressee);
74 + if ( addressee.length() == 0 ) {
75 + return new E13nData( ErrorTemplateIdCode.EmailNoAddressee );
75 76 }
76 - return addresseeOK(addressee) ? null : new E13nData(ErrorTemplateIdCode.EmailInvalidAddresseeFormat);
77 + return addresseeOK( addressee ) ? null : new E13nData( ErrorTemplateIdCode.EmailInvalidAddresseeFormat );
77 78 }
78 79
79 - protected boolean domainOK(String domain) {
80 + protected boolean domainOK( String domain ) {
80 81 int from = 0;
81 - for (int at; -1 != (at = domain.indexOf('.', from)); from = at + 1) {
82 - if (!subDomainOK(domain.substring(from, at))) {
82 + for ( int at; -1 != (at = domain.indexOf( '.', from )); from = at + 1 ) {
83 + if ( !subDomainOK( domain.substring( from, at ) ) ) {
83 84 return false;
84 85 }
85 86 }
86 - return subDomainOK(domain.substring(from));
87 + return subDomainOK( domain.substring( from ) );
87 88 }
88 89
89 90 /**
90 91 * Check that the Sub-Domain is OK.
91 - *
92 + * <p/>
92 93 * TODO: this should be evolved to have the "real" rules!
93 94 *
94 - * @param subDomain
95 - * !null
95 + * @param subDomain !null
96 96 */
97 - protected boolean subDomainOK(String subDomain) {
97 + protected boolean subDomainOK( String subDomain ) {
98 98 return (subDomain.length() != 0);
99 99 }
100 100
101 101 /**
102 102 * Check that the Addressee is OK.
103 - *
103 + * <p/>
104 104 * TODO: this should be evolved to have the "real" rules!
105 105 *
106 - * @param addressee
107 - * !null
106 + * @param addressee !null
108 107 */
109 - protected boolean addresseeOK(String addressee) {
108 + protected boolean addresseeOK( String addressee ) {
110 109 return true;
111 110 }
112 111 }