Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.

csv.impl
Class HtmlWriter

java.lang.Object
  extended by csv.impl.AbstractTableWriter
      extended by csv.impl.AbstractStreamTableWriter
          extended by csv.impl.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 Summary
static java.lang.String DEFAULT_TABLE_TEMPLATE
           
static java.lang.String DEFAULT_TBODY_TD_TEMPLATE
           
static java.lang.String DEFAULT_TBODY_TD_TEMPLATE2
           
static java.lang.String DEFAULT_TBODY_TEMPLATE
           
static java.lang.String DEFAULT_TBODY_TR_TEMPLATE
           
static java.lang.String DEFAULT_TBODY_TR_TEMPLATE2
           
static java.lang.String DEFAULT_THEAD_TEMPLATE
           
static java.lang.String DEFAULT_THEAD_TH_TEMPLATE
           
static java.lang.String DEFAULT_THEAD_TH_TEMPLATE2
           
static java.lang.String DEFAULT_THEAD_TR_TEMPLATE
           
 
Constructor Summary
HtmlWriter()
          Default Constructor.
HtmlWriter(java.io.File file)
           
HtmlWriter(java.io.OutputStream out)
           
HtmlWriter(java.lang.String file)
           
 
Method Summary
 void close()
          Closes the writer by printing the footer of the table.
static java.lang.String encodeHtml(java.lang.String s)
          Makes HTML encoding for the string.
 int getCurrentRowIndex()
          Returns the current data row index.
protected static java.lang.String getFooter(java.lang.String template)
          Returns the footer part of the given template
protected static java.lang.String getHeader(java.lang.String template)
          Returns the header part of the given template
 java.lang.String getTableTemplate()
          Returns the main table template.
 java.lang.String getTbodyTdTemplate()
          Returns the data cell template for even columns.
 java.lang.String getTbodyTdTemplate2()
          Returns the data cell template for odd columns.
 java.lang.String getTbodyTemplate()
          Returns the table body template.
 java.lang.String getTbodyTrTemplate()
          Returns the row template for even data rows.
 java.lang.String getTbodyTrTemplate2()
          Returns the row template for odd data rows.
 java.lang.String getTheadTemplate()
          Returns the header template.
 java.lang.String getTheadThTemplate()
          Returns the header cell template for even columns.
 java.lang.String getTheadThTemplate2()
          Returns the header cell template for odd columns.
 java.lang.String getTheadTrTemplate()
          Returns the header row template.
