| java.lang.Object org.columba.mail.parser.text.HtmlParser
HtmlParser | final public class HtmlParser (Code) | | Contains different utility functions for manipulating Html based
text. This includes functionality for removing and restoring
special entities (such as &, <, >, ...) and functionality for
removing html tags from the text.
author: Karl Peder Olesen (karlpeder), 20030623 |
Method Summary | |
public static String | getHtmlBody(String html) Extracts the body of a html document, i.e. | public static Charset | getHtmlCharset(String htmlSource) | public static String | htmlToText(String html) Strips html tags. | public static String | removeComments(String html) Parses a html documents and removes all html comments found. | public static String | restoreSpecialCharacters(Charset charset, String s) Performs in large terms the reverse of
substituteSpecialCharacters (though br tags are not
converted to newlines, this should be handled separately).
More preciesly it changes special entities like
amp, nbsp etc. | public static String | stripHtmlTags(String s) Strips html tags and removes extra spaces which occurs due
to e.g. | public static String | stripHtmlTags(String s, boolean breakToNl) Strips html tags. | public static String | substituteEmailAddress(String s) | public static String | substituteEmailAddress(String s, boolean ignoreLinks) Transforms email-addresses into HTML just as
substituteEmailAddress(String), but tries to ignore email-addresses,
which are already links, if the ignore links flag is set.
This extended functionality is necessary when parsing a text which
is already (partly) html.
FIXME: Can this be done smarter, i.e. | public static String | substituteSpecialCharacters(String s) | public static String | substituteSpecialCharactersInHeaderfields(String s) substitute special characters like:
<,>,&,\t,\n
with special entities used in html
This is the same as substituteSpecialCharacters, but
here an extra newline character is not inserted. | public static String | substituteURL(String s) | public static String | substituteURL(String s, boolean ignoreLinks) Transforms urls into HTML just as substituteURL(String),
but tries to ignore urls, which are already links, if the ignore
links flag is set.
This extended functionality is necessary when parsing a text which
is already (partly) html.
FIXME: Can this be done smarter, i.e. | public static String | textToHtml(String text, String title, String css, String charset) Replaces special chars - <,>,&,\t,\n," - with the special
entities used in html (amp, nbsp, ...). | public static String | validateHTMLString(String input) Tries to fix broken html-strings by inserting
html start- and end tags if missing, and by
removing content after the html end tag. |
getHtmlBody | public static String getHtmlBody(String html)(Code) | | Extracts the body of a html document, i.e. the html contents
between (and not including) body start and end tags.
Parameters: html - The html document to extract the body from The body of the html document author: Karl Peder Olesen (karlpeder) |
htmlToText | public static String htmlToText(String html)(Code) | | Strips html tags. and replaces special entities with their
"normal" counter parts, e.g. > => > .
Calling this method is the same as calling first stripHtmlTags
and then restoreSpecialCharacters.
Parameters: html - input string output without html tags and special entities(null on error) author: karlpeder, 20030623 author: (moved from org.columba.mail.parser.text.BodyTextParser) |
removeComments | public static String removeComments(String html)(Code) | | Parses a html documents and removes all html comments found.
Parameters: html - The html document Html document without comments author: Karl Peder Olesen (karlpeder) |
restoreSpecialCharacters | public static String restoreSpecialCharacters(Charset charset, String s)(Code) | | Performs in large terms the reverse of
substituteSpecialCharacters (though br tags are not
converted to newlines, this should be handled separately).
More preciesly it changes special entities like
amp, nbsp etc. to their real counter parts: &, space etc.
This includes transformation of special (language specific) chars
such as the Danish ? ? ? ? ? ?.
Parameters: s - input string output with special entities replaced with their"real" counter parts (null on error) author: karlpeder, 20030623 author: (moved from org.columba.mail.gui.message.util.DocumentParser) |
stripHtmlTags | public static String stripHtmlTags(String s)(Code) | | Strips html tags and removes extra spaces which occurs due
to e.g. indentation of the html and the head section, which does
not contain any textual information.
The conversion rutine does the following:
1. Removes the header from the html file, i.e. everything from
the html tag until and including the starting body tag.
2. Replaces multiple consecutive whitespace characters with a single
space (since extra whitespace should be ignored in html).
3. Replaces ending br tags with a single newline character
4. Replaces ending p, div and heading tags with two newlines characters;
resulting in a single empty line btw. paragraphs.
5. Strips remaining html tags.
NB: The tag stripping is done using a very simple regular expression,
which removes everything between < and >. Therefore too much text
could in some (hopefully rare!?) cases be removed.
Parameters: s - Input string Input stripped for html tags author: Karl Peder Olesen (karlpeder) |
stripHtmlTags | public static String stripHtmlTags(String s, boolean breakToNl)(Code) | | Strips html tags. The method used is very simple:
Everything between tag-start (<) and tag-end (>) is removed.
Optionaly br tags are replaced by newline and ending p tags with
double newline.
Parameters: s - input string Parameters: breakToNl - if true, newlines are inserted for br and p tags output without html tags (null on error) author: karlpeder, 20030623 author: (moved from org.columba.mail.gui.message.util.DocumentParser) See Also: stripHtmlTags(String) method |
substituteEmailAddress | public static String substituteEmailAddress(String s)(Code) | | parse text and transform every email-address
in a HTML-conform address
Parameters: s - input text text with email-adresses transformed to links(null on error) |
substituteEmailAddress | public static String substituteEmailAddress(String s, boolean ignoreLinks)(Code) | | Transforms email-addresses into HTML just as
substituteEmailAddress(String), but tries to ignore email-addresses,
which are already links, if the ignore links flag is set.
This extended functionality is necessary when parsing a text which
is already (partly) html.
FIXME: Can this be done smarter, i.e. directly with reg. expr. without manual parsing??
Parameters: s - input text Parameters: ignoreLinks - if true link tags are ignored. This gives awrong result if some e-mail adresses arealready links (but uses reg. expr. directly,and is therefore faster) text with email-adresses transformed to links |
substituteSpecialCharacters | public static String substituteSpecialCharacters(String s)(Code) | | Substitute special characters like:
<,>,&,\t,\n,"
with special entities used in html (amp, nbsp, ...)
Parameters: s - input string containing special characters output with special characters substituted(null on error) |
substituteSpecialCharactersInHeaderfields | public static String substituteSpecialCharactersInHeaderfields(String s)(Code) | | substitute special characters like:
<,>,&,\t,\n
with special entities used in html
This is the same as substituteSpecialCharacters, but
here an extra newline character is not inserted.
Parameters: s - input string containing special characters output with special characters substituted(null on error) |
substituteURL | public static String substituteURL(String s)(Code) | | parse text and transform every url
in a HTML-conform url
Parameters: s - input text text with urls transformed to links(null on error) |
substituteURL | public static String substituteURL(String s, boolean ignoreLinks)(Code) | | Transforms urls into HTML just as substituteURL(String),
but tries to ignore urls, which are already links, if the ignore
links flag is set.
This extended functionality is necessary when parsing a text which
is already (partly) html.
FIXME: Can this be done smarter, i.e. directly with reg. expr. without manual parsing??
Parameters: s - input text Parameters: ignoreLinks - if true link tags are ignored. This gives awrong result if some urls are already links(but uses reg. expr. directly, and istherefore faster) text with urls |
textToHtml | public static String textToHtml(String text, String title, String css, String charset)(Code) | | Replaces special chars - <,>,&,\t,\n," - with the special
entities used in html (amp, nbsp, ...). Then the complete
text is surrounded with proper html tags: Starting- and
ending html tag, header section and body section.
The complete body section is sorround with p tags.
This is the same as first calling substituteSpecialCharacters
and then add starting and ending html tags etc.
Further more urls and email adresses are converted into links
Optionally a title and css definition is inserted in the
html header.
TODO (@author fdietz): Add support for smilies and coloring of quoted text
Parameters: text - Text to convert to html Parameters: title - Title to include in header, not used if null Parameters: css - Style sheet def. to include in header,not used if null.The input shall not include the style tag Text converted to html author: Karl Peder Olesen (karlpeder), 20030916 |
validateHTMLString | public static String validateHTMLString(String input)(Code) | | Tries to fix broken html-strings by inserting
html start- and end tags if missing, and by
removing content after the html end tag.
Parameters: input - html content to be validated content with extra tags inserted if necessary |
|
|