Java Code Examples for org.apache.commons.lang.StringUtils#containsNone()

The following examples show how to use org.apache.commons.lang.StringUtils#containsNone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringEscapeUtils.java    From ymate-platform-v2 with Apache License 2.0 6 votes vote down vote up
public static String escapeCsv(String str) {
    if (StringUtils.containsNone(str, CSV_SEARCH_CHARS)) {
        if (str != null) {
            return str;
        }
        return null;
    }
    StringBuilder _out = new StringBuilder();
    _out.append(CSV_QUOTE);
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (c == CSV_QUOTE) {
            _out.append(CSV_QUOTE);
        }
        _out.append(c);
    }
    return _out.append(CSV_QUOTE).toString();
}
 
Example 2
Source File: RepomdWriter.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes all control characters from passed in String.
 * @param pkgId package id
 * @param input char input
 * @return sanitized string
 */
protected static String sanitize(Long pkgId, String input) {
    if (StringUtils.containsNone(input, CONTROL_CHARS)) {
        return input;
    }
    if (log.isDebugEnabled()) {
        log.debug("Package " + pkgId +
                " metadata contains control chars, cleanup required: " + input);
    }
    return StringUtils.replaceChars(input, CONTROL_CHARS, CONTROL_CHARS_REPLACEMENT);
}
 
Example 3
Source File: BaseDao.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * If the search string starts with "'" then the searchString will be returned without leading "'". If the search string consists only of
 * alphanumeric characters and allowed chars and spaces the wild card character '*' will be appended for enable ...* search. Otherwise the
 * searchString itself will be returned.
 * @param searchString
 * @param andSearch If true then all terms must match (AND search), otherwise OR will used (default)
 * @see #ALLOWED_CHARS
 * @see #ALLOWED_BEGINNING_CHARS
 * @see #ESCAPE_CHARS
 * @return The modified search string or the original one if no modification was done.
 */
public static String modifySearchString(final String searchString, final boolean andSearch)
{
  if (searchString == null) {
    return "";
  }
  if (searchString.startsWith("'") == true) {
    return searchString.substring(1);
  }
  for (int i = 0; i < searchString.length(); i++) {
    final char ch = searchString.charAt(i);
    if (Character.isLetterOrDigit(ch) == false && Character.isWhitespace(ch) == false) {
      final String allowed = (i == 0) ? ALLOWED_BEGINNING_CHARS : ALLOWED_CHARS;
      if (allowed.indexOf(ch) < 0) {
        return searchString;
      }
    }
  }
  final String[] tokens = StringUtils.split(searchString, ' ');
  final StringBuffer buf = new StringBuffer();
  boolean first = true;
  for (final String token : tokens) {
    if (first == true) {
      first = false;
    } else {
      buf.append(" ");
    }
    if (ArrayUtils.contains(luceneReservedWords, token) == false) {
      final String modified = modifySearchToken(token);
      if (tokens.length > 1 && andSearch == true && StringUtils.containsNone(modified, ESCAPE_CHARS) == true) {
        buf.append("+");
      }
      buf.append(modified);
      if (modified.endsWith("*") == false && StringUtils.containsNone(modified, ESCAPE_CHARS) == true) {
        if (andSearch == false || tokens.length > 1) {
          // Don't append '*' if used by SearchForm and only one token is given. It's will be appended automatically by BaseDao before the
          // search is executed.
          buf.append('*');
        }
      }
    } else {
      buf.append(token);
    }
  }
  return buf.toString();
}
 
Example 4
Source File: WebUtil.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
    * <p>
    * This helper append the parameter deliminator for a url.
    * </p>
    * It is using a null safe String util method to checkup the url String and append proper deliminator if necessary.
    *
    * @param url
    *            the url needs to append deliminator.
    * @return target url with the deliminator;
    */
   public static String appendParameterDeliminator(String url) {
if (url == null) {
    return null;
} else if (StringUtils.containsNone(url, "?")) {
    return url + "?";
} else {
    return url + "&";
}
   }
 
Example 5
Source File: StringFormatter.java    From fenixedu-academic with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Checks that a string does not contain special characters (only
 * alphanumeric ones).
 * 
 * @param string
 *            the string to check
 * @return <code>true</code> if the strings contains a special character
 */
protected static boolean containsNoneSpecialChars(String string) {
    return StringUtils.containsNone(string, specialChars);
}