Java Code Examples for org.apache.commons.lang3.StringUtils.indexOf()

The following are Jave code examples for showing how to use indexOf() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: nifi-registry   File: CertificateUtils.java   View Source Code Vote up 6 votes
/**
 * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because
 * the DN is in an unrecognized format, the entire DN is returned.
 *
 * @param dn the dn to extract the username from
 * @return the exatracted username
 */
public static String extractUsername(String dn) {
    String username = dn;

    // ensure the dn is specified
    if (StringUtils.isNotBlank(dn)) {
        // determine the separate
        final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ",";

        // attempt to locate the cd
        final String cnPattern = "cn=";
        final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern);
        if (cnIndex >= 0) {
            int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex);
            if (separatorIndex > 0) {
                username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex);
            } else {
                username = StringUtils.substring(dn, cnIndex + cnPattern.length());
            }
        }
    }

    return username;
}
 
Example 2
Project: saluki   File: ConsulRegistry.java   View Source Code Vote up 5 votes
private GrpcURL buildURL(ConsulService service) {
  try {
    for (String tag : service.getTags()) {
      if (StringUtils.indexOf(tag, Constants.PROVIDERS_CATEGORY) != -1) {
        String toUrlPath = StringUtils.substringAfter(tag, Constants.PROVIDERS_CATEGORY);
        GrpcURL salukiUrl = GrpcURL.valueOf(GrpcURL.decode(toUrlPath));
        return salukiUrl;
      }
    }
  } catch (Exception e) {
    log.error("convert consul service to url fail! service:" + service, e);
  }
  return null;
}
 
Example 3
Project: Fetax-AI   File: XSSFilter.java   View Source Code Vote up 5 votes
private String rmXSSDangerousCharacters(String script, String[] xss) {// 移除存在XSS攻击威胁的字符串

			if (null == xss || xss.length == 0) {
				return script;
			}

			for (String remove : xss) {

				if (StringUtils.isBlank(remove)) {
					continue;
				}

				if (StringUtils.indexOf(script, remove) < 0) {
					continue;
				}

				if (remove.length() == 1) {
					script = StringUtils.remove(script, remove.charAt(0));
					log.warn('[' + remove + "]已移除");
					continue;
				}

				Pattern p = Pattern.compile(remove, Pattern.CASE_INSENSITIVE);
				Matcher m = p.matcher(script);

				while (m.find()) {
					String st = m.group();
					script = StringUtils.remove(script, remove);
					log.warn('[' + st + "]已移除");
				}

			}

			return script;
		}
 
Example 4
Project: awe-awesomesky   File: XSSFilter.java   View Source Code Vote up 5 votes
private String rmXSSDangerousCharacters(String script, String[] xss) {// 移除存在XSS攻击威胁的字符串

			if (null == xss || xss.length == 0) {
				return script;
			}

			for (String remove : xss) {

				if (StringUtils.isBlank(remove)) {
					continue;
				}

				if (StringUtils.indexOf(script, remove) < 0) {
					continue;
				}

				if (remove.length() == 1) {
					script = StringUtils.remove(script, remove.charAt(0));
					log.warn('[' + remove + "]已移除");
					continue;
				}

				Pattern p = Pattern.compile(remove, Pattern.CASE_INSENSITIVE);
				Matcher m = p.matcher(script);

				while (m.find()) {
					String st = m.group();
					script = StringUtils.remove(script, remove);
					log.warn('[' + st + "]已移除");
				}

			}

			return script;
		}
 
Example 5
Project: util   File: FilePathUtil.java   View Source Code Vote up 5 votes
/**
 * 在Windows环境里,兼容Windows上的路径分割符,将 '/' 转回 '\'
 */
public static String normalizePath(String path) {
	if (Platforms.FILE_PATH_SEPARATOR_CHAR == Platforms.WINDOWS_FILE_PATH_SEPARATOR_CHAR
			&& StringUtils.indexOf(path, Platforms.LINUX_FILE_PATH_SEPARATOR_CHAR) != -1) {
		return StringUtils.replaceChars(path, Platforms.LINUX_FILE_PATH_SEPARATOR_CHAR,
				Platforms.WINDOWS_FILE_PATH_SEPARATOR_CHAR);
	}
	return path;

}
 
Example 6
Project: Android_watch_magpie   File: LogicTupleEvent.java   View Source Code Vote up 4 votes
private String getSubstring(String start, String end) {
    int first = StringUtils.indexOf(logicRepresentation, start);
    int second = StringUtils.indexOf(logicRepresentation, end);
    return StringUtils.substring(logicRepresentation, first + 1, second);
}
 
Example 7
Project: vscrawler   File: IndexOf.java   View Source Code Vote up 4 votes
@Override
protected int handleIndex(CharSequence str, CharSequence searchStr, int startPos) {
    return StringUtils.indexOf(str, searchStr, startPos);
}
 
Example 8
Project: util   File: CsvUtil.java   View Source Code Vote up 4 votes
/**
 * Parse fields as csv string,
 */
public static String toCsvString(Object... elements) {
	StringBuilder line = new StringBuilder();
	int last = elements.length - 1;
	for (int i = 0; i < elements.length; i++) {
		if (elements[i] == null) {
			if (i != last) {
				line.append(FIELD_SEPARATOR);
			}
			continue;
		}
		String field = elements[i].toString();

		// check for special cases
		int ndx = field.indexOf(FIELD_SEPARATOR);
		if (ndx == -1) {
			ndx = field.indexOf(FIELD_QUOTE);
		}
		if (ndx == -1 && (field.startsWith(SPACE) || field.endsWith(SPACE))) {
			ndx = 1;
		}
		if (ndx == -1) {
			ndx = StringUtils.indexOf(field, SPECIAL_CHARS);
		}

		// add field
		if (ndx != -1) {
			line.append(FIELD_QUOTE);
		}
		field = StringUtils.replace(field, QUOTE, DOUBLE_QUOTE);
		line.append(field);
		if (ndx != -1) {
			line.append(FIELD_QUOTE);
		}

		// last
		if (i != last) {
			line.append(FIELD_SEPARATOR);
		}
	}
	return line.toString();
}