Package com.nomagic.text.html
Class HtmlTextUtils
java.lang.Object
com.nomagic.text.html.HtmlTextUtils
HTML text related utility methods.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
encodeHtmlCharacters
(String text) Encodes string characters to html characters.static String
Create end tag for the given tag.static String
escapeLongSpaces
(String text) Replaces sequece of 2 or more spaces with same amount of not breaking spaces.static boolean
isDocTypeHtml
(String text) static boolean
Checks if given string is html string - starts with <html> tagstatic String
removeHtmlBodyPTags
(String htmlText) Extracts body from the given html text.static String
removeHtmlBodyTags
(String htmlText) Extracts body from the given html textstatic String
replaceNBSP
(String text) static String
Create start tag for the given tag.static String
toHtmlText
(String text) Convert given text to html text.static String
toPlainText
(String htmlText) Converts html text to plain text.static String
toPlainText
(Document doc) Converts document to plain textstatic String
Wrap given text in <html><body>new_line tagsstatic String
wrapInHtmlBodyPTags
(String text) Wrap given text in <html><body><p> tagsstatic String
wrapInHtmlBodyTags
(String text) Wrap given text in <html><body> tagsstatic String
Wrap given text in <html light="true"><body><p> tagsstatic String
Wrap given text in <html light="true"><body> tagsstatic String
wrapInHtmlTag
(String text) Wrap given text with <html> tagstatic StringBuilder
wrapInHtmlTag
(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
-