Package csv.impl
Class HtmlWriter
java.lang.Object
csv.impl.AbstractTableWriter
csv.impl.AbstractStreamTableWriter
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
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_TABLE_TEMPLATEstatic java.lang.StringDEFAULT_TBODY_TD_TEMPLATEstatic java.lang.StringDEFAULT_TBODY_TD_TEMPLATE2static java.lang.StringDEFAULT_TBODY_TEMPLATEstatic java.lang.StringDEFAULT_TBODY_TR_TEMPLATEstatic java.lang.StringDEFAULT_TBODY_TR_TEMPLATE2static java.lang.StringDEFAULT_THEAD_TEMPLATEstatic java.lang.StringDEFAULT_THEAD_TH_TEMPLATEstatic java.lang.StringDEFAULT_THEAD_TH_TEMPLATE2static java.lang.StringDEFAULT_THEAD_TR_TEMPLATE -
Constructor Summary
Constructors Constructor Description HtmlWriter()Default Constructor.HtmlWriter(java.io.File file)HtmlWriter(java.io.OutputStream out)HtmlWriter(java.lang.String file) -
Method Summary
Modifier and Type Method Description voidclose()Closes the writer by printing the footer of the table.static java.lang.StringencodeHtml(java.lang.String s)Makes HTML encoding for the string.intgetCurrentRowIndex()Returns the current data row index.protected static java.lang.StringgetFooter(java.lang.String template)Returns the footer part of the given templateprotected static java.lang.StringgetHeader(java.lang.String template)Returns the header part of the given templatejava.lang.StringgetTableTemplate()Returns the main table template.java.lang.StringgetTbodyTdTemplate()Returns the data cell template for even columns.java.lang.StringgetTbodyTdTemplate2()Returns the data cell template for odd columns.java.lang.StringgetTbodyTemplate()Returns the table body template.java.lang.StringgetTbodyTrTemplate()Returns the row template for even data rows.java.lang.StringgetTbodyTrTemplate2()Returns the row template for odd data rows.java.lang.StringgetTheadTemplate()Returns the header template.java.lang.StringgetTheadThTemplate()Returns the header cell template for even columns.java.lang.StringgetTheadThTemplate2()Returns the header cell template for odd columns.java.lang.StringgetTheadTrTemplate()Returns the header row template.protected voidinit()General initialization.booleanisHasHeaderRow()Returns true if this writer will create a header row.booleanisTableHeaderWritten()Returns whether the table header (table tag) was written.voidprintColumnContent(java.lang.Object o, int rowIndex, int columnIndex)Prints the value of this object only without any enclosing tags.voidprintDataRow(java.lang.Object[] columns, int rowIndex)Prints a data row to the underlying streamvoidprintHeaderRow(java.lang.Object[] columns)Prints the header row into the stream.voidprintRow(java.lang.Object[] columns)Prints the row.voidprintTableBodyFooter()Prints the table body (tbody) footer into the underlying stream.voidprintTableBodyHeader()Prints 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.voidprintTableFooter()Prints 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.voidprintTableHeader()Prints the table header into the underlying stream.voidprintTableHeadFooter()Prints the table head (thead) footer into the underlying stream.voidprintTableHeadHeader()Prints the table head (thead) header into the underlying stream.voidprintTableHeadRowFooter()Prints the table header row (tr) footer into the underlying stream.voidprintTableHeadRowHeader()Prints the table header row (tr) header into the underlying stream.voidsetHasHeaderRow(boolean hasHeaderRow)Sets whether writer will create a header row.voidsetTableTemplate(java.lang.String tableTemplate)Sets the main table template.voidsetTbodyTdTemplate(java.lang.String dataColumnTemplate)Sets the data cell template for even columns.voidsetTbodyTdTemplate2(java.lang.String dataColumnTemplate2)Sets the data cell template for odd columns.voidsetTbodyTemplate(java.lang.String bodyTemplate)Sets the body template.voidsetTbodyTrTemplate(java.lang.String bodyRowTemplate)Sets the row template for even data rows.voidsetTbodyTrTemplate2(java.lang.String bodyRowTemplate2)Sets the row template for odd data rows.voidsetTheadTemplate(java.lang.String headerTemplate)Sets the header template.voidsetTheadThTemplate(java.lang.String headerColumnTemplate)Sets the header cell template for even columns.voidsetTheadThTemplate2(java.lang.String headerColumnTemplate2)Sets the header cell template for odd columns.voidsetTheadTrTemplate(java.lang.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, convert, getRowCount, getTypeConversionHandler, incrementRowCount, printComment, printComment, printRow, printRow, printRow, registerTypeConversionHandler, unregisterTypeConversionHandler
-
Field Details
-
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 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:
closein interfaceTableWriter- Overrides:
closein classAbstractStreamTableWriter- See Also:
AbstractStreamTableWriter.close()
-
init
protected void init()Description copied from class:AbstractTableWriterGeneral initialization. This implementation does nothing.- Overrides:
initin classAbstractTableWriter- See Also:
AbstractTableWriter.init()
-
printRow
public void printRow(java.lang.Object[] columns) throws java.io.IOExceptionPrints 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 writtenrowIndex- 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 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. -
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
-