Example usage for org.apache.commons.validator GenericValidator isBlankOrNull

List of usage examples for org.apache.commons.validator GenericValidator isBlankOrNull

Introduction

In this page you can find the example usage for org.apache.commons.validator GenericValidator isBlankOrNull.

Prototype

public static boolean isBlankOrNull(String value) 

Source Link

Document

Checks if the field isn't null and length of the field is greater than zero not including whitespace.

Usage

From source file:com.aoindustries.website.signup.SignupTechnicalActionHelper.java

public static void setRequestAttributes(ServletContext servletContext, HttpServletRequest request,
        SignupTechnicalForm signupTechnicalForm) throws IOException, SQLException {
    AOServConnector rootConn = SiteSettings.getInstance(servletContext).getRootAOServConnector();

    // Build the list of countries
    List<SignupBusinessActionHelper.CountryOption> countryOptions = SignupBusinessActionHelper
            .getCountryOptions(rootConn);

    // Generate random passwords, keeping the selected password at index 0
    List<String> passwords = new ArrayList<String>(16);
    if (!GenericValidator.isBlankOrNull(signupTechnicalForm.getBaPassword()))
        passwords.add(signupTechnicalForm.getBaPassword());
    while (passwords.size() < 16)
        passwords.add(PasswordGenerator.generatePassword());

    // Store to the request
    request.setAttribute("countryOptions", countryOptions);
    request.setAttribute("passwords", passwords);
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateDate.java

public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {

    String valueString = ValidatorUtils.getValueAsString(bean, field.getProperty());

    String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month"));
    String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day"));

    if (((valueString == null) && (sProperty2 == null) && (sProperty3 == null))
            || ((valueString.length() == 0) && (sProperty2.length() == 0) && (sProperty3.length() == 0))) {
        // errors.add(field.getKey(),Resources.getActionError(request, va,
        // field));
        return true;
    }/* ww w.j a v  a  2 s  .c om*/

    Integer year = null;
    Integer month = null;
    Integer day = null;

    try {
        year = new Integer(valueString);
        month = new Integer(sProperty2);
        day = new Integer(sProperty3);
    } catch (NumberFormatException e) {
        errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        return false;
    }

    if (!GenericValidator.isBlankOrNull(valueString)) {
        if (!Data.validDate(day, month, year) || year == null || month == null || day == null
                || year.intValue() < 1 || month.intValue() < 0 || day.intValue() < 1) {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        }

        return false;
    }

    return true;
}

From source file:com.codeup.movies.validation.AddMovieValidator.java

private void validateTitle() {
    List<String> messages = new ArrayList<>();

    if (GenericValidator.isBlankOrNull(title)) {
        messages.add("Please enter a title");
        errors.put("title", messages);
    }/*  w ww  .  j  a  v a  2s.  c  om*/
}

From source file:de.codecentric.janus.plugin.ci.CIConfiguration.java

public static FormValidation doCheckName(@QueryParameter String value) {
    if (GenericValidator.isBlankOrNull(value)) {
        return FormValidation.error("Please provide a name so that the "
                + "CI system can be identified on the project bootstrap " + "page.");
    }/*from w w  w  .j  a  va 2 s.  c  o  m*/

    return FormValidation.ok();
}

From source file:com.panet.imeta.job.entry.validator.LongValidator.java

public boolean validate(CheckResultSourceInterface source, String propertyName,
        List<CheckResultInterface> remarks, ValidatorContext context) {
    Object result = null;/*from   w  ww.  j a va2  s  .  c o m*/
    String value = null;

    value = getValueAsString(source, propertyName);

    if (GenericValidator.isBlankOrNull(value)) {
        return Boolean.TRUE;
    }

    result = GenericTypeValidator.formatLong(value);

    if (result == null) {
        addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks,
                getLevelOnFail(context, VALIDATOR_NAME));
        return false;
    }
    return true;
}

From source file:com.panet.imeta.job.entry.validator.IntegerValidator.java

public boolean validate(CheckResultSourceInterface source, String propertyName,
        List<CheckResultInterface> remarks, ValidatorContext context) {

    Object result = null;/*  ww w .j a va 2s .  c o m*/
    String value = null;

    value = getValueAsString(source, propertyName);

    if (GenericValidator.isBlankOrNull(value)) {
        return true;
    }

    result = GenericTypeValidator.formatInt(value);

    if (result == null) {
        addFailureRemark(source, propertyName, VALIDATOR_NAME, remarks,
                getLevelOnFail(context, VALIDATOR_NAME));
        return false;
    }
    return true;

}

From source file:com.raven.loginn.service.AccountService.java

public Account findAccountByUserName(String userName) throws Exception {
    if (GenericValidator.isBlankOrNull(userName)) {
        throw new WarningMessageException("Kullanc ad bo olamaz");
    }/*from w w  w.  j ava 2 s.  c  o m*/
    return accountDao.findAccountByUserName(userName);
}

From source file:com.core.validators.CommonValidator.java

/**
 * Checks if the field is required.//www . ja  v a  2  s .  c o  m
 *
 * @return boolean If the field isn't <code>null</code> and
 * has a length greater than zero, <code>true</code> is returned.  
 * Otherwise <code>false</code>.
 */
public static boolean validateRequired(Object bean, Field field) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());

    return !GenericValidator.isBlankOrNull(value);
}

From source file:com.aoindustries.website.clientarea.accounting.AddCreditCardForm.java

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = super.validate(mapping, request);
    if (errors == null)
        errors = new ActionErrors();
    // cardNumber
    String cardNumber = getCardNumber();
    if (GenericValidator.isBlankOrNull(cardNumber))
        errors.add("cardNumber", new ActionMessage("addCreditCardForm.cardNumber.required"));
    else if (!GenericValidator.isCreditCard(CreditCard.numbersOnly(cardNumber)))
        errors.add("cardNumber", new ActionMessage("addCreditCardForm.cardNumber.invalid"));
    // expirationMonth and expirationYear
    String expirationMonth = getExpirationMonth();
    String expirationYear = getExpirationYear();
    if (GenericValidator.isBlankOrNull(expirationMonth) || GenericValidator.isBlankOrNull(expirationYear))
        errors.add("expirationDate", new ActionMessage("addCreditCardForm.expirationDate.required"));
    // cardCode/*w  ww.ja  v a  2s.co m*/
    String cardCode = getCardCode();
    if (GenericValidator.isBlankOrNull(cardCode))
        errors.add("cardCode", new ActionMessage("addCreditCardForm.cardCode.required"));
    else {
        try {
            CreditCard.validateCardCode(cardCode);
        } catch (LocalizedIllegalArgumentException e) {
            errors.add("cardCode", new ActionMessage(e.getLocalizedMessage(), false));
        }
    }
    return errors;
}

From source file:br.com.blackhouse.internet.controller.LoginController.java

/**
 * Returns true if user exist else false
 * //from   www .  j av a2 s . c om
 * @param userName
 *            user name
 * @param password
 *            user password
 * @return true if user exist else false
 */
@Transactional
public Usuario checkLogin(String userName, String password) {
    if (GenericValidator.isBlankOrNull(userName) || GenericValidator.isBlankOrNull(password)) {
        logger.log(Level.WARNING, "UserName and Password is null");

        return null;
    }

    Query query = entityManager.createQuery(
            "select p from Usuario p where  " + "p.userName=:userName and " + "p.password=:password");

    query.setParameter("userName", userName);
    query.setParameter("password", password);

    Usuario value = null;
    try {
        value = (Usuario) query.getSingleResult();
        value.setLastLoginDate(GregorianCalendar.getInstance().getTime());
    } catch (Exception e) {
        return null;
    }

    return value;
}