Package csv.impl

Class HtmlWriter

All Implemented Interfaces:
TableWriter

public class HtmlWriter
extends AbstractStreamTableWriter
Provides implementation for writing HTML table. The HTML table written is controlled by separate templates for each individual tags.

Please note! This class is mainly for convinience when aou need to create static HTML files. You'd rather use JSP pages when you are in a JSP environment (unless you have good reasons to use this class).

Author:
ralph
  • Field Details

  • Constructor Details

    • HtmlWriter

      public HtmlWriter()
      Default Constructor.
    • HtmlWriter

      public HtmlWriter​(java.io.OutputStream out)
      Parameters:
      out - output stream
    • HtmlWriter

      public HtmlWriter​(java.io.File file) throws java.io.IOException
      Parameters:
      file - output file
      Throws:
      java.io.IOException - when the file cannot be written
    • HtmlWriter

      public HtmlWriter​(java.lang.String file) throws java.io.IOException
      Parameters:
      file - output filename
      Throws:
      java.io.IOException - when the file cannot be written
  • Method Details

    • close

      public void close()
      Closes the writer by printing the footer of the table.
      Specified by:
      close in interface TableWriter
      Overrides:
      close in class AbstractStreamTableWriter
      See Also:
      AbstractStreamTableWriter.close()
    • init

      protected void init()
      Description copied from class: AbstractTableWriter
      General initialization. This implementation does nothing.
      Overrides:
      init in class AbstractTableWriter
      See Also:
      AbstractTableWriter.init()
    • printRow

      public void printRow​(java.lang.Object[] columns) throws java.io.IOException
      Prints the row. if the writer was configured to have a header row then first call will write a HTML header row
      Parameters:
      columns - columns to be written
      Throws:
      java.io.IOException - when an exception occurs
      See Also:
      TableWriter.printRow(java.lang.Object[])
    • printHeaderRow

      public void printHeaderRow​(java.lang.Object[] columns)
      Prints the header row into the stream.
      Parameters:
      columns - columns to be written
    • printDataRow

      public void printDataRow​(java.lang.Object[] columns, int rowIndex)
      Prints a data row to the underlying stream
      Parameters:
      columns - the column values to be written
      rowIndex - index of data row (not including header row)
    • printColumnContent

      public void printColumnContent​(java.lang.Object o, int rowIndex, int columnIndex)
      Prints the value of this object only without any enclosing tags.
      Parameters:
      o - object to be written
      rowIndex - index of data row (not including header row)
      columnIndex - index of column
    • printTableHeader

      public void printTableHeader()
      Prints the table header into the underlying stream.
    • printTableFooter

      public void printTableFooter()
      Prints the table footer into the underlying stream.
    • printTableHeadHeader

      public void printTableHeadHeader()
      Prints the table head (thead) header into the underlying stream.
    • printTableHeadFooter

      public void printTableHeadFooter()
      Prints the table head (thead) footer into the underlying stream.
    • printTableBodyHeader

      public void printTableBodyHeader()
      Prints the table body (tbody) header into the underlying stream.
    • printTableBodyFooter

      public void printTableBodyFooter()
      Prints the table body (tbody) footer into the underlying stream.
    • printTableHeadRowHeader

      public void printTableHeadRowHeader()
      Prints the table header row (tr) header into the underlying stream.
    • printTableHeadRowFooter

      public void printTableHeadRowFooter()
      Prints the table header row (tr) footer into the underlying stream.
    • printTableHeadColumnHeader

      public void printTableHeadColumnHeader​(int columnIndex)
      Prints the table header column (th) header into the underlying stream.
      Parameters:
      columnIndex - index of column
    • printTableHeadColumnFooter

      public void printTableHeadColumnFooter​(int columnIndex)
      Prints the table header column (th) footer into the underlying stream.
      Parameters:
      columnIndex - index of column
    • printTableBodyRowHeader

      public void printTableBodyRowHeader​(int rowIndex)
      Prints the table body row (tr) header into the underlying stream.
      Parameters:
      rowIndex - index of data row (not including header row)
    • printTableBodyRowFooter

      public void printTableBodyRowFooter​(int rowIndex)
      Prints the table body row (tr) footer into the underlying stream.
      Parameters:
      rowIndex - index of data row (not including header row)
    • printTableDataColumnHeader

      public void printTableDataColumnHeader​(int rowIndex, int columnIndex)
      Prints the table body data cell (td) header into the underlying stream.
      Parameters:
      rowIndex - index of data row (not including header row)
      columnIndex - index of column
    • printTableDataColumnFooter

      public void printTableDataColumnFooter​(int rowIndex, int columnIndex)
      Prints the table body data cell (td) footer into the underlying stream.
      Parameters:
      rowIndex - index of data row (not including header row)
      columnIndex - index of column
    • getTableTemplate

      public java.lang.String getTableTemplate()
      Returns the main table template.
      Returns:
      the tableTemplate
    • setTableTemplate

      public void setTableTemplate​(java.lang.String tableTemplate)
      Sets the main table template.
      Parameters:
      tableTemplate - the tableTemplate to set
    • getTheadTemplate

      public java.lang.String getTheadTemplate()
      Returns the header template.
      Returns:
      the headerTemplate
    • setTheadTemplate

      public void setTheadTemplate​(java.lang.String headerTemplate)
      Sets the header template.
      Parameters:
      headerTemplate - the headerTemplate to set
    • getTheadTrTemplate

      public java.lang.String getTheadTrTemplate()
      Returns the header row template.
      Returns:
      the headerRowTemplate
    • setTheadTrTemplate

      public void setTheadTrTemplate​(java.lang.String headerRowTemplate)
      Sets the header row template.
      Parameters:
      headerRowTemplate - the headerRowTemplate to set
    • getTheadThTemplate

      public java.lang.String getTheadThTemplate()
      Returns the header cell template for even columns.
      Returns:
      the headerColumnTemplate
    • setTheadThTemplate

      public void setTheadThTemplate​(java.lang.String headerColumnTemplate)
      Sets the header cell template for even columns.
      Parameters:
      headerColumnTemplate - the headerColumnTemplate to set
    • getTheadThTemplate2

      public java.lang.String getTheadThTemplate2()
      Returns the header cell template for odd columns.
      Returns:
      the headerColumnTemplate2
    • setTheadThTemplate2

      public void setTheadThTemplate2​(java.lang.String headerColumnTemplate2)
      Sets the header cell template for odd columns.
      Parameters:
      headerColumnTemplate2 - the headerColumnTemplate2 to set
    • getTbodyTemplate

      public java.lang.String getTbodyTemplate()
      Returns the table body template.
      Returns:
      the bodyTemplate
    • setTbodyTemplate

      public void setTbodyTemplate​(java.lang.String bodyTemplate)
      Sets the body template.
      Parameters:
      bodyTemplate - the bodyTemplate to set
    • getTbodyTrTemplate

      public java.lang.String getTbodyTrTemplate()
      Returns the row template for even data rows.
      Returns:
      the bodyRowTemplate
    • setTbodyTrTemplate

      public void setTbodyTrTemplate​(java.lang.String bodyRowTemplate)
      Sets the row template for even data rows.
      Parameters:
      bodyRowTemplate - the bodyRowTemplate to set
    • getTbodyTrTemplate2

      public java.lang.String getTbodyTrTemplate2()
      Returns the row template for odd data rows.
      Returns:
      the bodyRowTemplate2
    • setTbodyTrTemplate2

      public void setTbodyTrTemplate2​(java.lang.String bodyRowTemplate2)
      Sets the row template for odd data rows.
      Parameters:
      bodyRowTemplate2 - the bodyRowTemplate2 to set
    • getTbodyTdTemplate

      public java.lang.String getTbodyTdTemplate()
      Returns the data cell template for even columns.
      Returns:
      the dataColumnTemplate
    • setTbodyTdTemplate

      public void setTbodyTdTemplate​(java.lang.String dataColumnTemplate)
      Sets the data cell template for even columns.
      Parameters:
      dataColumnTemplate - the dataColumnTemplate to set
    • getTbodyTdTemplate2

      public java.lang.String getTbodyTdTemplate2()
      Returns the data cell template for odd columns.
      Returns:
      the dataColumnTemplate2
    • setTbodyTdTemplate2

      public void setTbodyTdTemplate2​(java.lang.String dataColumnTemplate2)
      Sets the data cell template for odd columns.
      Parameters:
      dataColumnTemplate2 - the dataColumnTemplate2 to set
    • isTableHeaderWritten

      public boolean isTableHeaderWritten()
      Returns whether the table header (table tag) was written.
      Returns:
      the tableHeaderWritten
    • getCurrentRowIndex

      public int getCurrentRowIndex()
      Returns the current data row index.
      Returns:
      the currentRowIndex
    • isHasHeaderRow

      public boolean isHasHeaderRow()
      Returns true if this writer will create a header row.
      Returns:
      the hasHeaderRow
    • setHasHeaderRow

      public void setHasHeaderRow​(boolean hasHeaderRow)
      Sets whether writer will create a header row.
      Parameters:
      hasHeaderRow - the hasHeaderRow to set
    • encodeHtml

      public static java.lang.String encodeHtml​(java.lang.String s)
      Makes HTML encoding for the string.
      Parameters:
      s - the string ready to be used in HTML
      Returns:
      HTML encoded string
    • getHeader

      protected static java.lang.String getHeader​(java.lang.String template)
      Returns the header part of the given template
      Parameters:
      template - template divided into two parts separated by a pipe character (|)
      Returns:
      header part of template
    • getFooter

      protected static java.lang.String getFooter​(java.lang.String template)
      Returns the footer part of the given template
      Parameters:
      template - template divided into two parts separated by a pipe character (|)
      Returns:
      footer part of template