public class HtmlUtil
extends java.lang.Object
Constructor and Description |
---|
HtmlUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getHtmlIcon(java.lang.String src,
java.lang.String alt)
Build an icon
|
static java.lang.String |
getHtmlIcon(java.lang.String src,
java.lang.String alt,
java.lang.String title)
Build an icon
|
static java.lang.String |
getHtmlIcon(java.lang.String src,
java.lang.String alt,
java.lang.String title,
java.lang.String css)
Build an icon
|
static java.lang.String |
html2text(java.lang.String html)
Extract all text from the specified html and returns it.
|
static java.lang.String |
truncate(java.lang.String fragmentHtml,
int maxTextLength)
Truncate the specified HTML fragment to the maximum text length specified.
|
static java.lang.String |
truncate(java.lang.String fragmentHtml,
int maxTextLength,
java.lang.String suffix)
Truncate the specified HTML fragment to the maximum text length specified.
|
public static java.lang.String truncate(java.lang.String fragmentHtml, int maxTextLength)
Important remark regarding behavior :
Specified HTML fragment is parsed using an HTML parser, thus when the HTML is
rewritten it WILL be modified according to default output rule of the parser.
Therefore line break, indentation and other whitespace may be lost during the process, but
the output should not be changed as seen from the web browser.
fragmentHtml
- the HTML fragment to truncatemaxTextLength
- the maximum length of text to keep (does not include HTML tag, comment and attribute length)public static java.lang.String truncate(java.lang.String fragmentHtml, int maxTextLength, java.lang.String suffix)
Inserting an optionnal suffix inside the block element in which text was truncated.
Important remark regarding behavior :
Specified HTML fragment is parsed using an HTML parser, thus when the HTML is
rewritten it WILL be modified according to default output rule of the parser.
Therefore line break, indentation and other whitespace may be lost during the process, but
the output should not be changed as seen from the web browser.
Example (notice the indentation and HTML compliance output):
String html = "<div><p>Hello <span>World!</span></p></div>"; String suffix = "<a href='#'> Read More...</a>"; assertEquals("<div>\n <p>Hello <span>Wo</span><a href=\"#\"> Read More...</a></p>\n</div>", HtmlUtil.truncate(html, 8, suffix));
fragmentHtml
- the HTML fragment to truncatemaxTextLength
- the maximum length of text to keep (does not include HTML tag, comment and attribute length)suffix
- a suffix to append inside the first truncated HTML nodepublic static java.lang.String html2text(java.lang.String html)
html
- the html from which text should be extractedpublic static java.lang.String getHtmlIcon(java.lang.String src, java.lang.String alt)
src
- the image sourcealt
- the iamge titlepublic static java.lang.String getHtmlIcon(java.lang.String src, java.lang.String alt, java.lang.String title)
src
- the image sourcealt
- the image alttitle
- the image titlepublic static java.lang.String getHtmlIcon(java.lang.String src, java.lang.String alt, java.lang.String title, java.lang.String css)
src
- the image sourcealt
- the image alttitle
- the image titlecss
- the css for class=""
attribute. "icon" is set by default.Copyright © 2001-2010 Jalios SA. All Rights Reserved.