Enum XmlEscapeLevel
- All Implemented Interfaces:
Serializable
,Comparable<XmlEscapeLevel>
,java.lang.constant.Constable
Levels defined for XML escape/unescape operations:
- Level 1: Escape only markup-significant characters (all five XML predefined entities). Therefore <, >, &, " and ' will be escaped. This level is safe for use in texts and also XML tag attributes (tag attributes are always quoted in XML). Note the result of a level-1 escape operation might still contain non-ASCII characters if they existed in input, and therefore you will still need to correctly manage your input/output character encoding settings.
- Level 2: Escape all markup-significant characters (as defined in level 1), plus all non-ASCII characters. The result of a level-2 escape operation is therefore always ASCII-only text, and safer to use in complex scenarios with mixed input/output character encodings. This level is safe for use in texts and also XML tag attributes (tag attributes are always quoted in XML).
- Level 3: Escape all non-alphanumeric characters, this is, all but those in the A-Z, a-z and 0-9 ranges. This level can be safely used for completely escaping texts, including whitespace, line feeds, punctuation, etc. in scenarios where this adds an extra level of safety.
- Level 4: Escape all characters, even alphanumeric ones.
Note that, apart from the settings established by each of these levels, different XML versions might establish the required escaping of a series of control characteres (basically, all the allowed ones). These control character will be always escaped, from level 1. Besides, some characters considered invalid in such versions of XML might be directly removed from output.
Also note that no level 0 exists, in order to keep consistency with HTML escape levels defined in
HtmlEscapeLevel
.
For further information, see the Glossary and the References sections at the
documentation for the XmlEscape
class.
- Since:
- 1.0.0
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionLevel 1 escape: escape only markup-significant characters (all five XML predefined entities): <, >, &, " and 'Level 2 escape: escape markup-significant characters plus all non-ASCII characters (result will always be ASCII).Level 3 escape: escape all non-alphanumeric characteres (escape all but those in the A-Z, a-z and 0-9 ranges).Level 4 escape: escape all characters, including alphanumeric. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic XmlEscapeLevel
forLevel
(int level) Utility method for obtaining an enum value from its corresponding int level value.int
Return the int escape level.static XmlEscapeLevel
Returns the enum constant of this type with the specified name.static XmlEscapeLevel[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
LEVEL_1_ONLY_MARKUP_SIGNIFICANT
Level 1 escape: escape only markup-significant characters (all five XML predefined entities): <, >, &, " and ' -
LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
Level 2 escape: escape markup-significant characters plus all non-ASCII characters (result will always be ASCII). -
LEVEL_3_ALL_NON_ALPHANUMERIC
Level 3 escape: escape all non-alphanumeric characteres (escape all but those in the A-Z, a-z and 0-9 ranges). -
LEVEL_4_ALL_CHARACTERS
Level 4 escape: escape all characters, including alphanumeric.
-
-
Field Details
-
escapeLevel
private final int escapeLevel
-
-
Constructor Details
-
XmlEscapeLevel
private XmlEscapeLevel(int escapeLevel)
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
forLevel
Utility method for obtaining an enum value from its corresponding int level value.
- Parameters:
level
- the level- Returns:
- the escape level enum constant, or IllegalArgumentException if level does not exist.
-
getEscapeLevel
public int getEscapeLevel()Return the int escape level.- Returns:
- the escape level.
-