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.util.StringUtility.java

/**
 * This method breaks a single String into a list of Strings. The string is
 * split after every 500 characters.//from w  w w  .  j a v  a 2  s  . c  o m
 * 
 * @param string The string to be split
 */
public static final List<String> convertStringToList(String string) {
    int length = StringUtils.length(string);
    /* Calculate the number of times the string is to be split */
    int numOfSplits = length / DATASTORE_ALLOWED_LENGTH_FOR_STRING;
    if (length % DATASTORE_ALLOWED_LENGTH_FOR_STRING > 0) {
        numOfSplits += 1;
    }
    List<String> strings = null;
    if (numOfSplits > 0) {
        strings = new ArrayList<String>();
        int offset = 0;
        for (int i = 0; i < numOfSplits; i++) {
            strings.add(StringUtils.substring(string, offset, offset + DATASTORE_ALLOWED_LENGTH_FOR_STRING));
            offset += DATASTORE_ALLOWED_LENGTH_FOR_STRING;
        }
    }
    return strings;
}

From source file:com.tek271.reverseProxy.utils.TextTools.java

/** remove chars less than 32 and replace with space */
public static String removeControlChars(String text) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0, n = StringUtils.length(text); i < n; i++) {
        char ch = text.charAt(i);
        if (ch < ' ')
            ch = ' ';
        sb.append(ch);//from w w  w.  j ava  2 s .  com
    }
    return sb.toString();
}

From source file:com.hangum.tadpole.commons.libs.core.utils.ValidChecker.java

/**
 * //  www .j av  a  2 s.co  m
 * 
 * @param passwd
 * @return
 */
public static boolean isSimplePasswordChecker(String passwd) {
    if (StringUtils.length(passwd) < 5) {
        return false;
    }
    return true;
}

From source file:hydrograph.ui.common.util.ConvertHexValues.java

/**
 * This method converts input hex-value into its equivalent character.
 * /*  w  w w.  ja va2 s  . c o  m*/
 * @param input
 *            , hex-value e.g. \x21 for !
 * @return string, if given input is valid hex-value then its equivalent character is returned else input is
 *         returned as it is.
 */
public static String parseHex(String input) {
    final int NO_OF_DIGITS = 2;

    if (StringUtils.isBlank(input) || StringUtils.length(input) < NO_OF_DIGITS + 2)
        return input;

    // Added support for \\t
    if (input.contains("\\t")) {
        input = input.replace("\\t", "\\x09");
    }

    String[] tokens = input.split("\\\\x");
    String hex;
    String temp;
    boolean startsWithHex = input.startsWith("\\x");

    for (int counter = 0; counter < tokens.length; counter++) {

        if (counter == 0 && !startsWithHex)
            continue;

        if (tokens[counter].equals(""))
            continue;

        temp = tokens[counter];
        hex = temp.substring(0, NO_OF_DIGITS);
        temp = temp.substring(NO_OF_DIGITS, temp.length());
        try {
            tokens[counter] = hexToChar(hex) + temp;
        } catch (NumberFormatException numberFormatException) {
            tokens[counter] = hex + temp;
        }
    }

    String result = "";
    for (String token : tokens) {
        result = result + token;
    }

    return result;

}

From source file:com.smartitengineering.util.opensearch.impl.Utils.java

public static void checkMaxLength(String name, int maxLength, String testString, boolean trim) {
    final String finalTestString;
    if (trim) {//from   w  ww. ja  va2s .  co  m
        finalTestString = StringUtils.trim(testString);
    } else {
        finalTestString = testString;
    }
    if (StringUtils.length(finalTestString) > maxLength) {
        throw new IllegalArgumentException(new StringBuilder(name).append(" must be fewer or equal to ")
                .append(maxLength).append(" characters").toString());
    }
}

From source file:de.hybris.platform.chinesetaxinvoiceaddon.forms.validation.TaxInvoiceValidator.java

protected static void validateInvoiceName(TaxInvoiceForm invoiceForm, final int maxFieldLength,
        final Errors errors) {

    if (StringUtils.isNotBlank(invoiceForm.getRecipientType())
            && invoiceForm.getRecipientType().equals(InvoiceRecipientType.UNIT.getCode())) {
        String recipient = invoiceForm.getRecipient();
        if (recipient == null || StringUtils.isEmpty(recipient)
                || (StringUtils.length(recipient) > maxFieldLength)) {
            errors.rejectValue(InvoiceField.RECIPIENT.getFieldKey(), InvoiceField.RECIPIENT.getErrorKey());
        }/*from  ww  w.ja va 2s  .  c o m*/
    }
}

From source file:com.smartitengineering.util.opensearch.impl.Utils.java

public static void checkMinLength(String name, int minLength, String testString, boolean trim) {
    final String finalTestString;
    if (trim) {// ww  w  . ja v a 2s  . com
        finalTestString = StringUtils.trim(testString);
    } else {
        finalTestString = testString;
    }
    if (StringUtils.length(finalTestString) < minLength) {
        throw new IllegalArgumentException(new StringBuilder(name).append(" must not be fewer than ")
                .append(minLength).append(" characters").toString());
    }
}

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

@Override
public void validate(final Object object, final Errors errors) {
    final ReviewForm reviewForm = (ReviewForm) object;
    final String headLine = reviewForm.getHeadline();
    final String comment = reviewForm.getComment();
    final Double rating = reviewForm.getRating();

    if (StringUtils.isEmpty(headLine) || StringUtils.length(headLine) > 255) {
        errors.rejectValue("headline", "review.headline.invalid");
    }/*  w w w .  j  ava  2s.  c  o  m*/

    if (StringUtils.isEmpty(comment) || StringUtils.length(comment) > 4000) {
        errors.rejectValue("comment", "review.comment.invalid");
    }

    if (rating == null || rating.doubleValue() < 1 || rating.doubleValue() > 5) {
        errors.rejectValue("rating", "review.rating.invalid");
    }
}

From source file:gov.nih.nci.cabig.caaers.utils.pdf.MedwatchUtils.java

public static int possibleElements(NodeList nodes, int n, String commaSeperatedXPath) {

    if (nodes == null || nodes.getLength() == 0)
        return 1;
    String[] xpath = StringUtils.isEmpty(commaSeperatedXPath) ? new String[] { "." }
            : commaSeperatedXPath.split(",");
    int l = 0;/*from w  ww . ja  v  a2  s .  com*/
    int k = 1;
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        for (int j = 0; j < xpath.length; j++) {
            String s = evalXPathsOnNode(node, xpath[j]);
            l += StringUtils.length(s);
        }
        if (l >= n)
            return k;

        k++;
    }

    return k;
}

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

@Override
public void validate(final Object object, final Errors errors) {
    final ReviewForm reviewForm = (ReviewForm) object;
    final String headLine = reviewForm.getHeadline();
    final String comment = reviewForm.getComment();
    final Double rating = reviewForm.getRating();

    if (StringUtils.isEmpty(headLine) || StringUtils.length(headLine) > 255) {
        errors.rejectValue("headline", "review.headline.invalid");
    }/*from  ww w.  ja va  2 s  .  c om*/

    if (StringUtils.isEmpty(comment) || StringUtils.length(comment) > 4000) {
        errors.rejectValue("comment", "review.comment.invalid");
    }

    if (rating == null || rating.doubleValue() < 0.5 || rating.doubleValue() > 5) {
        errors.rejectValue("rating", "review.rating.invalid");
    }
}