Example usage for org.apache.commons.validator EmailValidator getInstance

List of usage examples for org.apache.commons.validator EmailValidator getInstance

Introduction

In this page you can find the example usage for org.apache.commons.validator EmailValidator getInstance.

Prototype

public static EmailValidator getInstance() 

Source Link

Document

Returns the Singleton instance of this validator.

Usage

From source file:de.hybris.platform.ycommercewebservices.v1.controller.CustomersController.java

/**
 * Client should pass customer's data as POST Body. Content-Type needs to be set to
 * application/x-www-form-urlencoded; charset=UTF-8 and sample body (urlencoded) is: old=1234&new=1111<br>
 * Sample call: https://localhost:9002/rest/v1/mysite/customers <br>
 * Method requires authentication and is restricted to <code>HTTPS<code> channel.<br> 
 * Method type : <code>POST</code> Register data need to be sent as post body..<br>
 * //  www  . java  2s.c  o m
 * @param login
 *           - login to be created
 * @param password
 *           - customer password
 * @param firstName
 *           - customer first name
 * @param lastName
 *           - customer last name
 * @param titleCode
 *           - customer's title
 * @throws DuplicateUidException
 *            in case the requested login already exists
 * @throws RequestParameterException
 */
@Secured({ "ROLE_CLIENT", "ROLE_TRUSTED_CLIENT" })
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
@ResponseStatus(value = HttpStatus.CREATED)
public void registerUser(@RequestParam final String login, @RequestParam final String password,
        @RequestParam(required = false) final String titleCode, @RequestParam final String firstName,
        @RequestParam final String lastName) throws DuplicateUidException, RequestParameterException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("registerUser: login=" + login);
    }

    if (!EmailValidator.getInstance().isValid(login)) {
        throw new RequestParameterException("Login [" + login + "] is not a valid e-mail address!",
                RequestParameterException.INVALID, "login");
    }

    final RegisterData registration = new RegisterData();
    registration.setFirstName(firstName);
    registration.setLastName(lastName);
    registration.setLogin(login);
    registration.setPassword(password);
    registration.setTitleCode(titleCode);
    customerFacade.register(registration);
}

From source file:edu.monash.merc.util.DMUtil.java

/**
 * Validate the email adress.//from   w w  w .  j  a  v  a2 s  . c om
 *
 * @param email The email address.
 * @return true if it is a valid email address.
 */
public static boolean validateEmail(String email) {
    EmailValidator validator = EmailValidator.getInstance();
    return validator.isValid(email);
}

From source file:com.googlecode.osde.internal.ui.wizards.newjsprj.WizardNewGadgetXmlPage.java

/**
 * Validates user input./* w  ww  .  j a  v  a2 s .co  m*/
 *
 * @return true if the title and gadget spec file names are not empty, and the email is valid
 */
private boolean validatePage() {
    String specFilename = specFilenameText.getText().trim();
    if (specFilename.length() == 0) {
        setErrorMessage("Gadget spec file name is empty. Please enter gadget spec file name.");
        setMessage(null);
        return false;
    }
    String title = titleText.getText().trim();
    if (title.length() == 0) {
        setErrorMessage("Title is empty. Please enter the title.");
        setMessage(null);
        return false;
    }
    String authorEmail = authorEmailText.getText().trim();
    EmailValidator emailValidator = EmailValidator.getInstance();
    if (!emailValidator.isValid(authorEmail)) {
        setErrorMessage("Invalid author email. Please enter a valid email.");
        setMessage(null);
        return false;
    }
    setErrorMessage(null);
    setMessage("Click Next to continue.");
    return true;
}

From source file:com.iana.boesc.utility.BOESCUtil.java

/**
 * validates correct email address/*from ww  w  .  j  a va 2 s. c  om*/
 * 
 * @param email
 * @return
 */
public static boolean emailValidator(String email) {
    if (email == null || email.trim().equals("")) {
        return false;
    }
    EmailValidator validator = EmailValidator.getInstance();
    boolean isAddressValid = validator.isValid(email);
    return isAddressValid;
}

From source file:de.hybris.platform.ycommercewebservices.v2.controller.UsersController.java

private void registerNewUser(final String login, final String password, final String titleCode,
        final String firstName, final String lastName) throws RequestParameterException, DuplicateUidException {
    validateParametersForNewUser(login, titleCode, firstName, lastName);

    if (LOG.isDebugEnabled()) {
        LOG.debug("registerUser: login=" + login);
    }/*  www.  j a v a  2s.  c o  m*/

    if (!EmailValidator.getInstance().isValid(login)) {
        throw new RequestParameterException("Login [" + login + "] is not a valid e-mail address!",
                RequestParameterException.INVALID, "login");
    }

    final RegisterData registration = new RegisterData();
    registration.setFirstName(firstName);
    registration.setLastName(lastName);
    registration.setLogin(login);
    registration.setPassword(password);
    registration.setTitleCode(titleCode);
    customerFacade.register(registration);
}

From source file:com.nagarro.core.v2.controller.UsersController.java

private void registerNewUser(final String login, final String password, final String titleCode,
        final String firstName, final String lastName) throws RequestParameterException, DuplicateUidException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("registerUser: login=" + sanitize(login));
    }/*from  w  w  w .j  a v  a2s .c  o m*/

    if (!EmailValidator.getInstance().isValid(login)) {
        throw new RequestParameterException("Login [" + sanitize(login) + "] is not a valid e-mail address!",
                RequestParameterException.INVALID, "login");
    }

    final RegisterData registration = new RegisterData();
    registration.setFirstName(firstName);
    registration.setLastName(lastName);
    registration.setLogin(login);
    registration.setPassword(password);
    registration.setTitleCode(titleCode);
    customerFacade.register(registration);
}

