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:es.uvigo.ei.sing.gc.utils.Validator.java

public static boolean isNotEmpty(String text) {
    return !GenericValidator.isBlankOrNull(text);
}

From source file:jp.primecloud.auto.api.util.ValidateUtil.java

/**
 *
 * ?/*from   w  ww.java  2  s . c o  m*/
 *
 * @param value ??
 * @param code ??
 * @param params ??
 */
public static void required(String value, String code, Object[] params) {
    if (GenericValidator.isBlankOrNull(value)) {
        throw new AutoApplicationException(code, params);
    }
}

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

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

    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String sProperty2 = field.getVarValue("secondProperty");
    String value2 = ValidatorUtils.getValueAsString(bean, sProperty2);

    if (!GenericValidator.isBlankOrNull(value)) {
        try {//  ww  w  .  j ava2 s .  c o m
            if (!value.equals(value2)) {
                errors.add(field.getKey(), new ActionMessage("errors.different.passwords"));
                return false;
            }
        } catch (Exception e) {
            errors.add(field.getKey(), new ActionMessage("errors.different.passwords"));
            return false;
        }
    }

    return true;
}

From source file:com.draagon.meta.validator.NumericValidator.java

/**
 * Validates the value of the field in the specified object
 */// w w  w .  j a  v a 2 s.c  om
public void validate(Object object, Object value)
//throws MetaException
{
    String val = (value == null) ? null : value.toString();

    if (!GenericValidator.isBlankOrNull(val)) {

        for (int i = 0; i < val.length(); i++) {
            if (val.charAt(i) < '0' || val.charAt(i) > '9')
                throw new InvalidValueException(getMessage("The value is not a valid number"));
        }
    }
}

From source file:bookproject.web.action.SavePublisherAction.java

@Override
public void process(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String publisherName = request.getParameter("name");
    String address = request.getParameter("address");
    String email = request.getParameter("email");

    if (!GenericValidator.isBlankOrNull(publisherName) && !GenericValidator.isBlankOrNull(address)
            && GenericValidator.isEmail(email)) {

        Publisher publisher = new Publisher();
        publisher.setName(publisherName);
        publisher.setAddress(address);/*from ww  w  .  ja va2s  .  c om*/
        publisher.setEmail(email);
        boolean success = dbHelper.savePublisher(publisher);
        //            page = WebConstants.PAGE_PUBLISHER_LIST;
        page = "cs?action=showPublisherList";
        forward = false;
    } else {
        this.errorList.clear();
        this.errorList.add("Name, address and email can not empty");
        request.setAttribute(WebConstants.ATTR_ERROR_LIST, errorList);
        page = WebConstants.PAGE_ADD_PUBLISHER;
        forward = true;
    }

}

From source file:com.sapienter.jbilling.server.user.validator.AlphaNumValidator.java

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

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

    if (!GenericValidator.isBlankOrNull(value)) {
        try {/*from www  . java2 s. c  o m*/
            if (!basicValidation(value)) {
                errors.add(field.getKey(), Resources.getActionError(request, va, field));

                return false;
            }
        } catch (Exception e) {
            errors.add(field.getKey(), Resources.getActionError(request, va, field));
            return false;
        }
    }
    return true;
}

From source file:com.codeup.auth.application.authentication.LoginInput.java

private void validatePassword(String password) {
    ArrayList<String> messages = new ArrayList<>();

    if (GenericValidator.isBlankOrNull(password))
        messages.add("Enter your password");
    if (password != null && password.length() < 8)
        messages.add("Password must be at least 8 characters long");

    if (messages.size() > 0)
        this.messages.put("password", messages);
}

From source file:com.draagon.meta.validator.RequiredValidator.java

/**
 * Validates the value of the field in the specified object
 *//* w w w  . ja v a 2  s.  co  m*/
public void validate(Object object, Object value)
//throws MetaException
{
    String msg = getMessage("A value is required");
    String val = (value == null) ? null : value.toString();

    if (GenericValidator.isBlankOrNull(val)) {
        throw new InvalidValueException(msg);
    }
}

From source file:com.draagon.meta.validator.MaskValidator.java

/**
 * Validates the value of the field in the specified object
 *//*  w  w w.j  av a2 s  . c o  m*/
public void validate(Object object, Object value)
//throws MetaException
{
    String mask = (String) getAttribute(ATTR_MASK);
    String msg = getMessage("Invalid value format");

    String val = (value == null) ? null : value.toString();

    if (!GenericValidator.isBlankOrNull(val) && !GenericValidator.matchRegexp(val, mask)) {
        throw new InvalidValueException(msg);
    }
}

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

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

    String inputString = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String lowerValueString = field.getVarValue("value");

    if ((inputString == null) || (inputString.length() == 0)) {
        return true;
    }//  w ww.j a v a  2 s  .c  o  m
    Double input = null;
    Double lowerValue = null;

    try {
        input = new Double(inputString);
        lowerValue = new Double(lowerValueString);
    } catch (NumberFormatException e) {
        errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        return false;
    }

    if (!GenericValidator.isBlankOrNull(inputString)) {
        if (input.floatValue() <= lowerValue.floatValue()) {
            errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        }
        return false;
    }

    return true;
}