]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java
Please cherry-pick:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / validator / emailaddress / PizzaEmailAddressValidator.java
index 57bacdb2646d8093a308b58a9833130d75e5fc70..143f0575d5d69cca3ca6120ef09148f2b4b50f79 100644 (file)
@@ -44,14 +44,14 @@ public class PizzaEmailAddressValidator extends BaseStringValidator implements V
        private static ContactSessionBeanRemote CONTACT_BEAN;
 
        /**
-        * Pattern matcher
+        * Email pattern
         */
-       private static final Pattern EMAIL_PATTERN = Pattern.compile(PizzaEmailAddressValidator.EMAIL_REGEX);
+       private static final String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; //NOI18N
 
        /**
-        * Email pattern
+        * Pattern matcher
         */
-       private static final String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; //NOI18N
+       private static final Pattern PATTERN_MATCHER = Pattern.compile(PizzaEmailAddressValidator.EMAIL_REGEX);
 
        /**
         * Serial number
@@ -66,34 +66,32 @@ public class PizzaEmailAddressValidator extends BaseStringValidator implements V
 
        @Override
        public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
-               System.out.println("validate: value=" + value); //NOI18N
                // The required field
                String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N
 
                // Default is to reject empty email address fields
-               Boolean allowEmptyEmail = Boolean.FALSE;
+               Boolean allowEmptyValue = Boolean.FALSE;
 
-               // Is attribute "allowEmptyEmail" set?
-               if (component.getAttributes().containsKey("allowEmptyEmail")) { //NOI18N
+               // Is attribute "allowEmptyValue" set?
+               if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N
                        // Get attribute
-                       Object attribute = component.getAttributes().get("allowEmptyEmail"); //NOI18N
-                       System.out.println("attribute=" + attribute); //NOI18N
+                       Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N
 
                        // Make sure, it is Boolean as no String is accepted anymore
                        if (!(attribute instanceof String)) {
                                // Not valid attribute, please use "true" or "false" (default)
-                               throw new IllegalArgumentException("allowEmptyEmail must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
+                               throw new IllegalArgumentException("allowEmptyValue must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
                        }
 
                        // Securely cast it
-                       allowEmptyEmail = Boolean.parseBoolean((String) attribute);
+                       allowEmptyValue = Boolean.parseBoolean((String) attribute);
                }
 
                // Pre-validation (example: not null, not a string, empty string ...)
-               super.preValidate(context, component, value, requiredFields, allowEmptyEmail);
+               super.preValidate(context, component, value, requiredFields, allowEmptyValue);
 
                // Is the email address empty and allowed?
-               if (null == value && allowEmptyEmail) {
+               if (null == value && allowEmptyValue) {
                        // Then accept this here
                        return;
                } else if (null == value) {
@@ -107,7 +105,7 @@ public class PizzaEmailAddressValidator extends BaseStringValidator implements V
 
                // Checks if the email address matches a regex ("low-level" check)
                // @TODO Should also be done by <f:validatorRegex />)
-               boolean matches = EMAIL_PATTERN.matcher(emailAddress).matches(); //NOI18N
+               boolean matches = PATTERN_MATCHER.matcher(emailAddress).matches(); //NOI18N
 
                // Is the email address valid?
                if (!matches) {