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.google.ie.common.validation.CommentValidator.java

public void validateIdeaComments(Object object, Errors errors) {
    IdeaComment ideaComment = (IdeaComment) object;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, IDEA_KEY, IdeaExchangeConstants.Messages.REQUIRED_FIELD);
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, TEXT, IdeaExchangeConstants.Messages.REQUIRED_FIELD);
    if (StringUtils.length(ideaComment.getText()) > COMMENT_LENGTH) {
        errors.rejectValue(TEXT, IdeaExchangeErrorCodes.COMMENT_LENGTH_EXCEEDS,
                IdeaExchangeConstants.Messages.COMMENT_LENGTH_EXCEEDS);
    }// w ww  . jav  a 2s.  c  om

    if (log.isDebugEnabled()) {
        if (errors.hasErrors()) {
            log.debug("Validator found " + errors.getErrorCount() + " errors");
            for (Iterator<FieldError> iterator = errors.getFieldErrors().iterator(); iterator.hasNext();) {
                FieldError fieldError = iterator.next();
                log.debug("Error found in field: " + fieldError.getField() + " Message :"
                        + fieldError.getDefaultMessage());
            }
        } else {
            log.debug("Validator found no errors");
        }

    }
}

From source file:com.seitenbau.jenkins.plugins.dynamicparameter.BaseParameterDefinition.java

/**
 * Constructor./* www.ja  va2s. c o  m*/
 * @param name parameter name
 * @param description parameter description
 * @param uuid UUID of the parameter definition
 * @param remote flag showing if the script should be executed remotely
 */
protected BaseParameterDefinition(String name, String description, String uuid, Boolean remote) {
    super(name, description);
    _remote = remote;

    if (StringUtils.length(uuid) == 0) {
        _uuid = UUID.randomUUID();
    } else {
        _uuid = UUID.fromString(uuid);
    }
}

From source file:eu.annocultor.converter.ConverterHandlerDataObjects.java

static Attributes extractLang(Value value) {
    if (value != null && value instanceof LiteralValue) {
        String lang = ((LiteralValue) value).getLang();
        if (StringUtils.length(lang) == 2) {
            return new AttributesProxy(lang);
        }/*  w  ww  .  j  a v a  2  s  . co m*/
    }
    return null;
}

From source file:hr.fer.zemris.vhdllab.entity.ClientLog.java

@Override
public String toString() {
    return new ToStringBuilder(this).appendSuper(super.toString()).append("createdOn", createdOn)
            .append("dataLength", StringUtils.length(data)).toString();
}

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

protected static void validateStringField(final String addressField, final AddressField fieldType,
        final int maxFieldLength, final Errors errors) {
    if (addressField == null || StringUtils.isEmpty(addressField)
            || (StringUtils.length(addressField) > maxFieldLength)) {
        errors.rejectValue(fieldType.getFieldKey(), fieldType.getErrorKey());
    }//from w  ww  .ja va 2  s .  co  m
}

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

protected void validatePassword(final Errors errors, final String pwd) {
    if (StringUtils.isEmpty(pwd)) {
        errors.rejectValue("pwd", "register.pwd.invalid");
    } else if (StringUtils.length(pwd) < 6 || StringUtils.length(pwd) > 255) {
        errors.rejectValue("pwd", "register.pwd.invalid");
    }// w  w w .  j  a v  a 2  s.co m
}

From source file:com.contactlab.addon.form.validation.SubscriptionValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final EmailSubscriptionForm subscriptionForm = (EmailSubscriptionForm) object;

    final String firstName = subscriptionForm.getFirstName();
    final String lastName = subscriptionForm.getLastName();
    final String email = subscriptionForm.getEmail();
    final List<String> selectedCampaigns = subscriptionForm.getSelectedCampaigns();
    final boolean privacy = subscriptionForm.isPrivacy();

    /*/*from  w  w w .  j  a v a 2s .  c o  m*/
     * Fields actually unused
     */
    //final String emailConfirmation = subscriptionForm.getEmailConfirmation();
    // final String title = profileForm.getTitleCode();
    // final String middleName = profileForm.getMiddleName();
    // final String birthDate = profileForm.getBirthDate();
    // final String gender = profileForm.getGender();
    // final String address = profileForm.getAddress();
    // final String city = profileForm.getCity();
    //   final String postalCode = profileForm.getPostalCode();
    //   final String district = profileForm.getDistrict();
    //   final String region = profileForm.getRegion();
    //   final String country = profileForm.getCountry();
    //   final String phone = profileForm.getPhone();
    // final String cellPhone = profileForm.getCellPhone();
    //   final String fax = profileForm.getFax();
    //   final String company = profileForm.getCompany();

    if (!privacy) {
        errors.rejectValue("privacy", "newsletter.privacy.invalid");
    }

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

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

    if (StringUtils.isEmpty(email)) {
        errors.rejectValue("email", "newsletter.email.invalid");
    } else if (StringUtils.length(email) > 255 || !validateEmailAddress(email)) {
        errors.rejectValue("email", "newsletter.email.invalid");
    }

    if (selectedCampaigns == null || selectedCampaigns.isEmpty()) {
        errors.rejectValue("selectedCampaigns", "newsletter.selectedCampaigns.invalid");
    }

}

From source file:com.hangum.tadpole.preference.ui.AmazonPreferencePage.java

@Override
public boolean performOk() {
    String txtAccessKey = textAccessKey.getText();
    String txtSecretKey = textSecretKey.getText();

    if (StringUtils.length(txtAccessKey) > 10 && StringUtils.length(txtSecretKey) > 10) {
        try {/*  w  w  w.ja v a2s  .c  o  m*/
            updateEncriptInfo(PreferenceDefine.AMAZON_ACCESS_NAME, txtAccessKey);
            updateEncriptInfo(PreferenceDefine.AMAZON_SECRET_NAME, txtSecretKey);

        } catch (Exception e) {
            logger.error("GeneralPreference saveing", e); //$NON-NLS-1$

            MessageDialog.openError(getShell(), CommonMessages.get().Error,
                    Messages.get().GeneralPreferencePage_2 + e.getMessage()); //$NON-NLS-1$
            return false;
        }
    }

    return super.performOk();
}

From source file:com.manydesigns.elements.fields.AbstractTextField.java

public boolean validate() {
    if (mode.isView(insertable, updatable) || (mode.isBulk() && !bulkChecked)) {
        return true;
    }/*from www  .  j a  v a  2 s  .c o  m*/

    boolean result = true;
    if (required && StringUtils.isBlank(stringValue)) {
        errors.add(getText("elements.error.field.required"));
        result = false;
    }
    if (maxLength != null && StringUtils.length(stringValue) > maxLength) {
        errors.add(getText("elements.error.field.length.exceeded", maxLength));
        result = false;
    }
    return result;
}

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

protected void validateEmail(final Errors errors, final String email) {
    if (StringUtils.isEmpty(email)) {
        errors.rejectValue("email", "register.email.invalid");
    } else if (StringUtils.length(email) > 255 || !validateEmailAddress(email)) {
        errors.rejectValue("email", "register.email.invalid");
    }//from   w  w  w.java  2s. c  o m
}