public class HtmlUtil
extends java.lang.Object
Constructor and Description |
---|
HtmlUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
buildData(java.util.Map<java.lang.String,java.lang.Object> data) |
static java.lang.String |
escape(java.lang.String text)
Escapes the text so that it is safe to use in an HTML context.
|
static java.lang.String |
escape(java.lang.String text,
int mode)
Escapes the input text as a hexadecimal value, based on the mode (type).
|
static java.lang.String |
escapeAttribute(java.lang.String attribute)
Escapes the attribute value so that it is safe to use as an attribute
value.
|
static java.lang.String |
escapeCSS(java.lang.String css)
Escapes the CSS value so that it is safe to use in a CSS context.
|
static java.lang.String |
escapeHREF(java.lang.String href)
Escapes the HREF attribute so that it is safe to use as an HREF
attribute.
|
static java.lang.String |
escapeJS(java.lang.String js)
Escapes the JavaScript value so that it is safe to use in a JavaScript
context.
|
static java.lang.String |
escapeJSLink(java.lang.String link) |
static java.lang.String |
escapeURL(java.lang.String url)
Escapes the URL value so that it is safe to use as a URL.
|
static java.lang.String |
escapeXPath(java.lang.String xPath) |
static java.lang.String |
escapeXPathAttribute(java.lang.String xPathAttribute) |
static 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.
|
static java.lang.String |
fromInputSafe(java.lang.String text) |
static java.lang.String |
getAUICompatibleId(java.lang.String html) |
static Html |
getHtml() |
static java.lang.String |
render(java.lang.String html)
Renders the HTML content into text.
|
static java.lang.String |
replaceMsWordCharacters(java.lang.String text)
Deprecated.
As of Wilberforce (7.0.x), with no direct replacement
|
static java.lang.String |
replaceNewLine(java.lang.String html)
Replaces all new lines or carriage returns with the
HTML tag. |
void |
setHtml(Html html) |
static java.lang.String |
stripBetween(java.lang.String text,
java.lang.String tag)
Strips all content delimited by the tag out of the text.
|
static java.lang.String |
stripComments(java.lang.String text)
Strips all XML comments out of the text.
|
static java.lang.String |
stripHtml(java.lang.String text) |
static java.lang.String |
toInputSafe(java.lang.String text)
Encodes the text so that it's safe to use as an HTML input field value.
|
static java.lang.String |
unescape(java.lang.String text) |
static java.lang.String |
unescapeCDATA(java.lang.String text) |
static java.lang.String |
wordBreak(java.lang.String text,
int columns) |
public static java.lang.String buildData(java.util.Map<java.lang.String,java.lang.Object> data)
public static java.lang.String escape(java.lang.String text)
text
- the text to escapenull
if the text is
null
public static java.lang.String escape(java.lang.String text, int mode)
text
- the text to escapemode
- the encoding typenull
if the text is null
HtmlImpl.escape(String, int)
public static java.lang.String escapeAttribute(java.lang.String attribute)
attribute
- the attribute to escapenull
if the
attribute value is null
public static java.lang.String escapeCSS(java.lang.String css)
css
- the CSS value to escapenull
if the CSS value is
null
public static java.lang.String escapeHREF(java.lang.String href)
href
- the HREF attribute to escapenull
if the HREF
attribute is null
public static java.lang.String escapeJS(java.lang.String js)
js
- the JavaScript value to escapenull
if the
JavaScript value is null
public static java.lang.String escapeJSLink(java.lang.String link)
public static java.lang.String escapeURL(java.lang.String url)
url
- the URL value to escapenull
if the URL value is
null
public static java.lang.String escapeXPath(java.lang.String xPath)
public static java.lang.String escapeXPathAttribute(java.lang.String xPathAttribute)
public static java.lang.String extractText(java.lang.String html)
For example, raw text returned by this method can be stored in a search index.
html
- the HTML textnull
if the
HTML input is null
public static java.lang.String fromInputSafe(java.lang.String text)
public static java.lang.String getAUICompatibleId(java.lang.String html)
public static Html getHtml()
public static 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.
html
- the HTML textnull
if the HTML text is
null
@Deprecated public static java.lang.String replaceMsWordCharacters(java.lang.String text)
text
- the textnull
if the text is
null
public static java.lang.String replaceNewLine(java.lang.String html)
HTML tag.html
- the textnull
if the HTML text is
null
public static 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.
text
- the texttag
- the tag used for delimiting, which should only be the tag's
name (e.g. no <)null
if the text is null
public static java.lang.String stripComments(java.lang.String text)
text
- the textnull
if the text is null
public static java.lang.String stripHtml(java.lang.String text)
public static java.lang.String toInputSafe(java.lang.String text)
For example, the &
character is replaced by
&
.
text
- the textnull
if the text is null
public static java.lang.String unescape(java.lang.String text)
public static java.lang.String unescapeCDATA(java.lang.String text)
public static java.lang.String wordBreak(java.lang.String text, int columns)
public void setHtml(Html html)