Java Utililty Methods HTML

List of utility methods to do HTML

Description

The list of methods to do HTML are organized into topic(s).

Method

StringhtmlBlock(String labelText)
html Block
return "<html>" + labelText + "</html>";
StringhtmlBold(String content)
html Bold
return "<b>" + content + "</b>";
StringhtmlButton(String value, String action, int width)
Method htmlButton.
return htmlButton(value, action, width, 22);
booleanHTMLcheck(String doc)
HTM Lcheck
if (doc == null)
    return false;
if (doc.substring(0, 5).equals("<html"))
    return true;
if (doc.substring(0, 5).equals("<HTML"))
    return true;
if (doc.substring(0, 14).equals("<!DOCTYPE HTML"))
    return true;
...
StringhtmlCode(char tok)
html Code
int i = 0;
for (; i < HTML.length; i++) {
    if (HTML[i][0].equals(tok + "")) {
        return HTML[i][1];
return tok + "";
StringhtmlcodeToSpecialchars(String str)
htmlcode To Specialchars
str = str.replaceAll("&amp;", "&");
str = str.replaceAll("&quot;", "\"");
str = str.replaceAll("&#039;", "'");
str = str.replaceAll("&lt;", "<");
str = str.replaceAll("&gt;", ">");
return str;
StringhtmlcodeToSpecialchars(String str)
htmlcode To Specialchars
str = str.replaceAll("&amp;", "&");
str = str.replaceAll("&quot;", "\"");
str = str.replaceAll("&#039;", "'");
str = str.replaceAll("&lt;", "<");
str = str.replaceAll("&gt;", ">");
return str;
StringhtmlContentHeaderGen(String providerNo, String output, String errorMsg)
html Content Header Gen
StringBuilder htmlContentHeader = new StringBuilder();
htmlContentHeader.append(
        "<html><body><style type='text/css'><!-- .bodytext{  font-family: Tahoma, Arial, Helvetica, sans-serif;  font-size: 12px; font-style: normal;  line-height: normal;  font-weight: normal;  font-variant: normal;  text-transform: none;  color: #003366;  text-decoration: none; --></style>");
htmlContentHeader.append("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
htmlContentHeader.append("<tr>");
htmlContentHeader
        .append("<td colspan='4' class='bodytext'>Billing Invoice for Billing No." + providerNo + "</td>");
htmlContentHeader.append("<td colspan='7' class='bodytext'>Payment date of " + output + "</td>");
...
StringhtmlConvert(String htmlStr)
html Convert
if (htmlStr == null)
    return "";
htmlStr = htmlStr.replaceAll("&", "&amp;");
htmlStr = htmlStr.replaceAll(" ", "&nbsp;");
htmlStr = htmlStr.replaceAll("\"", "&quot;");
htmlStr = htmlStr.replaceAll("<", "&lt;");
htmlStr = htmlStr.replaceAll(">", "&gt;");
htmlStr = htmlStr.replaceAll("\r\n", "<br>");
...
StringHTMLEnc(String s)
HTML encoding (does not convert line breaks).
return XMLEncNA(s);