Tal Nisan has uploaded a new change for review. Change subject: frontend: Removed MailAddress class ......................................................................
frontend: Removed MailAddress class The class MainAddress though it's obscure name is an email address regex validator which has to be instantiated to validate and throws a runtime exception if the email is invalid, this is definitely a wrong behavior considering what we need the validator to be, the regex validation was extracted to the class that used it in the first place - EmailValidation and the redundant try/catch block and instantiation of a new class were removed Change-Id: I36c1f8f11d48ccfb00a9204c89828cd15c76338f Signed-off-by: Tal Nisan <[email protected]> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/EmailValidation.java D frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/MailAddress.java 2 files changed, 10 insertions(+), 30 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/89/14489/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/EmailValidation.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/EmailValidation.java index 31b55c1..4e72981 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/EmailValidation.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/validation/EmailValidation.java @@ -1,25 +1,28 @@ package org.ovirt.engine.ui.uicommonweb.validation; +import org.ovirt.engine.core.compat.Regex; +import org.ovirt.engine.core.compat.RegexOptions; import org.ovirt.engine.ui.uicompat.ConstantsManager; -import org.ovirt.engine.ui.uicompat.MailAddress; @SuppressWarnings("unused") public class EmailValidation implements IValidation { + + private static String ATOM = "[^\\x00-\\x1F^\\(^\\)^\\<^\\>^\\@^\\,^\\;^\\:^\\\\^\\\"^\\.^\\[^\\]^\\s]"; //$NON-NLS-1$ + private static String DOMAIN = "(" + ATOM + "+(\\." + ATOM + "+)*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + private static String IP_DOMAIN = "\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\]"; //$NON-NLS-1$ + + private static String pattern = "^" + ATOM + "+(\\." + ATOM + "+)*@" + DOMAIN + "|" + IP_DOMAIN + ")$"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + @Override public ValidationResult validate(Object value) { ValidationResult result = new ValidationResult(); - try - { - new MailAddress((String) value); - } catch (RuntimeException e) - { + if (!Regex.IsMatch((String) value, pattern, RegexOptions.IgnoreCase)) { result.setSuccess(false); result.getReasons().add(ConstantsManager.getInstance().getConstants().invalidEmailAddressInvalidReason()); } - return result; } } diff --git a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/MailAddress.java b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/MailAddress.java deleted file mode 100644 index 1ec9378..0000000 --- a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/MailAddress.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.ovirt.engine.ui.uicompat; - -import org.ovirt.engine.core.compat.Regex; -import org.ovirt.engine.core.compat.RegexOptions; - -/** - * Email address verification. - * (Imitate 'org.hibernate.validator.constraints.impl.EmailValidator') - */ -public class MailAddress { - - private static String ATOM = "[^\\x00-\\x1F^\\(^\\)^\\<^\\>^\\@^\\,^\\;^\\:^\\\\^\\\"^\\.^\\[^\\]^\\s]"; //$NON-NLS-1$ - private static String DOMAIN = "(" + ATOM + "+(\\." + ATOM + "+)*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - private static String IP_DOMAIN = "\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\]"; //$NON-NLS-1$ - - private static String pattern = "^" + ATOM + "+(\\." + ATOM + "+)*@" + DOMAIN + "|" + IP_DOMAIN + ")$"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - - public MailAddress(String value) { - if (!Regex.IsMatch(value, pattern, RegexOptions.IgnoreCase)) { - throw new RuntimeException(); - } - } -} -- To view, visit http://gerrit.ovirt.org/14489 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I36c1f8f11d48ccfb00a9204c89828cd15c76338f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Tal Nisan <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
