Example usage for org.apache.commons.lang StringUtils length

List of usage examples for org.apache.commons.lang StringUtils length

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils length.

Prototype

public static int length(String str) 

Source Link

Document

Gets a String's length or 0 if the String is null.

Usage

From source file:com.pedra.storefront.forms.validation.GuestValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final GuestForm guestForm = (GuestForm) object;
    final String email = guestForm.getEmail();

    if (StringUtils.isEmpty(email)) {
        errors.rejectValue("email", "profile.email.invalid");
    } else if (StringUtils.length(email) > 255 || !Pattern.matches(EMAIL_REGEX, email)) {
        errors.rejectValue("email", "profile.email.invalid");
    }/*from  w  w  w  .j  av a2  s .  com*/
}

From source file:com.pedra.storefront.forms.validation.ProfileValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final UpdateProfileForm profileForm = (UpdateProfileForm) object;
    final String title = profileForm.getTitleCode();
    final String firstName = profileForm.getFirstName();
    final String lastName = profileForm.getLastName();

    if (StringUtils.isEmpty(title)) {
        errors.rejectValue("titleCode", "profile.title.invalid");
    } else if (StringUtils.length(title) > 255) {
        errors.rejectValue("titleCode", "profile.title.invalid");
    }//from w w w . ja v  a 2  s . c o  m

    if (StringUtils.isEmpty(firstName)) {
        errors.rejectValue("firstName", "profile.firstName.invalid");
    } else if (StringUtils.length(firstName) > 255) {
        errors.rejectValue("firstName", "profile.firstName.invalid");
    }

    if (StringUtils.isEmpty(lastName)) {
        errors.rejectValue("lastName", "profile.lastName.invalid");
    } else if (StringUtils.length(lastName) > 255) {
        errors.rejectValue("lastName", "profile.lastName.invalid");
    }
}

From source file:net.sourceforge.atunes.kernel.modules.pattern.ArtistFirstCharPattern.java

@Override
public String getCDMetadataStringValue(final CDMetadata metadata, final int trackNumber) {
    String artist = metadata.getArtist(trackNumber);
    return StringUtils.length(artist) >= 1 ? artist.substring(0, 1) : null;
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.forms.validation.GuestValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final GuestForm guestForm = (GuestForm) object;
    final String email = guestForm.getEmail();

    if (StringUtils.isEmpty(email)) {
        errors.rejectValue("email", "profile.email.invalid");
    } else if (StringUtils.length(email) > 255 || !EMAIL_REGEX.matcher(email).matches()) {
        errors.rejectValue("email", "profile.email.invalid");
    }// w  w w. ja  va 2  s  .  c o  m
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.forms.validation.ProfileValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final UpdateProfileForm profileForm = (UpdateProfileForm) object;
    final String title = profileForm.getTitleCode();
    final String firstName = profileForm.getFirstName();
    final String lastName = profileForm.getLastName();

    if (StringUtils.isEmpty(title)) {
        errors.rejectValue("titleCode", "profile.title.invalid");
    } else if (StringUtils.length(title) > 255) {
        errors.rejectValue("titleCode", "profile.title.invalid");
    }/*from   ww  w. jav  a  2s . co  m*/

    if (StringUtils.isBlank(firstName)) {
        errors.rejectValue("firstName", "profile.firstName.invalid");
    } else if (StringUtils.length(firstName) > 255) {
        errors.rejectValue("firstName", "profile.firstName.invalid");
    }

    if (StringUtils.isBlank(lastName)) {
        errors.rejectValue("lastName", "profile.lastName.invalid");
    } else if (StringUtils.length(lastName) > 255) {
        errors.rejectValue("lastName", "profile.lastName.invalid");
    }
}

From source file:com.store.rau.storefront.forms.validation.ProfileValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final UpdateProfileForm profileForm = (UpdateProfileForm) object;
    final String title = profileForm.getTitleCode();
    final String firstName = profileForm.getFirstName();
    final String lastName = profileForm.getLastName();
    final String mobileNumber = profileForm.getMobileNumber();

    if (StringUtils.isEmpty(title)) {
        errors.rejectValue("titleCode", "profile.title.invalid");
    } else if (StringUtils.length(title) > 255) {
        errors.rejectValue("titleCode", "profile.title.invalid");
    }//ww  w. j a  va  2s  . co  m

    if (StringUtils.isBlank(firstName)) {
        errors.rejectValue("firstName", "profile.firstName.invalid");
    } else if (StringUtils.length(firstName) > 255) {
        errors.rejectValue("firstName", "profile.firstName.invalid");
    }

    if (StringUtils.isBlank(lastName)) {
        errors.rejectValue("lastName", "profile.lastName.invalid");
    } else if (StringUtils.length(lastName) > 255) {
        errors.rejectValue("lastName", "profile.lastName.invalid");
    }
    if (StringUtils.isBlank(mobileNumber)) {
        errors.rejectValue("mobileNumber", "profile.mobileNumber.invalid");
    } else if (StringUtils.length(mobileNumber) > 10) {
        errors.rejectValue("mobileNumber", "profile.mobileNumber.invalid");
    }
}

