public class HtmlImpl
extends java.lang.Object
implements com.liferay.portal.kernel.util.Html
| Modifier and Type | Field and Description |
|---|---|
static int |
ESCAPE_MODE_ATTRIBUTE |
static int |
ESCAPE_MODE_CSS |
static int |
ESCAPE_MODE_JS |
static int |
ESCAPE_MODE_TEXT |
static int |
ESCAPE_MODE_URL |
| Constructor and Description |
|---|
HtmlImpl() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
buildData(java.util.Map<java.lang.String,java.lang.Object> data)
Generates a string with the data-* attributes generated from the keys and
values of a map.
|
java.lang.String |
escape(java.lang.String text)
Escapes the text so that it is safe to use in an HTML context.
|
java.lang.String |
escape(java.lang.String text,
int mode)
Escapes the input text as a hexadecimal value, based on the mode (type).
|
java.lang.String |
escapeAttribute(java.lang.String attribute)
Escapes the attribute value so that it is safe to use as an attribute
value.
|
java.lang.String |
escapeCSS(java.lang.String css)
Escapes the CSS value so that it is safe to use in a CSS context.
|
java.lang.String |
escapeHREF(java.lang.String href)
Escapes the HREF attribute so that it is safe to use as an HREF
attribute.
|
java.lang.String |
escapeJS(java.lang.String js)
Escapes the JavaScript value so that it is safe to use in a JavaScript
context.
|
java.lang.String |
escapeJSLink(java.lang.String link) |
java.lang.String |
escapeURL(java.lang.String url)
Escapes the URL value so that it is safe to use as a URL.
|
java.lang.String |
escapeXPath(java.lang.String xPath) |
java.lang.String |
escapeXPathAttribute(java.lang.String xPathAttribute) |
java.lang.String |
extractText(java.lang.String html)
Extracts the raw text from the HTML input, compressing its whitespace and
removing all attributes, scripts, and styles.
|
java.lang.String |
fromInputSafe(java.lang.String text) |
java.lang.String |
getAUICompatibleId(java.lang.String text) |
protected boolean |
isTag(char[] tag,
java.lang.String text,
int pos) |
java.lang.String |
render(java.lang.String html)
Renders the HTML content into text.
|
java.lang.String |
replaceMsWordCharacters(java.lang.String text)
Deprecated.
As of 7.0.0, with no direct replacement
|
java.lang.String |
replaceNewLine(java.lang.String html)
Replaces all new lines or carriage returns with the
HTML tag. |
java.lang.String |
stripBetween(java.lang.String text,
java.lang.String tag)
Strips all content delimited by the tag out of the text.
|
java.lang.String |
stripComments(java.lang.String text)
Strips all XML comments out of the text.
|
java.lang.String |
stripHtml(java.lang.String text) |
protected int |
stripTag(char[] tag,
java.lang.String text,
int pos) |
java.lang.String |
toInputSafe(java.lang.String text)
Encodes the text so that it's safe to use as an HTML input field value.
|
java.lang.String |
unescape(java.lang.String text) |
java.lang.String |
unescapeCDATA(java.lang.String text) |
java.lang.String |
wordBreak(java.lang.String text,
int columns) |
public static final int ESCAPE_MODE_ATTRIBUTE
public static final int ESCAPE_MODE_CSS
public static final int ESCAPE_MODE_JS
public static final int ESCAPE_MODE_TEXT
public static final int ESCAPE_MODE_URL
public java.lang.String buildData(java.util.Map<java.lang.String,java.lang.Object> data)
{key1=value1;key2=value2} is returned as the string
data-key1=value1 data-key2=value2.buildData in interface com.liferay.portal.kernel.util.Htmldata - the map of values to convert to data-* attributesnull if the
map is nullpublic java.lang.String escape(java.lang.String text)
escape in interface com.liferay.portal.kernel.util.Htmltext - the text to escapenull if the text is
nullpublic java.lang.String escape(java.lang.String text,
int mode)
ESCAPE_MODE_ATTRIBUTE, ESCAPE_MODE_CSS, ESCAPE_MODE_JS, ESCAPE_MODE_TEXT,
and ESCAPE_MODE_URL.
Note that escape(text, ESCAPE_MODE_TEXT) returns the same as
escape(text).
escape in interface com.liferay.portal.kernel.util.Htmltext - the text to escapemode - the encoding typenull if the text is nullpublic java.lang.String escapeAttribute(java.lang.String attribute)
escapeAttribute in interface com.liferay.portal.kernel.util.Htmlattribute - the attribute to escapenull if the
attribute value is nullpublic java.lang.String escapeCSS(java.lang.String css)
escapeCSS in interface com.liferay.portal.kernel.util.Htmlcss - the CSS value to escapenull if the CSS value is
nullpublic java.lang.String escapeHREF(java.lang.String href)
escapeHREF in interface com.liferay.portal.kernel.util.Htmlhref - the HREF attribute to escapenull if the HREF
attribute is nullpublic java.lang.String escapeJS(java.lang.String js)
escapeJS in interface com.liferay.portal.kernel.util.Htmljs - the JavaScript value to escapenull if the
JavaScript value is nullpublic java.lang.String escapeJSLink(java.lang.String link)
escapeJSLink in interface com.liferay.portal.kernel.util.Htmlpublic java.lang.String escapeURL(java.lang.String url)
escapeURL in interface com.liferay.portal.kernel.util.Htmlurl - the URL value to escapenull if the URL value is
nullpublic java.lang.String escapeXPath(java.lang.String xPath)
escapeXPath in interface com.liferay.portal.kernel.util.Htmlpublic java.lang.String escapeXPathAttribute(java.lang.String xPathAttribute)
escapeXPathAttribute in interface com.liferay.portal.kernel.util.Htmlpublic java.lang.String extractText(java.lang.String html)
For example, raw text returned by this method can be stored in a search index.
extractText in interface com.liferay.portal.kernel.util.Htmlhtml - the HTML textnull if the
HTML input is nullpublic java.lang.String fromInputSafe(java.lang.String text)
fromInputSafe in interface com.liferay.portal.kernel.util.Htmlpublic java.lang.String getAUICompatibleId(java.lang.String text)
getAUICompatibleId in interface com.liferay.portal.kernel.util.Htmlpublic java.lang.String render(java.lang.String html)
Using the default settings, the output complies with the
Text/Plain; Format=Flowed (DelSp=No) protocol described in
RFC-3676.
render in interface com.liferay.portal.kernel.util.Htmlhtml - the HTML textnull if the HTML text is
null@Deprecated public java.lang.String replaceMsWordCharacters(java.lang.String text)
replaceMsWordCharacters in interface com.liferay.portal.kernel.util.Htmltext - the textnull if the text is
nullpublic java.lang.String replaceNewLine(java.lang.String html)
HTML tag.replaceNewLine in interface com.liferay.portal.kernel.util.Htmlhtml - the textnull if the text is
nullpublic java.lang.String stripBetween(java.lang.String text,
java.lang.String tag)
If the tag appears multiple times, all occurrences (including the tag) are stripped. The tag may have attributes. In order for this method to recognize the tag, it must consist of a separate opening and closing tag. Self-closing tags remain in the result.
stripBetween in interface com.liferay.portal.kernel.util.Htmltext - the texttag - the tag used for delimiting, which should only be the tag's
name (e.g. no <)null if the text is nullpublic java.lang.String stripComments(java.lang.String text)
stripComments in interface com.liferay.portal.kernel.util.Htmltext - the textnull
if the text is nullpublic java.lang.String stripHtml(java.lang.String text)
stripHtml in interface com.liferay.portal.kernel.util.Htmlpublic java.lang.String toInputSafe(java.lang.String text)
For example, the & character is replaced by
&.
toInputSafe in interface com.liferay.portal.kernel.util.Htmltext - the textnull if the text is nullpublic java.lang.String unescape(java.lang.String text)
unescape in interface com.liferay.portal.kernel.util.Htmlpublic java.lang.String unescapeCDATA(java.lang.String text)
unescapeCDATA in interface com.liferay.portal.kernel.util.Htmlpublic java.lang.String wordBreak(java.lang.String text,
int columns)
wordBreak in interface com.liferay.portal.kernel.util.Htmlprotected boolean isTag(char[] tag,
java.lang.String text,
int pos)
protected int stripTag(char[] tag,
java.lang.String text,
int pos)