|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.util.HtmlToText
Generates a best-guess plain text version of an HTML fragment. Parses the HTML and does some simple formatting. The parser and formatting are pretty stupid, but it's better than nothing.
Based on the ACS 4.0 Tcl conversion routines by Lars Pind and Aaron Swartz. In fact, its a direct port of that code to Java with very few changes.
Intended usage is allocate an HtmlToText object statically and then reuse it by calling its convert method. The class is not thread-safe for simultaneous access, so you should synchronize on your conversion object if collisions are possible.
Example:
static HtmlToText htmlToText = new HtmlToText(); synchronize(htmlToText) { String html = htmlToText.convert(text); }
Constructor Summary | |
HtmlToText()
Constructor. |
Method Summary | |
String |
convert(String input)
Convert HTML input to plain text output. |
static String |
generateHTMLText(String text,
String formatType)
Returns HTML text, converted from the following: HTML -- returns the input pre-formatted - returns the input wrapped in <pre> tags plain - returns the input converted to HTML. |
void |
setMaxLength(int maxlen)
Sets the maximum line length for wrapping text. |
void |
setShowTags(boolean showtags)
Sets the flags for whether unrecognized HTML tags are copied to the output. |
String |
toString()
Returns the last converted text block as a String. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public HtmlToText()
Method Detail |
public void setMaxLength(int maxlen)
maxlen
- the maximum number of character in an output
line.public void setShowTags(boolean showtags)
public String toString()
public String convert(String input)
public static String generateHTMLText(String text, String formatType)
formatType
- one of the types defined in MessageType.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |