Java Code Examples for org.apache.xml.utils.XMLChar#isValid()

The following examples show how to use org.apache.xml.utils.XMLChar#isValid() . 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: UserTextFilterForXml.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Removes invalid XML 1.0 Unicode characters
 * @param text The String to clean
 * @return The resulting String
 */
public static String cleanInvalidXmlChars(String text) {
    if (StringUtils.isBlank(text)) {
        return text;
    } else {
        StringBuilder sb = new StringBuilder();
        boolean strippedCharacter = false;
        for (int i = 0; i < text.length(); i++) {
            char c = text.charAt(i);
            if (XMLChar.isValid(c)) {
                sb.append(c);
            } else {
                strippedCharacter = true;
            }
        }

        if (strippedCharacter) {
            return sb.toString();
        } else {
            return text;
        }
    }
}
 
Example 2
Source File: StringUtil.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks, whether string contains invalid xml chars
 * @param string to check
 * @return true if there're xml invalid chars
 */
public static Boolean containsInvalidXmlChars2(String string) {
    for (int i = 0; i < string.length(); i++) {
        if (!XMLChar.isValid(string.charAt(i))) {
            return Boolean.TRUE;
        }
    }
    return Boolean.FALSE;
}
 
Example 3
Source File: AbstractToken.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Checks a string to see if any characters are invalid for inclusion in 
 * XML strings.
 * @param value     The string to check.
 * @return  A parse result of success if the string uses only valid characters.
 */
protected ParseResult checkForInvalidXMLChars(String value)
{
	for (char character : value.toCharArray())
	{
		if (!XMLChar.isValid(character))
		{
			return new ParseResult.Fail(
				"Invalid XML character 0x" + Integer.toString(character, 16) + " in " + value);
		}
	}

	return ParseResult.SUCCESS;
}
 
Example 4
Source File: AbstractToken.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Checks a string to see if any characters are invalid for inclusion in 
 * XML strings.
 * @param value     The string to check.
 * @return  A parse result of success if the string uses only valid characters.
 */
protected ParseResult checkForInvalidXMLChars(String value)
{
	for (char character : value.toCharArray())
	{
		if (!XMLChar.isValid(character))
		{
			return new ParseResult.Fail(
				"Invalid XML character 0x" + Integer.toString(character, 16) + " in " + value);
		}
	}

	return ParseResult.SUCCESS;
}
 
Example 5
Source File: StringUtil.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks, whether string contains invalid xml chars
 * @param string to check
 * @return true if there're xml invalid chars
 */
public static Boolean containsInvalidXmlChars2(String string) {
    for (int i = 0; i < string.length(); i++) {
        if (!XMLChar.isValid(string.charAt(i))) {
            return Boolean.TRUE;
        }
    }
    return Boolean.FALSE;
}