Class XmlEscape
- java.lang.Object
-
- org.unbescape.xml.XmlEscape
-
public final class XmlEscape extends java.lang.Object
Utility class for performing XML escape/unescape operations.
Configuration of escape/unescape operationsEscape operations can be (optionally) configured by means of:
- Level, which defines how deep the escape operation must be (what
chars are to be considered eligible for escaping, depending on the specific
needs of the scenario). Its values are defined by the
XmlEscapeLevel
enum. - Type, which defines whether escaping should be performed by means of CERs
(Character Entity References) or by means of decimal/hexadecimal numerical references.
Its values are defined by the
XmlEscapeType
enum.
Unescape operations need no configuration parameters. Unescape operations will always perform complete unescape of CERs, decimal and hexadecimal references.
FeaturesThis class supports both XML 1.0 and XML 1.1 escape/unescape operations. Whichever the XML version used, only the five predefined XML character entities are supported: <, >, &, " and '. This means there is no support for DTD-defined or user-defined entities.
Each version of XML establishes a series of characters that are considered not-valid, even when escaped —for example, the \u0000 (null byte)—. Escape operations will automatically remove these chars.
Also, each version of XML establishes a series of control characters that, even if allowed as valid characters, should always appear escaped. For example: \u0001 to \u0008 in XML 1.1.
This class supports the whole Unicode character set: \u0000 to \u10FFFF, including characters not representable by only one char in Java (>\uFFFF).
Input/OutputThere are four different input/output modes that can be used in escape/unescape operations:
- String input, String output: Input is specified as a String object and output is returned as another. In order to improve memory performance, all escape and unescape operations will return the exact same input object as output if no escape/unescape modifications are required.
- String input, java.io.Writer output: Input will be read from a String and output will be written into the specified java.io.Writer.
- java.io.Reader input, java.io.Writer output: Input will be read from a Reader and output will be written into the specified java.io.Writer.
- char[] input, java.io.Writer output: Input will be read from a char array (char[]) and output will be written into the specified java.io.Writer. Two int arguments called offset and len will be used for specifying the part of the char[] that should be escaped/unescaped. These methods should be called with offset = 0 and len = text.length in order to process the whole char[].
- ER
- XML Entity Reference: references to variables used to define shortcuts to standard text or special characters. Entity references start with '&' and end with ';'.
- CER
- Character Entity Reference: XML Entity Reference used to define a shortcut to a specific character. XML specifies five predefined CERs: < (<), > (>), & (&), " (") and ' (').
- DCR
- Decimal Character Reference: base-10 numerical representation of an Unicode codepoint: á
- HCR
- Hexadecimal Character Reference: hexadecimal numerical representation of an Unicode codepoint: á. Note that XML only allows lower-case 'x' for defining hexadecimal character entity references (in contrast with HTML, which allows both '&#x...;' and '&#x...;').
- Unicode Codepoint
- Each of the int values conforming the Unicode code space. Normally corresponding to a Java char primitive value (codepoint <= \uFFFF), but might be two chars for codepoints \u10000 to \u10FFFF if the first char is a high surrogate (\uD800 to \uDBFF) and the second is a low surrogate (\uDC00 to \uDFFF).
The following references apply:
- Using character escapes in markup and CSS [w3.org]
- XML 1.0 Specification [w3.org]
- XML 1.1 Specification [w3.org]
- Supplementary characters in the Java Platform [oracle.com]
- Since:
- 1.0.0
- Level, which defines how deep the escape operation must be (what
chars are to be considered eligible for escaping, depending on the specific
needs of the scenario). Its values are defined by the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
XmlEscape.InternalStringReader
-
Constructor Summary
Constructors Modifier Constructor Description private
XmlEscape()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
escapeXml(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeSymbols symbols, XmlEscapeType type, XmlEscapeLevel level)
private static void
escapeXml(java.io.Reader reader, java.io.Writer writer, XmlEscapeSymbols symbols, XmlEscapeType type, XmlEscapeLevel level)
private static void
escapeXml(java.lang.String text, java.io.Writer writer, XmlEscapeSymbols symbols, XmlEscapeType type, XmlEscapeLevel level)
private static java.lang.String
escapeXml(java.lang.String text, XmlEscapeSymbols symbols, XmlEscapeType type, XmlEscapeLevel level)
static void
escapeXml10(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a char[] input.static void
escapeXml10(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a char[] input.static void
escapeXml10(java.io.Reader reader, java.io.Writer writer)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a Reader input, writing results to a Writer.static void
escapeXml10(java.io.Reader reader, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a Reader input, writing results to a Writer.static java.lang.String
escapeXml10(java.lang.String text)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input.static void
escapeXml10(java.lang.String text, java.io.Writer writer)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input, writing results to a Writer.static void
escapeXml10(java.lang.String text, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a String input, writing results to a Writer.static java.lang.String
escapeXml10(java.lang.String text, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a String input.static void
escapeXml10Attribute(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a char[] input meant to be an XML attribute value.static void
escapeXml10Attribute(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a char[] input meant to be an XML attribute value.static void
escapeXml10Attribute(java.io.Reader reader, java.io.Writer writer)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.static void
escapeXml10Attribute(java.io.Reader reader, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.static java.lang.String
escapeXml10Attribute(java.lang.String text)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input meant to be an XML attribute value.static void
escapeXml10Attribute(java.lang.String text, java.io.Writer writer)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input meant to be an XML attribute value, writing results to a Writer.static void
escapeXml10Attribute(java.lang.String text, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a String input meant to be an XML attribute value, writing results to a Writer.static java.lang.String
escapeXml10Attribute(java.lang.String text, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a String input meant to be an XML attribute value.static void
escapeXml10AttributeMinimal(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a char[] input meant to be an XML attribute value.static void
escapeXml10AttributeMinimal(java.io.Reader reader, java.io.Writer writer)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.static java.lang.String
escapeXml10AttributeMinimal(java.lang.String text)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a String input meant to be an XML attribute value.static void
escapeXml10AttributeMinimal(java.lang.String text, java.io.Writer writer)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a String input meant to be an XML attribute value, writing results to a Writer.static void
escapeXml10Minimal(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a char[] input.static void
escapeXml10Minimal(java.io.Reader reader, java.io.Writer writer)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a Reader input, writing results to a Writer.static java.lang.String
escapeXml10Minimal(java.lang.String text)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a String input.static void
escapeXml10Minimal(java.lang.String text, java.io.Writer writer)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a String input, writing results to a Writer.static void
escapeXml11(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a char[] input.static void
escapeXml11(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a char[] input.static void
escapeXml11(java.io.Reader reader, java.io.Writer writer)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a Reader input, writing results to a Writer.static void
escapeXml11(java.io.Reader reader, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a Reader input, writing results to a Writer.static java.lang.String
escapeXml11(java.lang.String text)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input.static void
escapeXml11(java.lang.String text, java.io.Writer writer)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input, writing results to a Writer.static void
escapeXml11(java.lang.String text, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a String input, writing results to a Writer.static java.lang.String
escapeXml11(java.lang.String text, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a String input.static void
escapeXml11Attribute(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a char[] input meant to be an XML attribute value.static void
escapeXml11Attribute(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a char[] input meant to be an XML attribute value.static void
escapeXml11Attribute(java.io.Reader reader, java.io.Writer writer)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.static void
escapeXml11Attribute(java.io.Reader reader, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.static java.lang.String
escapeXml11Attribute(java.lang.String text)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input meant to be an XML attribute value.static void
escapeXml11Attribute(java.lang.String text, java.io.Writer writer)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input meant to be an XML attribute value, writing results to a Writer.static void
escapeXml11Attribute(java.lang.String text, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a String input meant to be an XML attribute value, writing results to a Writer.static java.lang.String
escapeXml11Attribute(java.lang.String text, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a String input meant to be an XML attribute value.static void
escapeXml11AttributeMinimal(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a char[] input meant to be an XML attribute value.static void
escapeXml11AttributeMinimal(java.io.Reader reader, java.io.Writer writer)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.static java.lang.String
escapeXml11AttributeMinimal(java.lang.String text)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a String input meant to be an XML attribute value.static void
escapeXml11AttributeMinimal(java.lang.String text, java.io.Writer writer)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a String input meant to be an XML attribute value, writing results to a Writer.static void
escapeXml11Minimal(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a char[] input.static void
escapeXml11Minimal(java.io.Reader reader, java.io.Writer writer)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a Reader input, writing results to a Writer.static java.lang.String
escapeXml11Minimal(java.lang.String text)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a String input.static void
escapeXml11Minimal(java.lang.String text, java.io.Writer writer)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a String input, writing results to a Writer.static void
unescapeXml(char[] text, int offset, int len, java.io.Writer writer)
Perform an XML unescape operation on a char[] input.static void
unescapeXml(java.io.Reader reader, java.io.Writer writer)
Perform an XML unescape operation on a Reader input, writing results to a Writer.static java.lang.String
unescapeXml(java.lang.String text)
Perform an XML unescape operation on a String input.static void
unescapeXml(java.lang.String text, java.io.Writer writer)
Perform an XML unescape operation on a String input, writing results to a Writer.
-
-
-
Method Detail
-
escapeXml10Minimal
public static java.lang.String escapeXml10Minimal(java.lang.String text)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a String input.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
This method calls
escapeXml10(String, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- type:
-
escapeXml11Minimal
public static java.lang.String escapeXml11Minimal(java.lang.String text)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a String input.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
This method calls
escapeXml11(String, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- type:
-
escapeXml10AttributeMinimal
public static java.lang.String escapeXml10AttributeMinimal(java.lang.String text)
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a String input meant to be an XML attribute value.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(String, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- Since:
- 1.1.5
- type:
-
escapeXml11AttributeMinimal
public static java.lang.String escapeXml11AttributeMinimal(java.lang.String text)
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a String input meant to be an XML attribute value.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml11(String, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- Since:
- 1.1.5
- type:
-
escapeXml10
public static java.lang.String escapeXml10(java.lang.String text)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method calls
escapeXml10(String, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
escapeXml11
public static java.lang.String escapeXml11(java.lang.String text)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method calls
escapeXml11(String, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
escapeXml10Attribute
public static java.lang.String escapeXml10Attribute(java.lang.String text)
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input meant to be an XML attribute value.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(String, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- Since:
- 1.1.5
-
escapeXml11Attribute
public static java.lang.String escapeXml11Attribute(java.lang.String text)
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input meant to be an XML attribute value.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml11(String, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- Since:
- 1.1.5
-
escapeXml10
public static java.lang.String escapeXml10(java.lang.String text, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a String input.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.All other String-based escapeXml10*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
escapeXml11
public static java.lang.String escapeXml11(java.lang.String text, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a String input.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.All other String-based escapeXml11*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
escapeXml10Attribute
public static java.lang.String escapeXml10Attribute(java.lang.String text, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.0 escape operation on a String input meant to be an XML attribute value.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
All other String-based escapeXml10*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- Since:
- 1.1.5
-
escapeXml11Attribute
public static java.lang.String escapeXml11Attribute(java.lang.String text, XmlEscapeType type, XmlEscapeLevel level)
Perform a (configurable) XML 1.1 escape operation on a String input meant to be an XML attribute value.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
All other String-based escapeXml11*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- Since:
- 1.1.5
-
escapeXml
private static java.lang.String escapeXml(java.lang.String text, XmlEscapeSymbols symbols, XmlEscapeType type, XmlEscapeLevel level)
-
escapeXml10Minimal
public static void escapeXml10Minimal(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a String input, writing results to a Writer.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
This method calls
escapeXml10(String, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
- type:
-
escapeXml11Minimal
public static void escapeXml11Minimal(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a String input, writing results to a Writer.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
This method calls
escapeXml11(String, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
- type:
-
escapeXml10AttributeMinimal
public static void escapeXml10AttributeMinimal(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a String input meant to be an XML attribute value, writing results to a Writer.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(String, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
- type:
-
escapeXml11AttributeMinimal
public static void escapeXml11AttributeMinimal(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a String input meant to be an XML attribute value, writing results to a Writer.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml11(String, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
- type:
-
escapeXml10
public static void escapeXml10(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input, writing results to a Writer.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method calls
escapeXml10(String, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeXml11
public static void escapeXml11(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input, writing results to a Writer.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method calls
escapeXml11(String, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeXml10Attribute
public static void escapeXml10Attribute(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input meant to be an XML attribute value, writing results to a Writer.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(String, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml11Attribute
public static void escapeXml11Attribute(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a String input meant to be an XML attribute value, writing results to a Writer.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml11(String, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml10
public static void escapeXml10(java.lang.String text, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.0 escape operation on a String input, writing results to a Writer.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.All other String/Writer-based escapeXml10*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeXml11
public static void escapeXml11(java.lang.String text, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.1 escape operation on a String input, writing results to a Writer.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.All other String/Writer-based escapeXml11*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.type
- the type of escape operation to be performed, seeXmlEscapeType
.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeXml10Attribute
public static void escapeXml10Attribute(java.lang.String text, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.0 escape operation on a String input meant to be an XML attribute value, writing results to a Writer.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
All other String/Writer-based escapeXml10*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml11Attribute
public static void escapeXml11Attribute(java.lang.String text, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.1 escape operation on a String input meant to be an XML attribute value, writing results to a Writer.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
All other String/Writer-based escapeXml11*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.type
- the type of escape operation to be performed, seeXmlEscapeType
.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml
private static void escapeXml(java.lang.String text, java.io.Writer writer, XmlEscapeSymbols symbols, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
- Throws:
java.io.IOException
-
escapeXml10Minimal
public static void escapeXml10Minimal(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a Reader input, writing results to a Writer.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
This method calls
escapeXml10(Reader, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
- type:
-
escapeXml11Minimal
public static void escapeXml11Minimal(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a Reader input, writing results to a Writer.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
This method calls
escapeXml11(Reader, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
- type:
-
escapeXml10AttributeMinimal
public static void escapeXml10AttributeMinimal(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(Reader, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
- type:
-
escapeXml11AttributeMinimal
public static void escapeXml11AttributeMinimal(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml11(Reader, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
- type:
-
escapeXml10
public static void escapeXml10(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a Reader input, writing results to a Writer.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method calls
escapeXml10(Reader, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeXml11
public static void escapeXml11(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a Reader input, writing results to a Writer.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method calls
escapeXml11(Reader, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeXml10Attribute
public static void escapeXml10Attribute(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(Reader, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml11Attribute
public static void escapeXml11Attribute(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml11(Reader, Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml10
public static void escapeXml10(java.io.Reader reader, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.0 escape operation on a Reader input, writing results to a Writer.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.All other Reader/Writer-based escapeXml10*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeXml11
public static void escapeXml11(java.io.Reader reader, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.1 escape operation on a Reader input, writing results to a Writer.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.All other Reader/Writer-based escapeXml11*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.type
- the type of escape operation to be performed, seeXmlEscapeType
.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeXml10Attribute
public static void escapeXml10Attribute(java.io.Reader reader, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.0 escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
All other Reader/Writer-based escapeXml10*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml11Attribute
public static void escapeXml11Attribute(java.io.Reader reader, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.1 escape operation on a Reader input meant to be an XML attribute value, writing results to a Writer.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
All other Reader/Writer-based escapeXml11*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be escaped.type
- the type of escape operation to be performed, seeXmlEscapeType
.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml
private static void escapeXml(java.io.Reader reader, java.io.Writer writer, XmlEscapeSymbols symbols, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
- Throws:
java.io.IOException
-
escapeXml10Minimal
public static void escapeXml10Minimal(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a char[] input.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
This method calls
escapeXml10(char[], int, int, java.io.Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
- type:
-
escapeXml11Minimal
public static void escapeXml11Minimal(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a char[] input.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
This method calls
escapeXml10(char[], int, int, java.io.Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
- type:
-
escapeXml10AttributeMinimal
public static void escapeXml10AttributeMinimal(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 1 (only markup-significant chars) escape operation on a char[] input meant to be an XML attribute value.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(char[], int, int, java.io.Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
- type:
-
escapeXml11AttributeMinimal
public static void escapeXml11AttributeMinimal(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 1 (only markup-significant chars) escape operation on a char[] input meant to be an XML attribute value.
Level 1 means this method will only escape the five markup-significant characters which are predefined as Character Entity References in XML: <, >, &, " and '.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(char[], int, int, java.io.Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_1_ONLY_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
- type:
-
escapeXml10
public static void escapeXml10(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a char[] input.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method calls
escapeXml10(char[], int, int, java.io.Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
-
escapeXml11
public static void escapeXml11(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a char[] input.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
This method calls
escapeXml11(char[], int, int, java.io.Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
-
escapeXml10Attribute
public static void escapeXml10Attribute(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) escape operation on a char[] input meant to be an XML attribute value.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml10(char[], int, int, java.io.Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml11Attribute
public static void escapeXml11Attribute(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML 1.1 level 2 (markup-significant and all non-ASCII chars) escape operation on a char[] input meant to be an XML attribute value.
Level 2 means this method will escape:
- The five markup-significant characters: <, >, &, " and '
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding XML Character Entity References (e.g. '<') when such CER exists for the replaced character, and replacing by a hexadecimal character reference (e.g. '␰') when there there is no CER for the replaced character.
Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
This method calls
escapeXml11(char[], int, int, java.io.Writer, XmlEscapeType, XmlEscapeLevel)
with the following preconfigured values:- type:
XmlEscapeType.CHARACTER_ENTITY_REFERENCES_DEFAULT_TO_HEXA
- level:
XmlEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml10
public static void escapeXml10(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.0 escape operation on a char[] input.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.All other char[]-based escapeXml10*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs
-
escapeXml11
public static void escapeXml11(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.1 escape operation on a char[] input.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.All other char[]-based escapeXml11*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs
-
escapeXml10Attribute
public static void escapeXml10Attribute(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.0 escape operation on a char[] input meant to be an XML attribute value.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
All other char[]-based escapeXml10*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml11Attribute
public static void escapeXml11Attribute(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
Perform a (configurable) XML 1.1 escape operation on a char[] input meant to be an XML attribute value.
This method will perform an escape operation according to the specified
XmlEscapeType
andXmlEscapeLevel
argument values.Besides, being an attribute value also \t, \n and \r will be escaped to avoid white-space normalization from removing line feeds (turning them into white spaces) during future parsing operations.
All other char[]-based escapeXml11*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will be written at all to this writer if input is null.type
- the type of escape operation to be performed, seeXmlEscapeType
.level
- the escape level to be applied, seeXmlEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.5
-
escapeXml
private static void escapeXml(char[] text, int offset, int len, java.io.Writer writer, XmlEscapeSymbols symbols, XmlEscapeType type, XmlEscapeLevel level) throws java.io.IOException
- Throws:
java.io.IOException
-
unescapeXml
public static java.lang.String unescapeXml(java.lang.String text)
Perform an XML unescape operation on a String input.
No additional configuration arguments are required. Unescape operations will always perform complete XML 1.0/1.1 unescape of CERs, decimal and hexadecimal references.
This method is thread-safe.
- Parameters:
text
- the String to be unescaped.- Returns:
- The unescaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no unescaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
unescapeXml
public static void unescapeXml(java.lang.String text, java.io.Writer writer) throws java.io.IOException
Perform an XML unescape operation on a String input, writing results to a Writer.
No additional configuration arguments are required. Unescape operations will always perform complete XML 1.0/1.1 unescape of CERs, decimal and hexadecimal references.
This method is thread-safe.
- Parameters:
text
- the String to be unescaped.writer
- the java.io.Writer to which the unescaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
unescapeXml
public static void unescapeXml(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform an XML unescape operation on a Reader input, writing results to a Writer.
No additional configuration arguments are required. Unescape operations will always perform complete XML 1.0/1.1 unescape of CERs, decimal and hexadecimal references.
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to be unescaped.writer
- the java.io.Writer to which the unescaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
unescapeXml
public static void unescapeXml(char[] text, int offset, int len, java.io.Writer writer) throws java.io.IOException
Perform an XML unescape operation on a char[] input.
No additional configuration arguments are required. Unescape operations will always perform complete XML 1.0/1.1 unescape of CERs, decimal and hexadecimal references.
This method is thread-safe.
- Parameters:
text
- the char[] to be unescaped.offset
- the position in text at which the unescape operation should start.len
- the number of characters in text that should be unescaped.writer
- the java.io.Writer to which the unescaped result will be written. Nothing will be written at all to this writer if input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
-
-