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

The following are Jave code examples for showing how to use strip() 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: saluki   File: GenericInvokeUtils.java   View Source Code Vote up 7 votes
private static Object generateMapType(ServiceDefinition def, TypeDefinition td, MetadataType metadataType,
                                      Set<String> resolvedTypes) {
    String keyType = StringUtils.substringAfter(td.getType(), "<");
    keyType = StringUtils.substringBefore(keyType, ",");
    keyType = StringUtils.strip(keyType);
    keyType = StringUtils.isNotEmpty(keyType) ? keyType : "java.lang.Object";
    Object key = generateType(def, keyType, metadataType, resolvedTypes);

    String valueType = StringUtils.substringAfter(td.getType(), ",");
    valueType = StringUtils.substringBefore(valueType, ">");
    valueType = StringUtils.strip(valueType);
    valueType = StringUtils.isNotEmpty(valueType) ? valueType : "java.lang.Object";
    Object value = generateType(def, valueType, metadataType, resolvedTypes);

    Map<Object, Object> map = new HashMap<>();
    map.put(key, value);
    return map;
}
 
Example 2
Project: cyberduck   File: FTPStatListService.java   View Source Code Vote up 6 votes
protected List<String> parse(final int response, final String[] reply) {
    final List<String> result = new ArrayList<String>(reply.length);
    for(final String line : reply) {
        // Some servers include the status code for every line.
        if(line.startsWith(String.valueOf(response))) {
            try {
                String stripped = line;
                stripped = StringUtils.strip(StringUtils.removeStart(stripped, String.valueOf(String.format("%d-", response))));
                stripped = StringUtils.strip(StringUtils.removeStart(stripped, String.valueOf(response)));
                result.add(stripped);
            }
            catch(IndexOutOfBoundsException e) {
                log.error(String.format("Failed parsing line %s", line), e);
            }
        }
        else {
            result.add(StringUtils.strip(line));
        }
    }
    return result;
}
 
Example 3
Project: hue   File: CommonUtils.java   View Source Code Vote up 5 votes
public static String normalizeString(String input) {
	// Contain only ASCII letters, digits, or underscore characters (_).
	// Begin with an alphabetic character or underscore character.
	// Subsequent characters may include letters, digits, underscores.
	// Be between 1 and 127 characters in length, not including quotes for
	// delimited identifiers.
	// Contain no quotation marks and no spaces.
	StringBuffer sb = new StringBuffer();
	// To lowercase and remove all extra whitespaces.
	input = StringUtils.normalizeSpace(input.toLowerCase());
	for (char c : input.toCharArray()) {
		if (VALID_CHARS.contains(String.valueOf(c))) {
			if (sb.length() == 0 && INVALID_FIRST_CHARS.contains(String.valueOf(c))) {
				sb.append(REPLACEMENT_CHAR);
			}
			else {
				sb.append(c);
			}
		}
		else {
			sb.append(REPLACEMENT_CHAR);
		}
	}

	String normalizedName = sb.toString();
	// Remove leading and trailing underscore and multiple underscores
	normalizedName = StringUtils.replacePattern(normalizedName, "_{2,}", REPLACEMENT_CHAR);
	normalizedName = StringUtils.strip(normalizedName, REPLACEMENT_CHAR);

	return normalizedName.length() > 127 ? normalizedName.substring(0, 127) : normalizedName;
}
 
Example 4
Project: cyberduck   File: PunycodeConverter.java   View Source Code Vote up 5 votes
/**
 * @return IDN normalized hostname
 */
public String convert(final String hostname) {
    if(!PreferencesFactory.get().getBoolean("connection.hostname.idn")) {
        return StringUtils.strip(hostname);
    }
    if(StringUtils.isNotEmpty(hostname)) {
        try {
            // Convenience function that implements the IDNToASCII operation as defined in
            // the IDNA RFC. This operation is done on complete domain names, e.g: "www.example.com".
            // It is important to note that this operation can fail. If it fails, then the input
            // domain name cannot be used as an Internationalized Domain Name and the application
            // should have methods defined to deal with the failure.
            // IDNA.DEFAULT Use default options, i.e., do not process unassigned code points
            // and do not use STD3 ASCII rules If unassigned code points are found
            // the operation fails with ParseException
            final String idn = IDN.toASCII(StringUtils.strip(hostname));
            if(log.isDebugEnabled()) {
                if(!StringUtils.equals(StringUtils.strip(hostname), idn)) {
                    log.debug(String.format("IDN hostname for %s is %s", hostname, idn));
                }
            }
            if(StringUtils.isNotEmpty(idn)) {
                return idn;
            }
        }
        catch(IllegalArgumentException e) {
            log.warn(String.format("Failed to convert hostname %s to IDNA", hostname), e);
        }
    }
    return StringUtils.strip(hostname);
}
 
Example 5
Project: spring2ts   File: ServicePath.java   View Source Code Vote up 5 votes
private String extractVariableName(String path, int start, int end, Set<String> variables) {
    String substring = StringUtils.substring(path, start, end);
    String stripped = StringUtils.strip(substring, "{}");
    String variable = StringUtils.substringBefore(stripped, ":");
    variables.add(variable);
    return String.format("${%s}", variable);
}
 
Example 6
Project: Reer   File: Strings.java   View Source Code Vote up 4 votes
private static String strip(Object val) {
  return StringUtils.strip(String.valueOf(val));
}
 
Example 7
Project: Reer   File: Strings.java   View Source Code Vote up 4 votes
private static String strip(Object val) {
  return StringUtils.strip(String.valueOf(val));
}
 
Example 8
Project: beaker-notebook-archive   File: MIMEContainer.java   View Source Code Vote up 4 votes
public static MIMEContainer Math(String code) {
  code = StringUtils.strip(code, "$");
  return addMimeType(MIME.TEXT_LATEX, "$$" + code + "$$");
}