Package csv.impl
Class HtmlWriter
java.lang.Object
csv.impl.AbstractTableWriter
csv.impl.AbstractStreamTableWriter
csv.impl.HtmlWriter
- All Implemented Interfaces:
TableWriter
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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault Constructor.HtmlWriter(File file) HtmlWriter(OutputStream out) HtmlWriter(String file) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the writer by printing the footer of the table.static StringencodeHtml(String s) Makes HTML encoding for the string.intReturns the current data row index.protected static StringReturns the footer part of the given templateprotected static StringReturns the header part of the given templateReturns the main table template.Returns the data cell template for even columns.Returns the data cell template for odd columns.Returns the table body template.Returns the row template for even data rows.Returns the row template for odd data rows.Returns the header template.Returns the header cell template for even columns.Returns the header cell template for odd columns.Returns the header row template.protected voidinit()General initialization.booleanReturns true if this writer will create a header row.booleanReturns whether the table header (table tag) was written.voidprintColumnContent(Object o, int rowIndex, int columnIndex) Prints the value of this object only without any enclosing tags.voidprintDataRow(Object[] columns, int rowIndex) Prints a data row to the underlying streamvoidprintHeaderRow(Object[] columns) Prints the header row into the stream.voidPrints the row.voidPrints the table body (tbody) footer into the underlying stream.voidPrints the table body (tbody) header into the underlying stream.voidprintTableBodyRowFooter(int rowIndex) Prints the table body row (tr) footer into the underlying stream.voidprintTableBodyRowHeader(int rowIndex) Prints the table body row (tr) header into the underlying stream.voidprintTableDataColumnFooter(int rowIndex, int columnIndex) Prints the table body data cell (td) footer into the underlying stream.voidprintTableDataColumnHeader(int rowIndex, int columnIndex) Prints the table body data cell (td) header into the underlying stream.voidPrints the table footer into the underlying stream.voidprintTableHeadColumnFooter(int columnIndex) Prints the table header column (th) footer into the underlying stream.voidprintTableHeadColumnHeader(int columnIndex) Prints the table header column (th) header into the underlying stream.voidPrints the table header into the underlying stream.voidPrints the table head (thead) footer into the underlying stream.voidPrints the table head (thead) header into the underlying stream.voidPrints the table header row (tr) footer into the underlying stream.voidPrints the table header row (tr) header into the underlying stream.voidsetHasHeaderRow(boolean hasHeaderRow) Sets whether writer will create a header row.voidsetTableTemplate(String tableTemplate) Sets the main table template.voidsetTbodyTdTemplate(String dataColumnTemplate) Sets the data cell template for even columns.voidsetTbodyTdTemplate2(String dataColumnTemplate2) Sets the data cell template for odd columns.voidsetTbodyTemplate(String bodyTemplate) Sets the body template.voidsetTbodyTrTemplate(String bodyRowTemplate) Sets the row template for even data rows.voidsetTbodyTrTemplate2(String bodyRowTemplate2) Sets the row template for odd data rows.voidsetTheadTemplate(String headerTemplate) Sets the header template.voidsetTheadThTemplate(String headerColumnTemplate) Sets the header cell template for even columns.voidsetTheadThTemplate2(String headerColumnTemplate2) Sets the header cell template for odd columns.voidsetTheadTrTemplate(String headerRowTemplate) Sets the header row template.Methods inherited from class csv.impl.AbstractStreamTableWriter
createOutputStreamWriter, createWriter, getCharsetEncoder, getOutputStream, getWriter, setCharset, setCharset, setCharsetEncoder, setOutputStreamMethods inherited from class csv.impl.AbstractTableWriter
convert, getMapper, getRowCount, incrementRowCount, printComment, printComment, printRow, printRow, printRow, setMapper
-
Field Details
-
DEFAULT_TABLE_TEMPLATE
- See Also:
-
DEFAULT_THEAD_TEMPLATE
- See Also:
-
DEFAULT_THEAD_TR_TEMPLATE
- See Also:
-
DEFAULT_THEAD_TH_TEMPLATE
- See Also:
-
DEFAULT_THEAD_TH_TEMPLATE2
- See Also:
-
DEFAULT_TBODY_TEMPLATE
- See Also:
-
DEFAULT_TBODY_TR_TEMPLATE
- See Also:
-
DEFAULT_TBODY_TD_TEMPLATE
- See Also:
-
DEFAULT_TBODY_TR_TEMPLATE2
- See Also:
-
DEFAULT_TBODY_TD_TEMPLATE2
- See Also:
-
-
Constructor Details
-
HtmlWriter
public HtmlWriter()Default Constructor. -
HtmlWriter
- Parameters:
out- output stream
-
HtmlWriter
- Parameters:
file- output file- Throws:
IOException- when the file cannot be written
-
HtmlWriter
- Parameters:
file- output filename- Throws:
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:
closein interfaceTableWriter- Overrides:
closein classAbstractStreamTableWriter- See Also:
-
init
protected void init()Description copied from class:AbstractTableWriterGeneral initialization. This implementation does nothing.- Overrides:
initin classAbstractTableWriter- See Also:
-
printRow
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:
IOException- when an exception occurs- See Also:
-
printHeaderRow
Prints the header row into the stream.- Parameters:
columns- columns to be written
-
printDataRow
Prints a data row to the underlying stream- Parameters:
columns- the column values to be writtenrowIndex- index of data row (not including header row)
-
printColumnContent
Prints the value of this object only without any enclosing tags.- Parameters:
o- object to be writtenrowIndex- index of data row (not including header row)columnIndex- index of column
-
printTableHeader
public void printTableHeader()Prints the table header into the underlying stream. -
printTableHeadHeader
public void printTableHeadHeader()Prints the table head (thead) header into the underlying stream. -
printTableBodyHeader
public void printTableBodyHeader()Prints the table body (tbody) header into the underlying stream. -
printTableHeadRowHeader
public void printTableHeadRowHeader()Prints the table header row (tr) header 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
-
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)
-
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
-
getTableTemplate
Returns the main table template.- Returns:
- the tableTemplate
-
setTableTemplate
Sets the main table template.- Parameters:
tableTemplate- the tableTemplate to set
-
getTheadTemplate
Returns the header template.- Returns:
- the headerTemplate
-
setTheadTemplate
Sets the header template.- Parameters:
headerTemplate- the headerTemplate to set
-
getTheadTrTemplate
Returns the header row template.- Returns:
- the headerRowTemplate
-
setTheadTrTemplate
Sets the header row template.- Parameters:
headerRowTemplate- the headerRowTemplate to set
-
getTheadThTemplate
Returns the header cell template for even columns.- Returns:
- the headerColumnTemplate
-
setTheadThTemplate
Sets the header cell template for even columns.- Parameters:
headerColumnTemplate- the headerColumnTemplate to set
-
getTheadThTemplate2
Returns the header cell template for odd columns.- Returns:
- the headerColumnTemplate2
-
setTheadThTemplate2
Sets the header cell template for odd columns.- Parameters:
headerColumnTemplate2- the headerColumnTemplate2 to set
-
getTbodyTemplate
Returns the table body template.- Returns:
- the bodyTemplate
-
setTbodyTemplate
Sets the body template.- Parameters:
bodyTemplate- the bodyTemplate to set
-
getTbodyTrTemplate
Returns the row template for even data rows.- Returns:
- the bodyRowTemplate
-
setTbodyTrTemplate
Sets the row template for even data rows.- Parameters:
bodyRowTemplate- the bodyRowTemplate to set
-
getTbodyTrTemplate2
Returns the row template for odd data rows.- Returns:
- the bodyRowTemplate2
-
setTbodyTrTemplate2
Sets the row template for odd data rows.- Parameters:
bodyRowTemplate2- the bodyRowTemplate2 to set
-
getTbodyTdTemplate
Returns the data cell template for even columns.- Returns:
- the dataColumnTemplate
-
setTbodyTdTemplate
Sets the data cell template for even columns.- Parameters:
dataColumnTemplate- the dataColumnTemplate to set
-
getTbodyTdTemplate2
Returns the data cell template for odd columns.- Returns:
- the dataColumnTemplate2
-
setTbodyTdTemplate2
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
Makes HTML encoding for the string.- Parameters:
s- the string ready to be used in HTML- Returns:
- HTML encoded string
-
getHeader
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
-