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

The following examples show how to use org.apache.commons.lang.StringUtils#containsAny() . These examples are extracted from open source projects. 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 Project: atlas   File: AtlasStructType.java    License: Apache License 2.0 6 votes vote down vote up
public static String escapeIndexQueryValue(String value) {
    String ret = value;

    if (StringUtils.containsAny(value, IDX_QRY_OFFENDING_CHARS)) {
        boolean isQuoteAtStart = value.charAt(0) == DOUBLE_QUOTE_CHAR;
        boolean isQuoteAtEnd   = value.charAt(value.length() - 1) == DOUBLE_QUOTE_CHAR;

        if (!isQuoteAtStart) {
            if (!isQuoteAtEnd) {
                ret = DOUBLE_QUOTE_CHAR + value + DOUBLE_QUOTE_CHAR;
            } else {
                ret = DOUBLE_QUOTE_CHAR + value;
            }
        } else if (!isQuoteAtEnd) {
            ret = value + DOUBLE_QUOTE_CHAR;
        }
    }

    return ret;
}
 
Example 2
Source Project: atlas   File: KafkaNotification.java    License: Apache License 2.0 6 votes vote down vote up
private static String surroundWithQuotes(String optionVal) {
    if(StringUtils.isEmpty(optionVal)) {
        return optionVal;
    }
    String ret = optionVal;

    // For property values which have special chars like "@" or "/", we need to enclose it in
    // double quotes, so that Kafka can parse it
    // If the property is already enclosed in double quotes, then do nothing.
    if(optionVal.indexOf(0) != '"' && optionVal.indexOf(optionVal.length() - 1) != '"') {
        // If the string as special characters like except _,-
        final String SPECIAL_CHAR_LIST = "/[email protected]#%^&*";
        if (StringUtils.containsAny(optionVal, SPECIAL_CHAR_LIST)) {
            ret = String.format("\"%s\"", optionVal);
        }
    }

    return ret;
}
 
Example 3
public SourceFileItemsFilter() {
    super(new SearchPattern() {
        @Override
        public void setPattern(String stringPattern) {
            if (!StringUtils.containsAny(stringPattern, new char[]{'*', '?'})) {
                stringPattern = "*"+stringPattern+"*"; //$NON-NLS-1$ //$NON-NLS-2$
            }
            // System.out.println("-- setPattern: \'" + stringPattern + '\'');
            super.setPattern(stringPattern);
        }
    });
    
    String patt = this.getPattern();
    myMatcher = new MyMatcher(patt+'*', false);
    isCompilationSetOnly = toggleCompilationSetOnlyAction.isChecked();
}
 
Example 4
public static String unescapeCsv(String str) {
    if (str == null) {
        return null;
    }
    if (str.length() < 2) {
        return str;
    }
    if (str.charAt(0) != CSV_QUOTE || str.charAt(str.length() - 1) != CSV_QUOTE) {
        return str;
    }
    String quoteless = str.substring(1, str.length() - 1);
    if (StringUtils.containsAny(quoteless, CSV_SEARCH_CHARS)) {
        str = StringUtils.replace(quoteless, CSV_QUOTE_STR + CSV_QUOTE_STR, CSV_QUOTE_STR);
    }
    return str;
}
 
Example 5
Source Project: incubator-atlas   File: AtlasStructType.java    License: Apache License 2.0 6 votes vote down vote up
public static String escapeIndexQueryValue(String value) {
    String ret = value;

    if (StringUtils.containsAny(value, IDX_QRY_OFFENDING_CHARS)) {
        boolean isQuoteAtStart = value.charAt(0) == DOUBLE_QUOTE_CHAR;
        boolean isQuoteAtEnd   = value.charAt(value.length() - 1) == DOUBLE_QUOTE_CHAR;

        if (!isQuoteAtStart) {
            if (!isQuoteAtEnd) {
                ret = DOUBLE_QUOTE_CHAR + value + DOUBLE_QUOTE_CHAR;
            } else {
                ret = DOUBLE_QUOTE_CHAR + value;
            }
        } else if (!isQuoteAtEnd) {
            ret = value + DOUBLE_QUOTE_CHAR;
        }
    }

    return ret;
}
 
Example 6
Source Project: hop   File: ServletTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean hasBadText( String value ) {
  Matcher matcher = PATTERN.matcher( value );
  if ( matcher.find() ) {
    return true;
  }
  return StringUtils.containsAny( value, BAD_CHARACTERS_TO_ESCAPE );
}
 
Example 7
Source Project: pxf   File: Utilities.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validation for directory names that can be created
 * for the server configuration directory. Optionally checking for
 * prohibited characters in the directory name.
 *
 * @param name                    the directory name
 * @param checkForProhibitedChars true to check for prohibited chars, false otherwise
 * @return true if value, false otherwise
 */
