Package org.apache.maven.doxia.util
Class HtmlTools
- java.lang.Object
-
- org.apache.maven.doxia.util.HtmlTools
-
public class HtmlTools extends java.lang.ObjectTheHtmlToolsclass defines methods to HTML handling.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private static javax.swing.text.html.HTML.Tag[]ALL_TAGSprivate static intASCIIprivate static charLOW_SURROGATEprivate static charLUNATE_SIGMAprivate static intMAX_CODE_POINTprivate static charMAX_HIGH_SURROGATEprivate static intMIN_CODE_POINTprivate static charMIN_HIGH_SURROGATEprivate static intMIN_SUPPLEMENTARY_CODE_POINTprivate static charNON_PRIVATE_USE_HIGH_SURROGATEprivate static java.util.Map<java.lang.String,javax.swing.text.html.HTML.Tag>TAG_MAP
-
Constructor Summary
Constructors Modifier Constructor Description privateHtmlTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringencodeId(java.lang.String id)Construct a valid id.static java.lang.StringencodeURL(java.lang.String url)Encode an urlstatic java.lang.StringescapeHTML(java.lang.String text)Escape special HTML characters in a String inxmlmode.static java.lang.StringescapeHTML(java.lang.String text, boolean xmlMode)Escape special HTML characters in a String.static javax.swing.text.html.HTML.TaggetHtmlTag(java.lang.String tagName)Returns a tag for a defined HTML tag name.private static booleanisHighSurrogate(char ch)static booleanisId(java.lang.String text)Determines if the specified text is a valid id according to the rules laid out inencodeId(String).private static booleanisSupplementaryCodePoint(int codePoint)private static booleanisValidCodePoint(int codePoint)static char[]toChars(int codePoint)Converts the given code point to an equivalent character array.private static inttoCodePoint(char high, char low)static java.lang.StringunescapeHTML(java.lang.String text)Unescapes HTML entities in a string in non xml mode.static java.lang.StringunescapeHTML(java.lang.String text, boolean xmlMode)Unescapes HTML entities in a string.
-
-
-
Field Detail
-
ALL_TAGS
private static final javax.swing.text.html.HTML.Tag[] ALL_TAGS
-
TAG_MAP
private static final java.util.Map<java.lang.String,javax.swing.text.html.HTML.Tag> TAG_MAP
-
ASCII
private static final int ASCII
- See Also:
- Constant Field Values
-
LUNATE_SIGMA
private static final char LUNATE_SIGMA
- See Also:
- Constant Field Values
-
NON_PRIVATE_USE_HIGH_SURROGATE
private static final char NON_PRIVATE_USE_HIGH_SURROGATE
- See Also:
- Constant Field Values
-
LOW_SURROGATE
private static final char LOW_SURROGATE
- See Also:
- Constant Field Values
-
MIN_HIGH_SURROGATE
private static final char MIN_HIGH_SURROGATE
- See Also:
- Constant Field Values
-
MAX_HIGH_SURROGATE
private static final char MAX_HIGH_SURROGATE
- See Also:
- Constant Field Values
-
MIN_CODE_POINT
private static final int MIN_CODE_POINT
- See Also:
- Constant Field Values
-
MAX_CODE_POINT
private static final int MAX_CODE_POINT
- See Also:
- Constant Field Values
-
MIN_SUPPLEMENTARY_CODE_POINT
private static final int MIN_SUPPLEMENTARY_CODE_POINT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getHtmlTag
public static javax.swing.text.html.HTML.Tag getHtmlTag(java.lang.String tagName)
Returns a tag for a defined HTML tag name. This is one of the tags defined inHtmlMarkup. If the given name does not represent one of the defined tags, thennullwill be returned.- Parameters:
tagName- theStringname requested.- Returns:
- a tag constant corresponding to the
tagName, ornullif not found. - Since:
- 1.1
- See Also:
- http://www.w3.org/TR/html401/index/elements.html
-
escapeHTML
public static java.lang.String escapeHTML(java.lang.String text)
Escape special HTML characters in a String inxmlmode. Note: this method doesn't escape non-ascii characters by numeric characters references.- Parameters:
text- the String to escape, may be null.- Returns:
- The escaped text or the empty string if text == null.
- See Also:
escapeHTML(String,boolean)
-
escapeHTML
public static java.lang.String escapeHTML(java.lang.String text, boolean xmlMode)Escape special HTML characters in a String.< becomes
If<> becomes>& becomes&" becomes"' becomes'if xmlMode = truexmlModeis true, every other character than the above remains unchanged, ifxmlModeis false, non-ascii characters get replaced by their hex code. Note: all characters are encoded, i.e.:ř = ř 𝟭 = 𝟭
- Parameters:
text- The String to escape, may be null.xmlMode-trueto replace also ' to &apos,falseto replace non-ascii characters by numeric characters references.- Returns:
- The escaped text or the empty string if text == null.
- Since:
- 1.1
- See Also:
- http://www.w3.org/TR/2000/REC-xml-20001006#sec-predefined-ent, http://www.w3.org/TR/html401/charset.html#h-5.3
-
unescapeHTML
public static java.lang.String unescapeHTML(java.lang.String text)
Unescapes HTML entities in a string in non xml mode.- Parameters:
text- theStringto unescape, may be null.- Returns:
- a new unescaped
String,nullif null string input. - Since:
- 1.1.1.
- See Also:
unescapeHTML(String, boolean)
-
unescapeHTML
public static java.lang.String unescapeHTML(java.lang.String text, boolean xmlMode)Unescapes HTML entities in a string.Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.
For example, the string "<Français>" will become "<Français>".
Note: all unicode entities are decoded, i.e.:ř = ř 𝟭 = 𝟭
- Parameters:
text- theStringto unescape, may be null.xmlMode- set totrueto replace &apos by '.- Returns:
- a new unescaped
String,nullif null string input. - Since:
- 1.1.1.
-
encodeURL
public static java.lang.String encodeURL(java.lang.String url)
Encode an url- Parameters:
url- the String to encode, may be null- Returns:
- the text encoded, null if null String input
-
encodeId
public static java.lang.String encodeId(java.lang.String id)
Construct a valid id.Note: this method is identical to
DoxiaUtils.encodeId( id, false ), the rules to encode an id are laid out there.- Parameters:
id- The id to be encoded.- Returns:
- The trimmed and encoded id, or null if id is null.
- See Also:
DoxiaUtils.encodeId(java.lang.String,boolean)
-
isId
public static boolean isId(java.lang.String text)
Determines if the specified text is a valid id according to the rules laid out inencodeId(String).- Parameters:
text- The text to be tested.- Returns:
trueif the text is a valid id, otherwisefalse.- See Also:
DoxiaUtils.isValidId(String)
-
toCodePoint
private static int toCodePoint(char high, char low)
-
isHighSurrogate
private static boolean isHighSurrogate(char ch)
-
isValidCodePoint
private static boolean isValidCodePoint(int codePoint)
-
isSupplementaryCodePoint
private static boolean isSupplementaryCodePoint(int codePoint)
-
toChars
public static char[] toChars(int codePoint)
Converts the given code point to an equivalent character array.- Parameters:
codePoint- the code point to convert.- Returns:
- If codePoint is a supplementary code point, returns a character array of length 2, otherwise a character array of length 1 containing only the original int as a char.
-
-