Package com.atlassian.confluence.util
Class HtmlUtil
- java.lang.Object
-
- com.atlassian.confluence.util.HtmlUtil
-
public final class HtmlUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static com.google.common.base.Function<String,String>HTML_ENCODE_FUNCTIONDeprecated, for removal: This API element is subject to removal in a future version.since 8.6.0.static HtmlUtilINSTANCE
-
Constructor Summary
Constructors Constructor Description HtmlUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcompleteUrlEncode(String url)Encodes the given url for protocols which theCompleteURLEncodersupports.static StringhtmlEncode(Object object)Encodes the given Object to be HTML safe using entity escapes.static StringhtmlEncode(String text)Encodes the given text to be HTML safe using entity escapes.static StringhtmlEncodeAndReplaceSpaces(String text)Encodes the given text to be HTML safe using entity escapes, and embedding non-breaking spaces in place of spaces.static StringreencodeURL(String originalUrl)Attempts to handle common encoding errors in hand-edited URLs, such as failing to URL encode quotes.static booleanshouldUrlDecode(String text)Checks if the given text should contains any percent encoded characters that should be decoded.static StringurlDecode(String url)Decodes URL percent encoded characters, using the character encoding as perGeneralUtil.getCharacterEncoding().static StringurlDecode(String url, String encoding)Decodes URL percent encoded characters.static StringurlEncode(String text)Encodes HTTP form parameter/values, using the character encoding as perGeneralUtil.getCharacterEncoding().static StringurlEncode(String text, String encoding)Encodes HTTP form parameter/values.
-
-
-
Field Detail
-
INSTANCE
public static final HtmlUtil INSTANCE
-
HTML_ENCODE_FUNCTION
@Deprecated(forRemoval=true) public static final com.google.common.base.Function<String,String> HTML_ENCODE_FUNCTION
Deprecated, for removal: This API element is subject to removal in a future version.since 8.6.0. UsehtmlEncode(String)directly.Function to applyhtmlEncode(String).
-
-
Method Detail
-
htmlEncode
public static String htmlEncode(Object object)
Encodes the given Object to be HTML safe using entity escapes. If the object is a number, returns the string it in string format If the object is a string, returns htmlEncoded string For everything else returns an empty string- Parameters:
object- the object to encode.- Returns:
- the encoded text.
-
htmlEncode
public static String htmlEncode(String text)
Encodes the given text to be HTML safe using entity escapes.- Parameters:
text- the text to encode.- Returns:
- the encoded text.
-
htmlEncodeAndReplaceSpaces
public static String htmlEncodeAndReplaceSpaces(String text)
Encodes the given text to be HTML safe using entity escapes, and embedding non-breaking spaces in place of spaces.- Parameters:
text- the text to encode.- Returns:
- the encoded text.
-
completeUrlEncode
public static String completeUrlEncode(String url)
Encodes the given url for protocols which theCompleteURLEncodersupports. To only encode HTTP form parameter/values or fragments, useurlEncode(String)instead. Uses the character encoding as perGeneralUtil.getCharacterEncoding().- Parameters:
url- the entire URL to encode- Returns:
- encoded url
- Since:
- 5.3.3
-
urlEncode
public static String urlEncode(String text)
Encodes HTTP form parameter/values, using the character encoding as perGeneralUtil.getCharacterEncoding(). To encode entire URLs, usecompleteUrlEncode(java.lang.String)instead.- Parameters:
text- part of the url to encode- Returns:
- encoded url
- Since:
- 5.3.3
-
urlEncode
public static String urlEncode(String text, String encoding)
Encodes HTTP form parameter/values. To encode entire URLs, usecompleteUrlEncode(java.lang.String)instead.- Parameters:
text- part of the url to encodeencoding- the character encoding to use- Returns:
- encoded url
- Since:
- 5.3.3
-
urlDecode
public static String urlDecode(String url)
Decodes URL percent encoded characters, using the character encoding as perGeneralUtil.getCharacterEncoding().- Parameters:
url- the URL to decode- Returns:
- the decoded string
-
urlDecode
public static String urlDecode(String url, String encoding)
Decodes URL percent encoded characters.- Parameters:
url- the URL to decodeencoding- the character encoding to use while decoding- Returns:
- the decoded string
-
shouldUrlDecode
public static boolean shouldUrlDecode(String text)
Checks if the given text should contains any percent encoded characters that should be decoded.- Parameters:
text- the text to check- Returns:
- true, if the text should be decoded
-
-