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

The following examples show how to use org.apache.commons.lang.StringUtils#normalizeSpace() . 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: RequestWrapper.java    From oxAuth with MIT License 6 votes vote down vote up
public String getContent() {
    try {
        if (this.parameterMap.isEmpty()) {
            if (ArrayUtils.isEmpty(content))
                content = IOUtils.toByteArray(delegate.getInputStream());
            else
                content = IOUtils.toByteArray(new LoggingServletInputStream(content));
        } else {
            content = getContentFromParameterMap(this.parameterMap);
        }
        String requestEncoding = delegate.getCharacterEncoding();
        String normalizedContent = StringUtils.normalizeSpace(new String(content, requestEncoding != null ? requestEncoding : StandardCharsets.UTF_8.name()));
        return StringUtils.isBlank(normalizedContent) ? null : normalizedContent;
    } catch (IOException e) {
        throw new IllegalStateException();
    }
}
 
Example 2
Source File: AliasesParser.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fixes an alias name by trimming it and removing all extraneous spaces
 * between the words.
 * @param name Name to be fixed.
 * @return Name fixed.
 */
protected String fixName(String name) {
	String result = StringUtils.normalizeSpace(name);
	
	int i = result.indexOf('¦');
	
	if (i != -1 && Character.isWhitespace(result.codePointBefore(i)))
		result = result.substring(0, i - 1) + result.substring(i);
	return result;
}
 
Example 3
Source File: TextPair.java    From dkpro-jwpl with Apache License 2.0 5 votes vote down vote up
/**
 * Normalizes the Strings in the TextPair.
 * This mainly deals with whitespace-issues.
 * Other normalizations can be included.
 *
 * @param str
 * @return
 */
private String normalize(String str){
	str = StringUtils.trimToEmpty(str);
	str = StringUtils.normalizeSpace(str);

	// remove whitespace before punctuation. not using \p{Punct},
	// because it includes to many special characters.
	str = str.replaceAll("\\s+(?=[.!,\\?;:])", "");

	return str;
}