Package com.nomagic.text.html
Class HtmlTextUtils
java.lang.Object
com.nomagic.text.html.HtmlTextUtils
HTML text related utility methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringencodeHtmlCharacters(String text) Encodes string characters to html characters.static StringCreate end tag for the given tag.static StringescapeLongSpaces(String text) Replaces sequece of 2 or more spaces with same amount of not breaking spaces.static booleanisDocTypeHtml(String text) static booleanChecks if given string is html string - starts with <html> tagstatic StringremoveHtmlBodyPTags(String htmlText) Extracts body from the given html text.static StringremoveHtmlBodyTags(String htmlText) Extracts body from the given html textstatic StringreplaceNBSP(String text) static StringCreate start tag for the given tag.static StringtoHtmlText(String text) Convert given text to html text.static StringtoPlainText(String htmlText) Converts html text to plain text.static StringtoPlainText(Document doc) Converts document to plain textstatic StringWrap given text in <html><body>new_line tagsstatic StringwrapInHtmlBodyPTags(String text) Wrap given text in <html><body><p> tagsstatic StringwrapInHtmlBodyTags(String text) Wrap given text in <html><body> tagsstatic StringWrap given text in <html light="true"><body><p> tagsstatic StringWrap given text in <html light="true"><body> tagsstatic StringwrapInHtmlTag(String text) Wrap given text with <html> tagstatic StringBuilderwrapInHtmlTag(StringBuilder text) Wrap given text with <html> tag
-
Constructor Details
-
HtmlTextUtils
public HtmlTextUtils()
-
-
Method Details
-
isHtml
Checks if given string is html string - starts with <html> tag- Parameters:
text- text
-
isDocTypeHtml
-
removeHtmlBodyPTags
Extracts body from the given html text. If body is wrapped with P tags, removes them as well.- Parameters:
htmlText- html text- Returns:
- body text
-
removeHtmlBodyTags
Extracts body from the given html text- Parameters:
htmlText- html text- Returns:
- body text
-
wrapInHtmlTag
Wrap given text with <html> tag- Parameters:
text- text- Returns:
- wrapped text
-
wrapInHtmlTag
Wrap given text with <html> tag- Parameters:
text- text- Returns:
- wrapped text
-
wrapInHtmlBodyPTags
Wrap given text in <html><body><p> tags- Parameters:
text- text- Returns:
- wrapped text
-
wrapInHtmlBodyNewLineTags
Wrap given text in <html><body>new_line tags- Parameters:
text- text- Returns:
- wrapped text
-
wrapInHtmlBodyTags
Wrap given text in <html><body> tags- Parameters:
text- text- Returns:
- wrapped text
-
wrapInHtmlLightBodyTags
Wrap given text in <html light="true"><body> tags- Parameters:
text- text- Returns:
- wrapped text
-
wrapInHtmlLightBodyPTags
Wrap given text in <html light="true"><body><p> tags- Parameters:
text- text- Returns:
- wrapped text
-
startTag
Create start tag for the given tag.- Parameters:
tag- The given tag.- Returns:
- tag wrapped to <tag>
-
endTag
Create end tag for the given tag.- Parameters:
tag- The given tag.- Returns:
- tag wrapped to </tag>
-
toHtmlText
Convert given text to html text. Characters are converter to html characters. Does nothing if text is html text already.- Parameters:
text- the given text- Returns:
- the html text
-
encodeHtmlCharacters
Encodes string characters to html characters. For example convert space to nbps;, < to < and etc.- Parameters:
text- plain text- Returns:
- string with encoded characters
-
toPlainText
Converts html text to plain text. Important - pass html text, not a plain text!- Parameters:
htmlText- html text- Returns:
- plain text
-
toPlainText
Converts document to plain text- Returns:
- the plain text
-
escapeLongSpaces
Replaces sequece of 2 or more spaces with same amount of not breaking spaces. Required for HTML text, which shrinks multiple spaces into single -
replaceNBSP
-