private static boolean isValidRestrictedDirectoryName(String name, boolean checkForProhibitedChars) {
    if (StringUtils.isBlank(name) ||
            (checkForProhibitedChars && StringUtils.containsAny(name, PROHIBITED_CHARS))) {
        return false;
    }
    File file = new File(name);
    try {
        file.getCanonicalPath();
        return true;
    } catch (IOException e) {
        return false;
    }
}
 
Example 8
Source Project: azure-devops-intellij   File: Command.java    License: MIT License 5 votes vote down vote up
protected boolean isFilePath(final String line) {
    if (StringUtils.endsWith(line, ":")) {
        // File paths are different on different OSes
        if (StringUtils.containsAny(line, "\\/")) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source Project: ymate-platform-v2   File: SQLParameter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    if (value instanceof String) {
        if (StringUtils.containsAny((String) value, new char[]{'\r', '\n'})) {
            return "\"".concat(__tryBase64Str((String) value)).concat("\"");
        } else {
            return "\"".concat(value.toString()).concat("\"");
        }
    }
    return value != null ? value.toString() : "@NULL";
}
 
Example 10
private boolean resourceMatchHelper(List<String> policyResource) {
    boolean isMatchAny = false;
    if (isDebugEnabled) {
        LOG.debug("==> SimpleAtlasAuthorizer resourceMatchHelper");
    }

    boolean optWildCard = true;

    List<String> policyValues = new ArrayList<>();

    if (policyResource != null) {
        boolean isWildCardPresent = !optWildCard;
        for (String policyValue : policyResource) {
            if (StringUtils.isEmpty(policyValue)) {
                continue;
            }
            if (StringUtils.containsOnly(policyValue, WILDCARD_ASTERISK)) {
                isMatchAny = true;
            } else if (!isWildCardPresent && StringUtils.containsAny(policyValue, WILDCARDS)) {
                isWildCardPresent = true;
            }
            policyValues.add(policyValue);
        }
        optWildCard = optWildCard && isWildCardPresent;
    } else {
        isMatchAny = false;
    }

    if (isDebugEnabled) {
        LOG.debug("<== SimpleAtlasAuthorizer resourceMatchHelper");
    }
    return isMatchAny;
}
 
Example 11
Source Project: pentaho-kettle   File: ServletTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean hasBadText( String value ) {
  Matcher matcher = PATTERN.matcher( value );
  if ( matcher.find() ) {
    return true;
  }
  return StringUtils.containsAny( value, BAD_CHARACTERS_TO_ESCAPE );
}
 
Example 12
private boolean validated() {
  if ( StringUtils.containsAny( wName.getText(), "%\"\\/:[]*|\t\r\n" ) ) {
    MessageBox messageBox = new MessageBox( shell, SWT.ERROR );
    messageBox.setMessage( BaseMessages.getString( PKG, "RunConfiguration.InvalidChars.Message" ) );
    messageBox.setText( BaseMessages.getString( PKG, "RunConfiguration.InvalidChars.Title" ) );
    messageBox.open();
    return false;
  }

  return true;
}
 
Example 13
Source Project: canal-1.1.3   File: MQMessageUtils.java    License: Apache License 2.0 4 votes vote down vote up
private static boolean isWildCard(String value) {
    // not contaiins '.' ?
    return StringUtils.containsAny(value, new char[] { '*', '?', '+', '|', '(', ')', '{', '}', '[', ']', '\\', '$',
            '^' });
}
 
Example 14
Source Project: DataLink   File: ModeUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isWildCard(String value) {
    return StringUtils.containsAny(value, new char[]{'*', '?', '+', '|', '(', ')', '{', '}', '[', ']', '\\', '$',
            '^', '.'});
}
 
Example 15
private boolean shouldUseQuotes(final LookupElement lookupElement) {
  return StringUtils.containsAny(lookupElement.getLookupString(), RESERVED_YAML_CHARS);
}
 
Example 16
Source Project: atlas   File: GlossaryService.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isNameInvalid(String name) {
    return StringUtils.containsAny(name, invalidNameChars);
}
 
Example 17
private boolean shouldUseQuotes(final LookupElement lookupElement) {
  return StringUtils.containsAny(lookupElement.getLookupString(), RESERVED_YAML_CHARS);
}
 
Example 18
Source Project: disthene-reader   File: WildcardUtil.java    License: MIT License 4 votes vote down vote up
public static boolean isPlainPath(String path) {
    char noPlainChars[] = {'*', '?', '{', '(', '['};
    return !(StringUtils.containsAny(path, noPlainChars));
}
 
Example 19
Source Project: canal   File: MQMessageUtils.java    License: Apache License 2.0 4 votes vote down vote up
private static boolean isWildCard(String value) {
    // not contaiins '.' ?
    return StringUtils.containsAny(value, new char[] { '*', '?', '+', '|', '(', ')', '{', '}', '[', ']', '\\', '$',
            '^' });
}