From source file:com.pedra.storefront.forms.validation.EmailValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final UpdateEmailForm updateEmailForm = (UpdateEmailForm) object;
    final String email = updateEmailForm.getEmail();
    final String chkEmail = updateEmailForm.getChkEmail();
    final String password = updateEmailForm.getPassword();

    if (StringUtils.isEmpty(email)) {
        errors.rejectValue("email", "profile.email.invalid");
    } else if (StringUtils.length(email) > 255 || !Pattern.matches(EMAIL_REGEX, email)) {
        errors.rejectValue("email", "profile.email.invalid");
    }/*from ww w  .java 2s  .  c o  m*/

    if (StringUtils.isEmpty(chkEmail)) {
        errors.rejectValue("chkEmail", "profile.checkEmail.invalid");
    }

    if (StringUtils.isEmpty(password)) {
        errors.rejectValue("password", "profile.pwd.invalid");
    }
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.forms.validation.SaveCartFormValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final SaveCartForm saveCartForm = (SaveCartForm) object;
    final String name = saveCartForm.getName();
    final String description = saveCartForm.getDescription();

    if (StringUtils.isBlank(name)) {
        errors.rejectValue("name", "basket.save.cart.validation.name.notBlank");
        return;//w  ww .j  a va  2  s .c  o m
    }

    if (!StringUtils.isAlphanumericSpace(name)) {
        errors.rejectValue("name", "basket.save.cart.validation.name.charset");
        return;
    }

    if (StringUtils.length(name) > 255) {
        errors.rejectValue("name", "basket.save.cart.validation.name.size");
        return;
    }

    if (StringUtils.length(description) > 255) {
        errors.rejectValue("description", "basket.save.cart.validation.description.size");
        return;
    }
}

From source file:com.pedra.storefront.forms.validation.PasswordValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final UpdatePasswordForm passwordForm = (UpdatePasswordForm) object;
    final String currPasswd = passwordForm.getCurrentPassword();
    final String newPasswd = passwordForm.getNewPassword();
    final String checkPasswd = passwordForm.getCheckNewPassword();

    if (StringUtils.isEmpty(currPasswd)) {
        errors.rejectValue("currentPassword", "profile.currentPassword.invalid");
    }/*from ww  w .  j a  v a  2  s  . co  m*/

    if (StringUtils.isEmpty(newPasswd)) {
        errors.rejectValue("newPassword", "updatePwd.pwd.invalid");
    } else if (StringUtils.length(newPasswd) < 6 || StringUtils.length(newPasswd) > 255) {
        errors.rejectValue("newPassword", "updatePwd.pwd.invalid");
    }

    if (StringUtils.isEmpty(checkPasswd)) {
        errors.rejectValue("checkNewPassword", "updatePwd.pwd.invalid");
    } else if (StringUtils.length(checkPasswd) < 6 || StringUtils.length(checkPasswd) > 255) {
        errors.rejectValue("checkNewPassword", "updatePwd.pwd.invalid");
    }
}

From source file:com.pedra.storefront.forms.validation.GuestRegisterValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final GuestRegisterForm guestRegisterForm = (GuestRegisterForm) object;
    final String newPasswd = guestRegisterForm.getPwd();
    final String checkPasswd = guestRegisterForm.getCheckPwd();

    if (StringUtils.isNotEmpty(newPasswd) && StringUtils.isNotEmpty(checkPasswd)
            && !StringUtils.equals(newPasswd, checkPasswd)) {
        errors.rejectValue("checkPwd", "validation.checkPwd.equals");
    } else {//from   w w w  .j a  va 2s . co m
        if (StringUtils.isEmpty(newPasswd)) {
            errors.rejectValue("pwd", "register.pwd.invalid");
        } else if (StringUtils.length(newPasswd) < 6 || StringUtils.length(newPasswd) > 255) {
            errors.rejectValue("pwd", "register.pwd.invalid");
        }

        if (StringUtils.isEmpty(checkPasswd)) {
            errors.rejectValue("checkPwd", "register.checkPwd.invalid");
        } else if (StringUtils.length(checkPasswd) < 6 || StringUtils.length(checkPasswd) > 255) {
            errors.rejectValue("checkPwd", "register.checkPwd.invalid");
        }
    }
}