public final class HtmlProcessing
extends java.lang.Object
HtmlProcessing - Various methods for HTML processing for mail module.| Modifier and Type | Method and Description |
|---|---|
static org.w3c.dom.Document |
createDOMDocument(java.lang.String string)
Creates a
DOM document from specified XML/HTML string. |
static java.lang.String |
filterInlineImages(java.lang.String content,
com.openexchange.session.Session session,
MailPath msgUID)
Filters inline images occurring in HTML content of a message:
Inline images
The source of inline images is in the message itself. |
static java.lang.String |
formatContentForDisplay(java.lang.String content,
java.lang.String charset,
boolean isHtml,
com.openexchange.session.Session session,
MailPath mailPath,
UserSettingMail usm,
boolean[] modified,
DisplayMode mode,
boolean embedded)
Performs all the formatting for both text and HTML content for a proper display according to specified user's mail settings.
|
static java.lang.String |
formatHrefLinks(java.lang.String content)
Searches for non-HTML links and convert them to valid HTML links.
|
static java.lang.String |
formatHTMLForDisplay(java.lang.String content,
java.lang.String charset,
com.openexchange.session.Session session,
MailPath mailPath,
UserSettingMail usm,
boolean[] modified,
DisplayMode mode,
boolean embedded)
Performs all the formatting for HTML content for a proper display according to specified user's mail settings.
|
static java.lang.String |
formatTextForDisplay(java.lang.String content,
UserSettingMail usm,
DisplayMode mode)
Performs all the formatting for text content for a proper display according to specified user's mail settings.
|
static java.lang.String |
getConformHTML(java.lang.String htmlContent,
ContentType contentType)
Creates valid HTML from specified HTML content conform to W3C standards.
|
static java.lang.String |
getConformHTML(java.lang.String htmlContent,
java.lang.String charset)
Creates valid HTML from specified HTML content conform to W3C standards.
|
static java.lang.String |
getHash(java.lang.String str,
int maxLen)
Calculates the MD5 for given string.
|
static java.lang.Character |
getHTMLEntity(java.lang.String entity)
Maps specified HTML entity - e.g.
|
static java.lang.String |
html2text(java.lang.String htmlContent,
boolean appendHref)
Converts specified HTML content to plain text.
|
static java.lang.String |
htmlFormat(java.lang.String plainText)
Formats plain text to HTML by escaping HTML special characters e.g.
|
static java.lang.String |
htmlFormat(java.lang.String plainText,
boolean withQuote)
Formats plain text to HTML by escaping HTML special characters e.g.
|
static java.lang.String |
prettyPrint(java.lang.String htmlContent)
Pretty prints specified HTML content.
|
static java.lang.String |
prettyPrintXML(org.w3c.dom.Node node)
Pretty-prints specified XML/HTML node.
|
static java.lang.String |
prettyPrintXML(java.lang.String string)
Pretty-prints specified XML/HTML string.
|
static java.lang.String |
replaceHTMLEntities(java.lang.String content)
Replaces all HTML entities occurring in specified HTML content.
|
static java.lang.String |
saneCss(java.lang.String htmlContent,
com.openexchange.html.HtmlService optHtmlService,
java.lang.String cssPrefix)
Sanitizes possible CSS style sheets contained in provided HTML content.
|
static java.lang.String |
urlEncodeSafe(java.lang.String text,
java.lang.String charset)
Translates specified string into application/x-www-form-urlencoded format using a specific encoding scheme.
|
static boolean |
useSanitize()
Whether to use sanitize.
|
public static java.lang.String formatTextForDisplay(java.lang.String content,
UserSettingMail usm,
DisplayMode mode)
content - The plain text contentusm - The settings used for formatting contentmode - The display mode#formatContentForDisplay(String, String, boolean, Session, MailPath, UserSettingMail, boolean[], DisplayMode)public static java.lang.String formatHTMLForDisplay(java.lang.String content,
java.lang.String charset,
com.openexchange.session.Session session,
MailPath mailPath,
UserSettingMail usm,
boolean[] modified,
DisplayMode mode,
boolean embedded)
content - The HTML contentcharset - The character encodingsession - The sessionmailPath - The message's unique path in mailboxusm - The settings used for formatting contentmodified - A boolean array with length 1 to store modified status of external images filtermode - The display modeembedded - true for embedded display (CSS prefixed, <body> replaced with <div>); otherwise false#formatContentForDisplay(String, String, boolean, Session, MailPath, UserSettingMail, boolean[], DisplayMode)public static java.lang.String formatContentForDisplay(java.lang.String content,
java.lang.String charset,
boolean isHtml,
com.openexchange.session.Session session,
MailPath mailPath,
UserSettingMail usm,
boolean[] modified,
DisplayMode mode,
boolean embedded)
If content is plain text:
DisplayMode.MODIFYABLE is givenDisplayMode.DISPLAY is givenDisplayMode.DISPLAY is givenDisplayMode.DISPLAY is
givencontent - The contentcharset - The character encoding (only needed by HTML content; may be null on plain text)isHtml - true if content is of type text/html; otherwise falsesession - The sessionmailPath - The message's unique path in mailboxusm - The settings used for formatting contentmodified - A boolean array with length 1 to store modified status of external images filter (only
needed by HTML content; may be null on plain text)mode - The display modeembedded - true for embedded display (CSS prefixed, <body> replaced with <div>); otherwise falsepublic static boolean useSanitize()
public static java.lang.String getHash(java.lang.String str,
int maxLen)
str - The stringmaxLen - The max. length or -1public static java.lang.String saneCss(java.lang.String htmlContent,
com.openexchange.html.HtmlService optHtmlService,
java.lang.String cssPrefix)
htmlContent - The HTML contentoptHtmlService - The optional HTML servicepublic static java.lang.String html2text(java.lang.String htmlContent,
boolean appendHref)
htmlContent - The validated HTML contentappendHref - true to append URLs contained in hrefs and srcs; otherwise false.<a href=\"www.somewhere.com\">Link<a> would be
Link [www.somewhere.com]public static java.lang.String formatHrefLinks(java.lang.String content)
Example: http://www.somewhere.com is converted to
<a href="http://www.somewhere.com">http://www.somewhere.com</a>.
content - The content to search inpublic static java.lang.String getConformHTML(java.lang.String htmlContent,
ContentType contentType)
htmlContent - The HTML contentcontentType - The corresponding content type (including charset parameter)public static java.lang.String getConformHTML(java.lang.String htmlContent,
java.lang.String charset)
htmlContent - The HTML contentcharset - The charset parameterpublic static org.w3c.dom.Document createDOMDocument(java.lang.String string)
DOM document from specified XML/HTML string.string - The XML/HTML stringnull if given string cannot be transformed to a DOM documentpublic static java.lang.String prettyPrintXML(java.lang.String string)
string - The XML/HTML string to pretty-printpublic static java.lang.String prettyPrintXML(org.w3c.dom.Node node)
node - The XML/HTML node pretty-printpublic static java.lang.String prettyPrint(java.lang.String htmlContent)
htmlContent - The HTML contentpublic static java.lang.String replaceHTMLEntities(java.lang.String content)
content - The contentpublic static java.lang.Character getHTMLEntity(java.lang.String entity)
ü - to corresponding ASCII character.entity - The HTML entitynullpublic static java.lang.String htmlFormat(java.lang.String plainText,
boolean withQuote)
"<" is converted to
"<".plainText - The plain textwithQuote - Whether to escape quotes (") or notpublic static java.lang.String htmlFormat(java.lang.String plainText)
"<" is converted to
"<".
This is just a convenience method which invokes with latter parameter set to
htmlFormat(String, boolean)true.
plainText - The plain texthtmlFormat(String, boolean)public static java.lang.String filterInlineImages(java.lang.String content,
com.openexchange.session.Session session,
MailPath msgUID)
Content-Id; e.g.: <img
src="cid:[cid-value]" ... />.content - The HTML content possibly containing imagessession - The sessionmsgUID - The message's unique path in mailboxpublic static java.lang.String urlEncodeSafe(java.lang.String text,
java.lang.String charset)
text - The string to be translated.charset - The character encoding to use; should be UTF-8 according to W3C