List of usage examples for org.apache.commons.validator EmailValidator getInstance
public static EmailValidator getInstance()
From source file:com.adsapient.gui.forms.GuestAccountActionForm.java
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { HibernateEntityDao hibernateEntityDao = (HibernateEntityDao) ContextAwareGuiBean.getContext() .getBean("hibernateEntityDao"); ActionErrors errors = new ActionErrors(); if ("list".equalsIgnoreCase(this.action) || "init".equalsIgnoreCase(this.action) || "view".equalsIgnoreCase(this.action) || "remove".equalsIgnoreCase(this.action) || "resetStatistic".equalsIgnoreCase(this.action)) { return null; }/*from w w w .ja v a 2s .c o m*/ if (getName().trim().length() == 0) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.edituser.namerequired")); } if (getProfileLogin().trim().length() == 0) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.edituser.loginrequired")); } if (getProfilePassword().trim().length() == 0) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.passwordrequired")); } if (!this.getProfilePassword().equals(this.getConfirmpassword()) && (this.getProfilePassword().length() != 0)) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.confirmpassword")); } if (getEmail().trim().length() == 0) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.emailrequired")); } EmailValidator ev = EmailValidator.getInstance(); if (!ev.isValid(getEmail())) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.edituser.wrongemail")); } UserImpl sameUser = (UserImpl) hibernateEntityDao.loadObjectWithCriteria(UserImpl.class, "login", getProfileLogin()); if ((sameUser != null) && (!sameUser.getId().equals(this.getId()))) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.login.exist")); } return errors; }
From source file:gov.nih.nci.cabig.caaers.web.ae.SubmitReportTab.java
public boolean isEmailValid(String email) { String trimmedEmail = (email != null) ? email.trim() : email; return EmailValidator.getInstance().isValid(trimmedEmail); }
From source file:de.knurt.fam.template.util.ContactDetailsRequestHandler.java
/** * return true, if the request is valid. the request is valid, if the user * wants to change its own contact details or if the user is an * administrator. invalid request is missing param that must be there or * modify another user without to have the right to OR modify another user * without to have the right to.// w w w . ja va 2 s . c o m * * @param rq * request got * @return true, if the request is valid. */ public static boolean isValidUpdateRequest(HttpServletRequest rq) { boolean result = userHasRightToViewAndModifyContactDetails(rq); if (result) { result = getUserOfRequest(rq) != null; } if (result) { String newMail = ContactDetailsRequestHandler.getValue(rq, "mail"); if (newMail != null && !EmailValidator.getInstance().isValid(newMail)) { result = false; } } return result; }
From source file:com.seajas.search.attender.service.remoting.RemotingService.java
/** * Determine whether a given email is valid. * /*from w w w . ja va 2s . c om*/ * @param email * @return boolean */ public boolean validEmail(final String email) { return EmailValidator.getInstance().isValid(email); }
From source file:com.patrolpro.beans.SignupClientBean.java
public boolean validateInformation() { boolean isValid = true; FacesContext myContext = FacesContext.getCurrentInstance(); if (contactName == null || contactName.length() < 3) { myContext.addMessage(this.nameErrorLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a your name!")); isValid = false;/*from ww w. jav a 2 s . c om*/ } if (companyName == null || companyName.length() < 3) { myContext.addMessage(this.companyNameLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a company name!")); isValid = false; } EmailValidator emailValidator = EmailValidator.getInstance(); if (contactEmail == null || contactEmail.length() < 3) { myContext.addMessage(this.contactEmailLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a contact email!")); isValid = false; } else if (!emailValidator.isValid(contactEmail)) { myContext.addMessage(this.contactEmailLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a valid email!")); isValid = false; } if (contactPhone == null || contactPhone.length() < 3) { myContext.addMessage(this.contactPhoneLabel.getClientId(myContext), new FacesMessage(FacesMessage.SEVERITY_ERROR, "", "Please enter a contact phone number!")); isValid = false; } return isValid; }
From source file:com.jdon.jivejdon.presentation.form.AccountForm.java
public void doValidate(ActionMapping mapping, HttpServletRequest request, List errors) { if ((getAction() == null) || ModelForm.EDIT_STR.equals(getAction()) || ModelForm.CREATE_STR.equals(getAction())) { addErrorIfStringEmpty(errors, "username.required", getUsername()); if (getPassword() != null && getPassword().length() > 0) { if (!getPassword().equals(getPassword2())) { errors.add("password.check"); }//from w w w. ja v a2 s . c o m } addErrorIfStringEmpty(errors, "email.emailcheck", getEmail()); if (!UtilValidate.isAlphanumeric(this.getUsername())) { errors.add("username.alphanumeric"); } if (this.getUsername() != null && this.getUsername().length() > 20) { errors.add("username.toolong"); } if (!EmailValidator.getInstance().isValid(this.getEmail())) { errors.add("email.emailcheck"); } if (!SkinUtils.verifyRegisterCode(registerCode, request)) { errors.add("registerCode.dismatch"); } } }
From source file:com.github.jgility.core.project.Person.java
/** * Setzt die E-Mail-Adresse und berprft dessen Wert * /*from w w w . j ava2s .com*/ * @param eMail E-Mail-Adresse <br> * muss dem Standard entsprechen. Zum Beispiel: <code>example@mail.com</code> * @throws IllegalArgumentException wird geworfen, wenn Parameter keine valide E-Mail-Adresse * ist */ public void setEMail(String eMail) throws IllegalArgumentException { EmailValidator emailValidator = EmailValidator.getInstance(); if (emailValidator.isValid(eMail)) { this.eMail = eMail; } else { throw new IllegalArgumentException("e-mail adress is invalid: " + eMail); } }
From source file:com.fengduo.bee.web.shiro.ShiroDbRealm.java
/** * ?,.//from w ww . ja va 2s . com */ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { if (null == authcToken) { throw new AccountException("!"); } UsernamePasswordCaptchaToken token = (UsernamePasswordCaptchaToken) authcToken; String name = token.getUsername(); if (StringUtils.isEmpty(name)) { throw new AccountException("??!"); } char[] password = token.getPassword(); if (password == null || password.length == 0) { throw new AccountException("?!"); } // ?? String captcha = token.getCaptcha(); boolean useCaptcha = token.isUseCaptcha(); if (useCaptcha) { String exitCode = (String) SecurityUtils.getSubject().getSession() .getAttribute(ValidateCodeServlet.VALIDATE_CODE); if (StringUtils.isEmpty(exitCode)) { throw new CaptchaInvalidException("???,??!"); } if (StringUtils.isEmpty(captcha) || !captcha.equalsIgnoreCase(exitCode)) { throw new CaptchaException("??!"); } } Parameter map = Parameter.newParameter(); if (EmailValidator.getInstance().isValid(name)) { map.put("email", name); } else if (StringFormatter.isLegalPhone(name)) { map.put("phone", name); } else { map.put("nick", name); } final User user = userService.queryUser(map); if (null == user) { throw new UnknownAccountException(",!"); } // if (user.getVerifyStatus() == VerifyStatusEnum.NORMAL.getValue()) { IdentityInfo identityInfo = userService.getIdentityInfo(user.getId()); if (identityInfo != null) { user.setIdentity(true); user.setRealName(identityInfo.getRealName()); } } return new SimpleAuthenticationInfo(new ShiroUser(user, password, captcha), user.getPassword(), ByteSource.Util.bytes(UserConstants.SALT), getName()); }
From source file:gov.nih.nci.cabig.caaers.web.rule.notification.NotificationsTab.java
@Override protected void validate(ReportDefinitionCommand command, BeanWrapper commandBean, Map<String, InputFieldGroup> fieldGroups, Errors errors) { if (CollectionUtils.isEmpty(command.getReportDefinition().getPlannedNotifications())) return;// w ww . j a v a 2s . c o m List<PlannedNotification> plannedNotifications = command.getEmailNotifications(); if (CollectionUtils.isEmpty(plannedNotifications)) return; EmailValidator emailValidator = EmailValidator.getInstance(); int i = 0; for (PlannedNotification plannedNotification : plannedNotifications) { i++; PlannedEmailNotification nf = (PlannedEmailNotification) plannedNotification; // Message if (nf.getNotificationBodyContent() == null || StringUtils.isEmpty(nf.getNotificationBodyContent().getBody())) { errors.rejectValue("tempProperty", "RPD_003", new Object[] { i }, "Message Invalid in Email Notification(" + i + ")"); } // Recipients if (nf.getRecipients() == null) { errors.rejectValue("tempProperty", "RPD_004", new Object[] { i }, "Invalid Recipient Information in Email Notification (" + i + ")"); } else { for (Recipient recipient : nf.getRecipients()) { if (StringUtils.isEmpty(recipient.getContact())) { errors.rejectValue("tempProperty", "RPD_004", new Object[] { i }, "Invalid Recipient Information in Email Notification (" + i + ")"); break; } // valid email? if (recipient instanceof ContactMechanismBasedRecipient) { if (!emailValidator.isValid(recipient.getContact())) { errors.rejectValue("tempProperty", "RPD_005", new Object[] { recipient.getContact(), i }, "Invalid email address [" + recipient.getContact() + "] in Email Notification (" + i + ")"); break; } } } } // subject line if (StringUtils.isEmpty(nf.getSubjectLine())) { errors.rejectValue("tempProperty", "RPD_006", new Object[] { i }, "Subject line Invalid in Email Notification(" + i + ")"); } } }
From source file:com.seajas.search.attender.wsdl.Profile.java
/** * {@inheritDoc}/*from ww w.jav a 2s . c o m*/ */ @Override public List<ProfileError> createProfile(final String email, final String emailLanguage, final String timeZone, final String notificationType, final Integer day, final Integer hour, final Integer minute, final Integer interval, final Integer maximum, final String query, final String searchParameterFormat, final String searchParameterLanguage, final String searchParameterAuthor, final String searchParameterType, final String searchParameterGeo, final List<Integer> taxonomyIdentifiers) { List<ProfileError> errors = new ArrayList<ProfileError>(); // Validate the given input if (StringUtils.isEmpty(query)) errors.add(new ProfileError("query", "profiles.error.query.empty")); String unescapedQuery = StringEscapeUtils.unescapeXml(StringEscapeUtils.unescapeXml(query)); // Validate the subscriber(s) String[] emails = email.trim().split(","); for (String subscriberEmail : emails) if (StringUtils.isEmpty(subscriberEmail.trim()) || !EmailValidator.getInstance().isValid(subscriberEmail.trim())) errors.add(new ProfileError("email", "profiles.error.subscriber.emails.invalid")); if (StringUtils.isEmpty(emailLanguage)) errors.add(new ProfileError("emailLanguage", "profiles.error.subscriber.email.languages.invalid")); else if (!attenderService.getAvailableSearchLanguages().contains(emailLanguage)) errors.add(new ProfileError("emailLanguage", "profiles.error.subscriber.email.languages.invalid")); if (StringUtils.isEmpty(timeZone)) errors.add(new ProfileError("timeZone", "profiles.error.subscriber.timezones.invalid")); else if (!Arrays.asList(TimeZone.getAvailableIDs()).contains(timeZone) && !timeZone.matches("^GMT[+\\-][0-9]{2}:[0-9]{2}$")) errors.add(new ProfileError("timeZone", "profiles.error.subscriber.timezones.invalid")); if (StringUtils.isEmpty(notificationType)) errors.add(new ProfileError("notificationType", "profiles.error.subscriber.types.invalid")); else try { NotificationType.valueOf(notificationType); } catch (IllegalArgumentException e) { errors.add(new ProfileError("notificationType", "profiles.error.subscriber.types.invalid")); } if (day == null) errors.add(new ProfileError("day", "profiles.error.subscriber.days.invalid")); else if (day < 0 || day > 6) errors.add(new ProfileError("day", "profiles.error.subscriber.days.invalid")); if (hour == null) errors.add(new ProfileError("subscriberHours", "profiles.error.subscriber.hours.invalid")); else if (hour < 0 || hour > 23) errors.add(new ProfileError("subscriberHours", "profiles.error.subscriber.hours.invalid")); if (minute == null) errors.add(new ProfileError("minute", "profiles.error.subscriber.minutes.invalid")); else if (minute < 0 || minute > 59) errors.add(new ProfileError("minute", "profiles.error.subscriber.minutes.invalid")); // Validate the search parameters if (!StringUtils.isEmpty(searchParameterFormat)) try { MediaType.parseMediaTypes(searchParameterFormat.replaceAll(" ", ",")); } catch (IllegalArgumentException e) { errors.add(new ProfileError("searchParameterFormat", "profiles.error.search.parameter.format.invalid")); } else if (!StringUtils.isEmpty(searchParameterLanguage)) { if (!attenderService.getAvailableSearchLanguages().contains(searchParameterLanguage)) errors.add(new ProfileError("searchParameterLanguage", "profiles.error.search.parameter.language.invalid")); } // Validate the taxonomy identifiers for (Integer taxonomyIdentifier : taxonomyIdentifiers) if (taxonomyIdentifier == null) errors.add(new ProfileError("taxonomyIdentifiers", "profiles.error.taxonomy.identifiers.empty")); // Add it up if there aren't any errors if (errors.size() == 0) { List<ProfileSubscriber> subscribers = new ArrayList<ProfileSubscriber>(emails.length); for (String subscriberEmail : emails) subscribers.add(new ProfileSubscriber(subscriberEmail.trim(), emailLanguage, false, null, timeZone, NotificationType.valueOf(notificationType), day, hour, minute, interval, maximum, null)); Map<String, String> searchParameters = new HashMap<String, String>(); if (!StringUtils.isEmpty(searchParameterFormat)) searchParameters.put("dcterms_format", searchParameterFormat); if (!StringUtils.isEmpty(searchParameterLanguage)) searchParameters.put("dcterms_language", searchParameterLanguage); if (!StringUtils.isEmpty(searchParameterAuthor)) searchParameters.put("dcterms_author", searchParameterAuthor); if (!StringUtils.isEmpty(searchParameterType)) searchParameters.put("dcterms_type", searchParameterType); if (!StringUtils.isEmpty(searchParameterGeo)) searchParameters.put("geo_total", searchParameterGeo); attenderService.addProfile(unescapedQuery, true, subscribers, searchParameters, taxonomyIdentifiers); } return errors; }