Package lumis.util
Class HtmlUtil
- java.lang.Object
-
- lumis.util.HtmlUtil
-
@StableMinor(version="17.0", sinceVersion="4.0") public abstract class HtmlUtil extends java.lang.Object
Utility class for HTML decoding- Since:
- 4.0.0
- Version:
- $Revision$ $Date$
-
-
Constructor Summary
Constructors Constructor Description HtmlUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
decode(java.lang.String inputHtml)
Decodes a HTML string, replacing character references (&...;) by their corresponding characters.static java.lang.String
encode(java.lang.String inputHtml)
Encodes a HTML string, replacing extended characters by their corresponding character references.static java.lang.String
encode(java.lang.String inputHtml, boolean useEntityRefs)
Encodes a HTML string, replacing extended caracters by their corresponding character references if the parameteruseEntityRefs
istrue
static java.lang.String
fixInvalidHtmlPattern(java.lang.String inputHtml)
Parses the input HTML string, fixes any invalid HTML patterns and returns the fixed result.static boolean
isFragment(java.lang.String html)
Returns if the given HTML code is a fragment or if it contains a root html element.static void
validateJSFragmentSafety(java.lang.String jsFragment)
Validates if a javascript code fragment is safe to be injected in a page.
-
-
-
Method Detail
-
decode
public static java.lang.String decode(java.lang.String inputHtml)
Decodes a HTML string, replacing character references (&...;) by their corresponding characters.e.g: coração -> coração
For more information about HTML character references, see the section "5.3 Character references" of the HTML 4.01 Specification
- Parameters:
inputHtml
- input HTML- Returns:
- the HTML decoded
-
encode
public static java.lang.String encode(java.lang.String inputHtml)
Encodes a HTML string, replacing extended characters by their corresponding character references.e.g: coração -> coração
For more information about HTML character references, see the section "5.3 Character references" of the HTML 4.01 Specification
- Parameters:
inputHtml
- the string to be encoded.- Returns:
- the encoded string.
-
encode
public static java.lang.String encode(java.lang.String inputHtml, boolean useEntityRefs)
Encodes a HTML string, replacing extended caracters by their corresponding character references if the parameteruseEntityRefs
istrue
e.g: coração -> coração
else the replacement is done using the decimal reference
e.g: coração -> coração
For more information about HTML character references, see the section "5.3 Character references" of the HTML 4.01 Specification
- Parameters:
inputHtml
- the string to be encoded.useEntityRefs
- if HTML entities should be used during encoding.- Returns:
- the encoded string.
-
fixInvalidHtmlPattern
public static java.lang.String fixInvalidHtmlPattern(java.lang.String inputHtml)
Parses the input HTML string, fixes any invalid HTML patterns and returns the fixed result.- Parameters:
input
- HTML to be fixed- Returns:
- the fixed HTML
- Since:
- 4.1.1
-
validateJSFragmentSafety
public static void validateJSFragmentSafety(java.lang.String jsFragment)
Validates if a javascript code fragment is safe to be injected in a page. This method is to be used when javascript codes are obtained from unsecure sources, such as a HTTP request parameter.Currently this method accepts code that contains only letters, numbers, underscore or period. These can be used to represent an object reference.
- Parameters:
jsFragment
- the javascript code fragment.- Throws:
java.lang.IllegalArgumentException
- if the javascript code fragment is considered unsafe.- Since:
- 5.0.0
-
isFragment
public static boolean isFragment(java.lang.String html)
Returns if the given HTML code is a fragment or if it contains a root html element.- Parameters:
html
- the HTML code.- Returns:
true
if the given code is a fragment, orfalse
if it contains a root html element.- Since:
- 12.1.0
-
-