com.atlassian.confluence.util
Class HtmlUtil

java.lang.Object
  extended by com.atlassian.confluence.util.HtmlUtil

public final class HtmlUtil
extends Object


Field Summary
static com.google.common.base.Function<String,String> HTML_ENCODE_FUNCTION
          Function to apply htmlEncode(String).
 
Constructor Summary
HtmlUtil()
           
 
Method Summary
static String completeUrlEncode(String url)
          Encodes the given url for protocols which the CompleteURLEncoder supports.
static String htmlEncode(String text)
          Encodes the given text to be HTML safe using entity escapes.
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.
static String reencodeURL(String originalUrl)
          Attempts to handle common encoding errors in hand-edited URLs, such as failing to URL encode quotes.
static boolean shouldUrlDecode(String text)
          Checks if the given text should contains any percent encoded characters that should be decoded.
static String urlDecode(String url)
          Decodes URL percent encoded characters, using the character encoding as per GeneralUtil.getCharacterEncoding().
static String urlDecode(String url, String encoding)
          Decodes URL percent encoded characters.
static String urlEncode(String text)
          Encodes HTTP form parameter/values, using the character encoding as per GeneralUtil.getCharacterEncoding().
static String urlEncode(String text, String encoding)
          Encodes HTTP form parameter/values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTML_ENCODE_FUNCTION

public static final com.google.common.base.Function<String,String> HTML_ENCODE_FUNCTION
Function to apply htmlEncode(String).

Constructor Detail

HtmlUtil

public HtmlUtil()
Method Detail

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 the CompleteURLEncoder supports. To only encode HTTP form parameter/values or fragments, use urlEncode(String) instead. Uses the character encoding as per GeneralUtil.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 per GeneralUtil.getCharacterEncoding(). To encode entire URLs, use completeUrlEncode(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, use completeUrlEncode(java.lang.String) instead.

Parameters:
text - part of the url to encode
encoding - 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 per GeneralUtil.getCharacterEncoding().

Parameters:
url - the URL to decode
Returns:
the decoded string

urlDecode

public static String urlDecode(String url,
                               String encoding)
                        throws UnsupportedEncodingException
Decodes URL percent encoded characters.

Parameters:
url - the URL to decode
encoding - the character encoding to use while decoding
Returns:
the decoded string
Throws:
UnsupportedEncodingException

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

reencodeURL

public static String reencodeURL(String originalUrl)
Attempts to handle common encoding errors in hand-edited URLs, such as failing to URL encode quotes.

Parameters:
originalUrl - the url to re-encode.
Returns:
the re-encoded URL, or the original value if it cannot be


Copyright © 2003–2015 Atlassian. All rights reserved.