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

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

Introduction

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

Prototype

public static String stripToNull(String str) 

Source Link

Document

Strips whitespace from the start and end of a String returning null if the String is empty ("") after the strip.

Usage

From source file:ru.org.linux.tag.TagService.java

/**
 *  ? .   /*from   w w w . j a  v a 2s.  co m*/
 *
 * @param tags ??   ?
 * @return ?? 
 */
public ImmutableList<String> parseSanitizeTags(String tags) {
    if (tags == null) {
        return ImmutableList.of();
    }

    Set<String> tagSet = new HashSet<String>();

    //  ??   ?
    tags = tags.replaceAll("\\|", ",");
    String[] tagsArr = tags.split(",");

    if (tagsArr.length == 0) {
        return ImmutableList.of();
    }

    for (String aTagsArr : tagsArr) {
        String tag = StringUtils.stripToNull(aTagsArr.toLowerCase());
        //   - ?
        if (tag == null) {
            continue;
        }

        //  :  //,  ??, ?, ?  <>
        if (isGoodTag(tag)) {
            tagSet.add(tag);
        }
    }

    return ImmutableList.copyOf(tagSet);
}

From source file:ru.org.linux.topic.TagDao.java

public static ImmutableList<String> parseSanitizeTags(String tags) {
    if (tags == null) {
        return ImmutableList.of();
    }/*from  w ww .  j a v a 2 s . c  om*/

    Set<String> tagSet = new HashSet<String>();

    //  ??   ?
    tags = tags.replaceAll("\\|", ",");
    String[] tagsArr = tags.split(",");

    if (tagsArr.length == 0) {
        return ImmutableList.of();
    }

    for (String aTagsArr : tagsArr) {
        String tag = StringUtils.stripToNull(aTagsArr.toLowerCase());
        //   - ?
        if (tag == null) {
            continue;
        }

        //  :  //,  ??, ?, ?  <>
        if (isGoodTag(tag)) {
            tagSet.add(tag);
        }
    }

    return ImmutableList.copyOf(tagSet);
}

From source file:ru.org.linux.topic.TopicTagService.java

/**
 *  ? . Error  //w  ww  .j  av  a2 s .c  om
 *
 * @param tags   ??   ?
 * @param errors ?? ?   ( 'tags')
 * @return ?? 
 */
public ImmutableList<String> parseTags(String tags, Errors errors) {
    Set<String> tagSet = new HashSet<String>();

    //  ??   ?
    tags = tags.replaceAll("\\|", ",");
    String[] tagsArr = tags.split(",");

    if (tagsArr.length == 0) {
        return ImmutableList.of();
    }

    for (String aTagsArr : tagsArr) {
        String tag = StringUtils.stripToNull(aTagsArr.toLowerCase());
        //   - ?
        if (tag == null) {
            continue;
        }

        //  :  //,  ??, ?, ?  <>
        if (tag.length() > TagService.MAX_TAG_LENGTH) {
            errors.rejectValue("tags", null, "  : '" + tag
                    + "\' (? " + TagService.MAX_TAG_LENGTH + " ?)");
        } else if (!TagService.isGoodTag(tag)) {
            errors.rejectValue("tags", null, "? : '" + tag + '\'');
        }

        tagSet.add(tag);
    }

    if (tagSet.size() > MAX_TAGS_PER_TOPIC) {
        errors.rejectValue("tags", null,
                "   (? " + MAX_TAGS_PER_TOPIC + ')');
    }

    return ImmutableList.copyOf(tagSet);
}

From source file:ru.org.linux.user.UserTagService.java

/**
 *  ? .// w w  w.j  a va2s.  c  om
 *
 * @param tags ??   ?
 * @return ?? 
 */
public ImmutableList<String> parseTags(String tags, Errors errors) {
    Set<String> tagSet = new HashSet<String>();

    //  ???   ?
    tags = tags.replaceAll("\\|", ",");
    String[] tagsArr = tags.split(",");

    if (tagsArr.length == 0) {
        return ImmutableList.of();
    }

    for (String aTagsArr : tagsArr) {
        String tag = StringUtils.stripToNull(aTagsArr);
        //   - ?
        if (tag == null) {
            continue;
        }

        //  :  //,  ??, ?, ?  <>
        if (!TagService.isGoodTag(tag)) {
            errors.reject("? : '" + tag + '\'');
            continue;
        }

        tagSet.add(tag);
    }

    return ImmutableList.copyOf(tagSet);
}

From source file:util.POIUtils.java

/**
 * Gets the string value of a cell./*  ww w  . ja  v  a2  s  .co  m*/
 *
 * @param cell the cell to get the string value of
 * @return the string value of the specified cell
 */
private static String getStringValue(Cell cell) {

    if (cell != null) {
        switch (cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:
            cell.setCellType(Cell.CELL_TYPE_NUMERIC);
            return formatNumber(cell.getNumericCellValue());
        case Cell.CELL_TYPE_BOOLEAN:
            return Boolean.toString(cell.getBooleanCellValue());
        default:
            return StringUtils.stripToNull(cell.getRichStringCellValue().getString());
        }
    }
    return null;
}