Package org.unbescape.html
Enum HtmlEscapeLevel
- Object
-
- Enum<HtmlEscapeLevel>
-
- org.unbescape.html.HtmlEscapeLevel
-
- All Implemented Interfaces:
java.io.Serializable
,Comparable<HtmlEscapeLevel>
public enum HtmlEscapeLevel extends Enum<HtmlEscapeLevel>
Levels defined for HTML escape/unescape operations:
- Level 0: Escape only markup-significant characters, excluding the apostrophe. Therefore <, >, & and " will be escaped. This level can be used for escaping texts and also tag attributes that are always surrounded by double quotes, whenever the apostrophe (') is considered a safe character and the user prefers it not to be escaped for legibility reasons (e.g. might denote literals in expression languages like OGNL). Note the result of a level-0 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 1: Escape only markup-significant characters (including the apostrophe). Therefore <, >, &, " and ' will be escaped. This level is sometimes called XML escape or XML-style escape, though it is not exactly equivalent to XML due to some HTML specificities. It is equivalent to the JSP escape configured by the escapeXml attribute in JSTL's <c:out ... /> tags, and safe for use in texts and also tag attributes that are always quoted —be it with single (apostrophe) or double quotes. 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 can be used for escaping texts and also tag attributes that are always quoted —be it with single (apostrophe) or double quotes.
- 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 escaping texts and also tag attributes, even when these tag attributes are unquoted.
- Level 4: Escape all characters, even alphanumeric ones.
For further information, see the Glossary and the References sections at the documentation for the
HtmlEscape
class.- Since:
- 1.0.0
- Author:
- Daniel Fernández
-
-
Enum Constant Summary
Enum Constants Enum Constant Description LEVEL_0_ONLY_MARKUP_SIGNIFICANT_EXCEPT_APOS
Level 0 escape: escape only markup-significant characters, excluding the apostrophe: <, >, & and "LEVEL_1_ONLY_MARKUP_SIGNIFICANT
Level 1 escape (XML-style): escape only markup-significant characters (including the apostrophe): <, >, &, " 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HtmlEscapeLevel
forLevel(int level)
Utility method for obtaining an enum value from its corresponding int level value.int
getEscapeLevel()
Return the int escape level.static HtmlEscapeLevel
valueOf(String name)
Returns the enum constant of this type with the specified name.static HtmlEscapeLevel[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
LEVEL_0_ONLY_MARKUP_SIGNIFICANT_EXCEPT_APOS
public static final HtmlEscapeLevel LEVEL_0_ONLY_MARKUP_SIGNIFICANT_EXCEPT_APOS
Level 0 escape: escape only markup-significant characters, excluding the apostrophe: <, >, & and "
-
LEVEL_1_ONLY_MARKUP_SIGNIFICANT
public static final HtmlEscapeLevel LEVEL_1_ONLY_MARKUP_SIGNIFICANT
Level 1 escape (XML-style): escape only markup-significant characters (including the apostrophe): <, >, &, " and '
-
LEVEL_2_ALL_NON_ASCII_PLUS_MARKUP_SIGNIFICANT
public static final HtmlEscapeLevel 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
public static final HtmlEscapeLevel 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
public static final HtmlEscapeLevel LEVEL_4_ALL_CHARACTERS
Level 4 escape: escape all characters, including alphanumeric.
-
-
Method Detail
-
values
public static HtmlEscapeLevel[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (HtmlEscapeLevel c : HtmlEscapeLevel.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static HtmlEscapeLevel valueOf(String name)
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
public static HtmlEscapeLevel forLevel(int level)
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.
-
-