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

The following examples show how to use org.apache.commons.lang.StringUtils#containsAny() . 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: AtlasStructType.java    From atlas with 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 File: KafkaNotification.java    From atlas with 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
Source File: SelectModulaSourceFileDialog.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
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
Source File: StringEscapeUtils.java    From ymate-platform-v2 with Apache License 2.0 6 votes vote down vote up
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 File: AtlasStructType.java    From incubator-atlas with 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 File: ServletTestUtils.java    From hop with 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 File: Utilities.java    From pxf with 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 File: Command.java    From azure-devops-intellij with 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 File: SQLParameter.java    From ymate-platform-v2 with 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
Source File: SimpleAtlasAuthorizer.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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 File: ServletTestUtils.java    From pentaho-kettle with 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
Source File: RunConfigurationDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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 File: MQMessageUtils.java    From canal-1.1.3 with 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 File: ModeUtils.java    From DataLink with Apache License 2.0 4 votes vote down vote up
public static boolean isWildCard(String value) {
    return StringUtils.containsAny(value, new char[]{'*', '?', '+', '|', '(', ')', '{', '}', '[', ']', '\\', '$',
            '^', '.'});
}
 
Example 15
Source File: YamlValueInsertHandler.java    From intellij-spring-assistant with MIT License 4 votes vote down vote up
private boolean shouldUseQuotes(final LookupElement lookupElement) {
  return StringUtils.containsAny(lookupElement.getLookupString(), RESERVED_YAML_CHARS);
}
 
Example 16
Source File: GlossaryService.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static boolean isNameInvalid(String name) {
    return StringUtils.containsAny(name, invalidNameChars);
}
 
Example 17
Source File: YamlInsertValueHandler.java    From intellij-swagger with MIT License 4 votes vote down vote up
private boolean shouldUseQuotes(final LookupElement lookupElement) {
  return StringUtils.containsAny(lookupElement.getLookupString(), RESERVED_YAML_CHARS);
}
 
Example 18
Source File: WildcardUtil.java    From disthene-reader with MIT License 4 votes vote down vote up
public static boolean isPlainPath(String path) {
    char noPlainChars[] = {'*', '?', '{', '(', '['};
    return !(StringUtils.containsAny(path, noPlainChars));
}
 
Example 19
Source File: MQMessageUtils.java    From canal with Apache License 2.0 4 votes vote down vote up
private static boolean isWildCard(String value) {
    // not contaiins '.' ?
    return StringUtils.containsAny(value, new char[] { '*', '?', '+', '|', '(', ')', '{', '}', '[', ']', '\\', '$',
            '^' });
}