From source file:de.hybris.platform.ycommercewebservices.v2.controller.CartsController.java

/**
 * Method puts an email to the cart. This step is necessary to make a guest checkout.
 * //from w ww.  j a  va  2  s. c  o m
 * @formparam email Email of the guest user. It will be used during checkout process
 * @throws de.hybris.platform.commerceservices.customer.DuplicateUidException
 */
@Secured({ "ROLE_CLIENT", "ROLE_TRUSTED_CLIENT" })
@RequestMapping(value = "/{cartId}/email", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
public void guestLogin(@RequestParam final String email) throws DuplicateUidException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("createGuestUserForAnonymousCheckout: email=" + email);
    }

    if (!EmailValidator.getInstance().isValid(email)) {
        throw new RequestParameterException("Email [" + email + "] is not a valid e-mail address!",
                RequestParameterException.INVALID, "login");
    }

    customerFacade.createGuestUserForAnonymousCheckout(email, "guest");
}

From source file:cu.uci.coj.restapi.controller.RestUserProfileController.java

private String ValidateUser(User user) {
    ResourceBundleMessageSource r = new ResourceBundleMessageSource();
    r.setBasename("messages_en");

    user.setDob(new Date(user.getYear() - 1900, user.getMonth() - 1, user.getDay()));

    if (user.getNick().length() == 0)
        return r.getMessage("judge.register.error.nick", null, new Locale("en"));

    if ((user.getNick().length()) > 15)
        return r.getMessage("judge.register.error.long25charact", null, new Locale("en"));

    if (user.getNick().length() < 3)
        return r.getMessage("judge.register.error.less3charact", null, new Locale("en"));

    if (user.getName().length() < 1)
        return r.getMessage("errormsg.7", null, new Locale("en"));

    if (user.getName().length() > 30)
        return r.getMessage("errormsg.6", null, new Locale("en"));

    if (!user.getName().matches("[a-zA-Z\\.\\-\\'\\s]+"))
        return r.getMessage("errormsg.8", null, new Locale("en"));

    if (user.getLastname().length() < 1)
        return r.getMessage("errormsg.10", null, new Locale("en"));

    if (user.getLastname().length() > 50)
        return r.getMessage("errormsg.9", null, new Locale("en"));

    if (!user.getLastname().matches("[a-zA-Z\\.\\-\\'\\s]+"))
        return r.getMessage("errormsg.11", null, new Locale("en"));

    // si el correo ha sido cambiado y esta en uso por otra persona en el
    // COJ//from  w  ww.  ja va 2s  .  c  om
    if (user.getEmail().length() == 0)
        return r.getMessage("errormsg.51", null, new Locale("en"));

    if (!StringUtils.isEmpty(user.getEmail()) && userDAO.bool("email.changed", user.getEmail(), user.getUid())
            && userDAO.emailExistUpdate(user.getEmail().trim(), user.getUsername()))
        return r.getMessage("judge.register.error.emailexist", null, new Locale("en"));

    EmailValidator emailValidator = EmailValidator.getInstance(); //ver como inyectar este objeto
    if (!emailValidator.isValid(user.getEmail()))
        return r.getMessage("judge.register.error.bademail", null, new Locale("en"));

    if (user.getCountry_id() == 0)
        return r.getMessage("judge.register.error.country", null, new Locale("en"));

    if (user.getInstitution_id() == 0)
        return r.getMessage("judge.register.error.institution", null, new Locale("en"));

    if (user.getLid() == 0)
        return r.getMessage("judge.register.error.planguage", null, new Locale("en"));

    if (user.getLocale() == 0)
        return r.getMessage("judge.register.error.locale", null, new Locale("en"));

    if (user.getName().length() == 0)
        return r.getMessage("judge.register.error.name", null, new Locale("en"));

    if (user.getGender() == 0)
        return r.getMessage("judge.register.error.gender", null, new Locale("en"));

    return "0";
}

From source file:com.acc.controller.CustomersController.java

@Secured("ROLE_CUSTOMERGROUP")
@RequestMapping(value = "/current/login", method = { RequestMethod.PUT, RequestMethod.POST })
@ResponseBody/*from w w  w.java 2s . co m*/
public LoginChangeResponse changeLogin(@RequestParam final String newLogin, @RequestParam final String password)
        throws DuplicateUidException, PasswordMismatchException {
    if (!EmailValidator.getInstance().isValid(newLogin)) {
        throw new IllegalArgumentException("Login is not a valid e-mail address! (Login=" + newLogin + ")");
    }
    customerFacade.changeUid(newLogin, password);
    final LoginChangeResponse loginChangeResponse = new LoginChangeResponse();
    loginChangeResponse.setSuccess(true);
    return loginChangeResponse;
}

From source file:com.nagarro.core.v2.controller.CartsController.java

/**
 * Assigns an email to the cart. This step is required to make a guest checkout.
 *
 * @formparam email Email of the guest user. It will be used during checkout process
 * @throws de.hybris.platform.commerceservices.customer.DuplicateUidException
 *//*from  w  ww .  j  a  v  a2 s .c  o m*/
@Secured({ "ROLE_CLIENT", "ROLE_TRUSTED_CLIENT" })
@RequestMapping(value = "/{cartId}/email", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
public void guestLogin(@RequestParam final String email) throws DuplicateUidException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("createGuestUserForAnonymousCheckout: email=" + sanitize(email));
    }

    if (!EmailValidator.getInstance().isValid(email)) {
        throw new RequestParameterException("Email [" + sanitize(email) + "] is not a valid e-mail address!",
                RequestParameterException.INVALID, "login");
    }

    customerFacade.createGuestUserForAnonymousCheckout(email, "guest");
}