[Yanel-commits] rev 28292 - in public/yanel/trunk/src/contributions/resources/contact-form: . src/java/org/wyona/yanel/impl/resources

michi at wyona.com michi at wyona.com
Wed Oct 31 21:33:43 CET 2007


Author: michi
Date: 2007-10-31 21:33:42 +0100 (Wed, 31 Oct 2007)
New Revision: 28292

Modified:
   public/yanel/trunk/src/contributions/resources/contact-form/resource.xml
   public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
Log:
make email validation regex configurable

Modified: public/yanel/trunk/src/contributions/resources/contact-form/resource.xml
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/resource.xml	2007-10-31 20:33:12 UTC (rev 28291)
+++ public/yanel/trunk/src/contributions/resources/contact-form/resource.xml	2007-10-31 20:33:42 UTC (rev 28292)
@@ -24,5 +24,6 @@
   <property name="mime-type"/>
   <property name="from"/>
   <property name="xslt-body"/>
+  <property name="email-validation-regex"/>
 </rtd>
 </resource>

Modified: public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java
===================================================================
--- public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java	2007-10-31 20:33:12 UTC (rev 28291)
+++ public/yanel/trunk/src/contributions/resources/contact-form/src/java/org/wyona/yanel/impl/resources/ContactResource.java	2007-10-31 20:33:42 UTC (rev 28292)
@@ -93,6 +93,8 @@
     private RepoPath rp = null;
     private Path path = null;
     private String language = null;
+
+    private String defaultEmailRegEx = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*";
     
     /**
      * 
@@ -278,6 +280,7 @@
         if(email == null || ("").equals(email)) {
             transformer.setParameter("error", "emailNotSet");
         } else if(!validateEmail(email)) {
+            log.warn("Doesn't seem to be a valid email: " + email + " (according to the following regular expression: " + getEmailRegEx() + ")");
             transformer.setParameter("error", "emailNotValid");
         } else {
             contact = new ContactBean(request);
@@ -328,13 +331,12 @@
     }
     
     /**
-     * this method checks if the specified email is valid against a regex
+     * this method checks if the specified email is valid against a regular expression
      * @param email
      * @return true if email is valid
      */
-    private boolean validateEmail(String email) {
-        String emailRegEx = "(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*";
-        Pattern pattern = Pattern.compile(emailRegEx);
+    private boolean validateEmail(String email) throws Exception {
+        Pattern pattern = Pattern.compile(getEmailRegEx());
         Matcher matcher = pattern.matcher(email);
         return matcher.find();
     }
@@ -394,4 +396,12 @@
    protected RepositoryFactory getRepositoryFactory() {
        return yanel.getRepositoryFactory("DefaultRepositoryFactory");
    }
+
+    /**
+     *
+     */
+    private String getEmailRegEx() throws Exception {
+        if (getResourceConfigProperty("email-validation-regex") != null) return getResourceConfigProperty("email-validation-regex");
+        return defaultEmailRegEx;
+    }
 }



More information about the Yanel-commits mailing list