protected  void init()
          General initialization.
 boolean isHasHeaderRow()
          Returns true if this writer will create a header row.
 boolean isTableHeaderWritten()
          Returns whether the table header (table tag) was written.
 void printColumnContent(java.lang.Object o, int rowIndex, int columnIndex)
          Prints the value of this object only without any enclosing tags.
 void printDataRow(java.lang.Object[] columns, int rowIndex)
          Prints a data row to the underlying stream
 void printHeaderRow(java.lang.Object[] columns)
          Prints the header row into the stream.
 void printRow(java.lang.Object[] columns)
          Prints the row.
 void printTableBodyFooter()
          Prints the table body (tbody) footer into the underlying stream.
 void printTableBodyHeader()
          Prints the table body (tbody) header into the underlying stream.
 void printTableBodyRowFooter(int rowIndex)
          Prints the table body row (tr) footer into the underlying stream.
 void printTableBodyRowHeader(int rowIndex)
          Prints the table body row (tr) header into the underlying stream.
 void printTableDataColumnFooter(int rowIndex, int columnIndex)
          Prints the table body data cell (td) footer into the underlying stream.
 void printTableDataColumnHeader(int rowIndex, int columnIndex)
          Prints the table body data cell (td) header into the underlying stream.
 void printTableFooter()
          Prints the table footer into the underlying stream.
 void printTableHeadColumnFooter(int columnIndex)
          Prints the table header column (th) footer into the underlying stream.
 void printTableHeadColumnHeader(int columnIndex)
          Prints the table header column (th) header into the underlying stream.
 void printTableHeader()
          Prints the table header into the underlying stream.
 void printTableHeadFooter()
          Prints the table head (thead) footer into the underlying stream.
 void printTableHeadHeader()
          Prints the table head (thead) header into the underlying stream.
 void printTableHeadRowFooter()
          Prints the table header row (tr) footer into the underlying stream.
 void printTableHeadRowHeader()
          Prints the table header row (tr) header into the underlying stream.
 void setHasHeaderRow(boolean hasHeaderRow)
          Sets whether writer will create a header row.
 void setTableTemplate(java.lang.String tableTemplate)
          Sets the main table template.
 void setTbodyTdTemplate(java.lang.String dataColumnTemplate)
          Sets the data cell template for even columns.
 void setTbodyTdTemplate2(java.lang.String dataColumnTemplate2)
          Sets the data cell template for odd columns.
 void setTbodyTemplate(java.lang.String bodyTemplate)
          Sets the body template.
 void setTbodyTrTemplate(java.lang.String bodyRowTemplate)
          Sets the row template for even data rows.
 void setTbodyTrTemplate2(java.lang.String bodyRowTemplate2)
          Sets the row template for odd data rows.
 void setTheadTemplate(java.lang.String headerTemplate)
          Sets the header template.
 void setTheadThTemplate(java.lang.String headerColumnTemplate)
          Sets the header cell template for even columns.
 void setTheadThTemplate2(java.lang.String headerColumnTemplate2)
          Sets the header cell template for odd columns.
 void setTheadTrTemplate(java.lang.String headerRowTemplate)
          Sets the header row template.
 
Methods inherited from class csv.impl.AbstractStreamTableWriter
getOutputStream, getWriter, setOutputStream
 
Methods inherited from class csv.impl.AbstractTableWriter
convert, convert, getRowCount, getTypeConversionHandler, incrementRowCount, printComment, printComment, registerTypeConversionHandler, unregisterTypeConversionHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TABLE_TEMPLATE

public static final java.lang.String DEFAULT_TABLE_TEMPLATE
See Also:
Constant Field Values

DEFAULT_THEAD_TEMPLATE

public static final java.lang.String DEFAULT_THEAD_TEMPLATE
See Also:
Constant Field Values

DEFAULT_THEAD_TR_TEMPLATE

public static final java.lang.String DEFAULT_THEAD_TR_TEMPLATE
See Also:
Constant Field Values

DEFAULT_THEAD_TH_TEMPLATE

public static final java.lang.String DEFAULT_THEAD_TH_TEMPLATE
See Also:
Constant Field Values

DEFAULT_THEAD_TH_TEMPLATE2

public static final java.lang.String DEFAULT_THEAD_TH_TEMPLATE2
See Also:
Constant Field Values

DEFAULT_TBODY_TEMPLATE

public static final java.lang.String DEFAULT_TBODY_TEMPLATE
See Also:
Constant Field Values

DEFAULT_TBODY_TR_TEMPLATE

public static final java.lang.String DEFAULT_TBODY_TR_TEMPLATE
See Also:
Constant Field Values

DEFAULT_TBODY_TD_TEMPLATE

public static final java.lang.String DEFAULT_TBODY_TD_TEMPLATE
See Also:
Constant Field Values

DEFAULT_TBODY_TR_TEMPLATE2

public static final java.lang.String DEFAULT_TBODY_TR_TEMPLATE2
See Also:
Constant Field Values

DEFAULT_TBODY_TD_TEMPLATE2

public static final java.lang.String DEFAULT_TBODY_TD_TEMPLATE2
See Also:
Constant Field Values
Constructor Detail

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

HtmlWriter

public HtmlWriter(java.lang.String file)
           throws java.io.IOException
Parameters:
file - output filename
Throws:
java.io.IOException
Method Detail

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
Throws:
java.io.IOException

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

Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.

Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.