Package org.eclipse.rdf4j.common.xml
Class XMLUtil
- java.lang.Object
-
- org.eclipse.rdf4j.common.xml.XMLUtil
-
public class XMLUtil extends java.lang.ObjectUtility methods for handling and processing XML data.
-
-
Constructor Summary
Constructors Constructor Description XMLUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static boolean_charInRange(char c, int start, int end)private static java.lang.String_escapeAttValue(java.lang.String value)private static boolean_isAsciiBaseChar(char c)private static boolean_isAsciiDigit(char c)private static boolean_isNonAsciiBaseChar(char c)private static boolean_isNonAsciiDigit(char c)static java.lang.StringescapeAttributeValue(java.lang.String value)Escapes all characters that have a special meaning in XML attribute values -- i.e.static java.lang.StringescapeCharacterData(java.lang.String text)Escapes any special characters in the supplied text so that it can be included as character data in an XML document.static java.lang.StringescapeDoubleQuotedAttValue(java.lang.String value)Escapes any special characters in the supplied value so that it can be used as an double-quoted attribute value in an XML document.static java.lang.StringescapeSingleQuotedAttValue(java.lang.String value)Escapes any special characters in the supplied value so that it can be used as an single-quoted attribute value in an XML document.static java.lang.StringescapeText(java.lang.String text)Escapes all characters that have a special meaning in XML text -- i.e.static intfindURISplitIndex(java.lang.String uri)Tries to find a point in the supplied URI where this URI can be safely split into a namespace part and a local name.static booleanisCombiningChar(char c)static booleanisDigit(char c)static booleanisExtender(char c)static booleanisIdeographic(char c)static booleanisLetter(char c)static booleanisNCName(java.lang.String name)Checks whether the supplied String is an NCName (Namespace Classified Name) as specified at http://www.w3.org/TR/REC-xml-names/#NT-NCName .static booleanisNCNameChar(char c)static booleanisNCNameStartChar(char c)static booleanisValidCharacterDataChar(char c)Returns whether the specified character can appear in XML character data.static booleanisValidCharacterDataChar(int c)Returns whether the specified character can appear in XML character data.static java.lang.StringremoveInvalidCharacterDataChars(java.lang.String s)Removes all non-valid XML character data chars from the specified String.static java.lang.StringresolveEntities(java.lang.String text)Replaces all XML character entities with the character they represent.static java.lang.StringresolveEntity(java.lang.String entName)Resolves an entity reference or character reference to its value.
-
-
-
Method Detail
-
escapeCharacterData
public static java.lang.String escapeCharacterData(java.lang.String text)
Escapes any special characters in the supplied text so that it can be included as character data in an XML document. The characters that are escaped are &, <, > and carriage return (\r).
-
escapeDoubleQuotedAttValue
public static java.lang.String escapeDoubleQuotedAttValue(java.lang.String value)
Escapes any special characters in the supplied value so that it can be used as an double-quoted attribute value in an XML document. The characters that are escaped are &, <, >, tab (\t), carriage return (\r), line feed (\n) and " .
-
escapeSingleQuotedAttValue
public static java.lang.String escapeSingleQuotedAttValue(java.lang.String value)
Escapes any special characters in the supplied value so that it can be used as an single-quoted attribute value in an XML document. The characters that are escaped are &, <, >, tab (\t), carriage return (\r), line feed (\n) and ' .
-
_escapeAttValue
private static java.lang.String _escapeAttValue(java.lang.String value)
-
resolveEntities
public static java.lang.String resolveEntities(java.lang.String text)
Replaces all XML character entities with the character they represent.
-
resolveEntity
public static java.lang.String resolveEntity(java.lang.String entName)
Resolves an entity reference or character reference to its value.- Parameters:
entName- The 'name' of the reference. This is the string between & and ;, e.g. amp, quot, #65 or #x41.- Returns:
- The value of the supplied reference, or the reference itself if it could not be resolved.
-
findURISplitIndex
public static int findURISplitIndex(java.lang.String uri)
Tries to find a point in the supplied URI where this URI can be safely split into a namespace part and a local name. According to the XML specifications, a local name must start with a letter or underscore and can be followed by zero or more 'NCName' characters.- Parameters:
uri- The URI to split.- Returns:
- The index of the first character of the local name, or -1 if the URI can not be split into a namespace and local name.
-
isNCName
public static final boolean isNCName(java.lang.String name)
Checks whether the supplied String is an NCName (Namespace Classified Name) as specified at http://www.w3.org/TR/REC-xml-names/#NT-NCName .
-
isNCNameStartChar
public static final boolean isNCNameStartChar(char c)
-
isNCNameChar
public static final boolean isNCNameChar(char c)
-
escapeAttributeValue
public static java.lang.String escapeAttributeValue(java.lang.String value)
Escapes all characters that have a special meaning in XML attribute values -- i.e. &, <, >, " and ' -- with their entities.- See Also:
resolveEntities(java.lang.String)
-
escapeText
public static java.lang.String escapeText(java.lang.String text)
Escapes all characters that have a special meaning in XML text -- i.e. &, < and > -- with their entities.- See Also:
resolveEntities(java.lang.String)
-
isValidCharacterDataChar
public static boolean isValidCharacterDataChar(char c)
Returns whether the specified character can appear in XML character data.
-
isValidCharacterDataChar
public static boolean isValidCharacterDataChar(int c)
Returns whether the specified character can appear in XML character data. The integer encoding also makes the representation of supplementary Unicode characters possible.
-
removeInvalidCharacterDataChars
public static java.lang.String removeInvalidCharacterDataChars(java.lang.String s)
Removes all non-valid XML character data chars from the specified String. If all characters are valid character data chars, this method will return the same String.
-
isLetter
public static final boolean isLetter(char c)
-
_isAsciiBaseChar
private static boolean _isAsciiBaseChar(char c)
-
_isNonAsciiBaseChar
private static boolean _isNonAsciiBaseChar(char c)
-
isIdeographic
public static final boolean isIdeographic(char c)
-
isCombiningChar
public static final boolean isCombiningChar(char c)
-
isDigit
public static final boolean isDigit(char c)
-
_isAsciiDigit
private static boolean _isAsciiDigit(char c)
-
_isNonAsciiDigit
private static boolean _isNonAsciiDigit(char c)
-
isExtender
public static final boolean isExtender(char c)
-
_charInRange
private static boolean _charInRange(char c, int start, int end)
-
-