|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jalios.util.HtmlUtil
public class HtmlUtil
Html manipulation methods.
Constructor Summary | |
---|---|
HtmlUtil()
|
Method Summary | |
---|---|
static String |
getHtmlIcon(String src,
String alt)
Build an icon |
static String |
getHtmlIcon(String src,
String alt,
String title)
Build an icon |
static String |
getHtmlIcon(String src,
String alt,
String title,
String css)
Build an icon |
static String |
html2text(String html)
Extract all text from the specified html and returns it. |
static String |
truncate(String fragmentHtml,
int maxTextLength)
Truncate the specified HTML fragment to the maximum text length specified. |
static String |
truncate(String fragmentHtml,
int maxTextLength,
String suffix)
Truncate the specified HTML fragment to the maximum text length specified. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HtmlUtil()
Method Detail |
---|
public static String truncate(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 String truncate(String fragmentHtml, int maxTextLength, 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 node
public static String html2text(String html)
html
- the html from which text should be extracted
public static String getHtmlIcon(String src, String alt)
src
- the image sourcealt
- the iamge title
public static String getHtmlIcon(String src, String alt, String title)
src
- the image sourcealt
- the image alttitle
- the image title
public static String getHtmlIcon(String src, String alt, String title, String css)
src
- the image sourcealt
- the image alttitle
- the image titlecss
- the css for class=""
attribute. "icon" is set by default.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |