Html utilities : HTML Output « Servlets « Java






Html utilities

   

import java.io.IOException;
import java.io.StringWriter;
import java.util.Vector;

public class HtmlUtils {

  public String createHtmlHeader(String title) {

    String htmlHeader = null;
    htmlHeader = "<HTML><HEAD><TITLE> " + title + " </TITLE></HEAD><BODY>";
    return htmlHeader;
  }

  public String getHtmlFooter() {

    String htmlFooter = "</BODY></HTML>";
    return htmlFooter;
  }

  public String getHead(int level, String heading) {
    return "<H" + level + "> " + heading + "</H" + level + ">";
  }

  public String getTableHead(String align, int border) {

    String tableHeader = null;
    tableHeader = "<TABLE align=" + align + " border=" + border + ">";
    return tableHeader;

  }

  public String getTR(String align) {
    String TRCell = null;
    TRCell = "<TR align=" + align + ">";
    return TRCell;
  }

  public String getTR() {
    String TRCell = null;
    TRCell = "<TR>";
    return TRCell;
  }

  public String getTD(String align, String value) {
    String TDCell = null;
    TDCell = "<TD align=" + align + "> " + value + " </TD>";
    return TDCell;
  }

  public String getTD() {
    String TDCell = null;
    TDCell = "<TD>";
    return TDCell;
  }

  public String getTD(int width) {
    String TDCell = null;
    TDCell = "<TD WIDTH=" + width + ">";
    return TDCell;
  }

  public String getTH(String align, String value) {
    String THCell = null;
    THCell = "<TH align=" + align + "> " + value + " </TH>";
    return THCell;
  }

  public String getTableContents(String align, Vector values,
      int elementCounter) throws IOException {

    StringWriter Cells = new StringWriter();
    String contents = new String();
    int vsize = values.size();

    Cells.write("<TR>");

    for (int i = 0; i < vsize; i++) {
      String value = values.elementAt(i).toString();

      if (i != 0) {
        if (i >= elementCounter) {

          if (i % elementCounter == 0) {
            Cells.write("</TR>\n\n<TR>");
          }
        }
      }

      Cells.write("<TD align=" + align + "> " + value + " </TD> \n");
    }

    Cells.write("</TR>");

    contents = Cells.toString();
    Cells.flush();
    Cells.close();

    return contents;
  }

  public String getClosedTR() {
    String TRCell = null;
    TRCell = "</TR>";
    return TRCell;
  }

  public String getClosedTD() {
    String TDCell = null;
    TDCell = "</TD>";
    return TDCell;
  }

  public String getBR(int lines) {

    StringWriter lineBR = new StringWriter();
    String lineBRs = new String();

    for (int i = 0; i <= lines; i++) {
      lineBR.write("<BR>\n");
    }
    lineBRs = lineBR.toString();

    return lineBRs;
  }

  public String getLI(String item) {

    String li = new String("<LI>");
    li += item;
    return li;

  }
}

           
         
    
    
  








Related examples in the same category

1.Servlet Output HTML Demo
2.Servlet Display Static HTML
3.Prints a conversion table of miles per gallon to kilometers per liter
4.Servlet: Print Table
5.Html Parse Servlet
6.Escape and unescape string
7.Escapes newlines, tabs, backslashes, and quotes in the specified string
8.Web Calendar
9.HTML Helper
10.Escape HTML
11.Convert HTML to text
12.Text To HTML
13.Unescape HTML
14.Java object representations of the HTML table structure
15.Entity Decoder
16.Format a color to HTML RGB color format (e.g. #FF0000 for Color.red)
17.Definitions of HTML character entities and conversions between unicode characters and HTML character entities
18.Encode special characters and do formatting for HTML output
19.HTML color names
20.Utility methods for dealing with HTML
21.Filter the specified message string for characters that are sensitive in HTML
22.A collection of all character entites defined in the HTML4 standard.
23.Decode an HTML color string like '#F567BA;' into a Color
24.Normalize Post Data
25.Get HTML Color String from Java Color object
26.HTML Decoder
27.HTML Parser
28.HTML color and Java Color
29.HTML form Utilites
30.Html Dimensions
31.break Lines with HTML
32.insert HTML block dynamically
33.Convert an integer to an HTML RGB value
34.Convert to HTML string