You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/10/10 09:19:10 UTC

svn commit: r583373 - in /ofbiz/trunk: applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java framework/base/src/base/org/ofbiz/base/util/UtilValidate.java

Author: jacopoc
Date: Wed Oct 10 00:19:10 2007
New Revision: 583373

URL: http://svn.apache.org/viewvc?rev=583373&view=rev
Log:
Issue OFBIZ-668

1) replaced the logic inside the isEmail method with a call to org.apache.commons.validator.EmailValidator.isValid(...)
2) I've left the code that returns true if the string is empty
3) the only remarkable difference is that the original code was accepting (by default) a domain without dots (user@localhost); the new code requires a real domain (user@domain.com)

Thanks to John Martin for the advices.

Modified:
    ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilValidate.java

Modified: ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java?rev=583373&r1=583372&r2=583373&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java (original)
+++ ofbiz/trunk/applications/party/src/org/ofbiz/party/communication/CommunicationEventServices.java Wed Oct 10 00:19:10 2007
@@ -206,7 +206,7 @@
                     if (UtilValidate.isEmpty(emailAddress)) continue;
                     emailAddress = emailAddress.trim();
                     
-                    if (! UtilValidate.isEmail(emailAddress, true)) {
+                    if (! UtilValidate.isEmail(emailAddress)) {
                         
                         // If validation fails, just log and skip the email address
                         Debug.logError(skippingInvalidEmailAddress + ": " + emailAddress, module);

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilValidate.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilValidate.java?rev=583373&r1=583372&r2=583373&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilValidate.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilValidate.java Wed Oct 10 00:19:10 2007
@@ -21,6 +21,8 @@
 import java.util.Calendar;
 import java.util.Collection;
 
+import org.apache.commons.validator.EmailValidator;
+
 /**
  * General input/data validation methods
  * Utility methods for validating data, especially input.
@@ -687,38 +689,8 @@
     }
 
     public static boolean isEmail(String s) {
-        return isEmail(s, false);
-    }
-
-    /** Email address must be of form a@b.c -- in other words:
-     *  - there must be at least one character before the @
-     *  - there must be at least one character before and after the .
-     *  - the character @ is required, and . requirement is controlled
-     *  - by requireDot
-     */
-    public static boolean isEmail(String s, boolean requireDot) {
-
-        // todo: use regular expression validation
-        
         if (isEmpty(s)) return defaultEmptyOK;
-
-        // is s whitespace?
-        if (isWhitespace(s)) return false;
-
-        int atSymbolIndex = s.indexOf('@');
-
-        // there must be >= 1 character before @
-        // indexOf returns -1 if char not found, so 0 or -1 are bad
-        if (atSymbolIndex <= 0 ) return false;
-
-        if (requireDot) {
-            int dotIndex = s.lastIndexOf('.');
-            if (dotIndex == -1) return false; // no dot
-            if (dotIndex < atSymbolIndex + 2) return false; // nothing between @ and .
-            if (dotIndex == s.length() - 1 ) return false; // . is last character
-        }
-
-        return true;
+        return EmailValidator.getInstance().isValid(s);
     }
 
     /** isUrl returns true if the string contains ://