Package csv.impl
Class XmlWriter
java.lang.Object
csv.impl.AbstractTableWriter
csv.impl.AbstractStreamTableWriter
csv.impl.XmlWriter
- All Implemented Interfaces:
TableWriter
Writer implementation for XML streams.
- Author:
- ralph
-
Constructor Summary
ConstructorDescriptionConstructor.Constructor.Constructor.XmlWriter
(OutputStream out) Constructor.XmlWriter
(OutputStream out, boolean writeHeaderRow) Constructor.Constructor.Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Prints the closing of the XML file before closing the stream.protected String
Encodes the object for usage in XML file.protected String
getColumnEndTag
(int column) Returns column's closing tagprotected String
getColumnName
(int index) Returns the column name at given index.Returns the name of the attribute within column tag that contains the column name.protected String
getColumnStartTag
(int column, Object value) Returns the complete start tag for the column.protected String
getColumnTagAttributes
(int column, Object value) Returns all attributes that need to be set for a column opening tag.Returns the name of the column tag.protected String
getColumnTagName
(int column) Returns correct column name.protected String
getColumnType
(Object value) Returns the type of the value to be set as attribute in column opening tag.Returns the name of the attribute in the column tag that contains the Java type of the value.protected String
getDefaultColumnName
(int index) Creates a default name for the column.Returns the encoding string for XML header.Object[]
Returns the header column names.Returns the name of the row tag.Returns the XML root tag name.protected void
init()
Initializes the writer.boolean
Returns whether column tag names will be equal to column names.boolean
Returns true when the first row being written contains the column names.void
printComment
(String comment) Prints the comment into the stream.void
printComment
(String comment, int row, int column) Prints the comment at the given location.protected void
Prints the footer.protected void
Prints the header.void
Prints the row into the stream.void
setColumnNameAttribute
(String columnNameAttribute) Sets the name of the attribute within column tag that contains the column name.void
setColumnTagName
(String columnTagName) Sets the name of teh column tag.void
setColumnTypeAttribute
(String columnTypeAttribute) Sets the name of the attribute in the column tag that contains the Java type of the value.void
setEncoding
(String encoding) Sets the encoding string for XML header.void
setHeaderColumns
(Object[] headerColumns) Sets the header column names explicitely.void
setRowTagName
(String rowTagName) Set the name of the row tag.void
setTopLevelTagName
(String topLevelTagName) Sets the XML root tag name.void
setUseColumnNameTags
(boolean useColumnNameTags) Sets whether column tag names will be equal to column names.void
setWriteHeaderRow
(boolean writeHeaderRow) Sets whether the first row being written contains the column names.Methods inherited from class csv.impl.AbstractStreamTableWriter
createOutputStreamWriter, createWriter, getCharsetEncoder, getOutputStream, getWriter, setCharset, setCharset, setCharsetEncoder, setOutputStream
Methods inherited from class csv.impl.AbstractTableWriter
convert, getMapper, getRowCount, incrementRowCount, printRow, printRow, printRow, setMapper
-
Constructor Details
-
XmlWriter
public XmlWriter()Constructor. -
XmlWriter
Constructor.- Parameters:
out
- output stream
-
XmlWriter
Constructor.- Parameters:
out
- output streamwriteHeaderRow
- whether a dedicated header row will be received as first row
-
XmlWriter
Constructor.- Parameters:
file
- output file- Throws:
IOException
- if exception occurs
-
XmlWriter
Constructor.- Parameters:
file
- output filewriteHeaderRow
- whether a dedicated header row will be received as first row- Throws:
IOException
- if exception occurs
-
XmlWriter
Constructor.- Parameters:
file
- file to write- Throws:
IOException
- if exception occurs
-
XmlWriter
Constructor.- Parameters:
file
- file to writewriteHeaderRow
- whether a dedicated header row will be received as first row- Throws:
IOException
- if exception occurs
-
-
Method Details
-
close
public void close()Prints the closing of the XML file before closing the stream.- Specified by:
close
in interfaceTableWriter
- Overrides:
close
in classAbstractStreamTableWriter
- See Also:
-
init
protected void init()Initializes the writer.- Overrides:
init
in classAbstractTableWriter
- See Also:
-
printRow
Prints the row into the stream. The first row must contain the column names ifsetWriteHeaderRow(boolean)
was set.- Parameters:
columns
- columns to be written in row- Throws:
IOException
- when an exception occurs- See Also:
-
getColumnStartTag
Returns the complete start tag for the column.- Parameters:
column
- index of columnvalue
- value in column- Returns:
- start tag, will include combined closing tag if value is null
-
getColumnEndTag
Returns column's closing tag- Parameters:
column
- column index- Returns:
- closing column tag
-
getColumnTagName
Returns correct column name.- Parameters:
column
- index of column- Returns:
- column name
- See Also:
-
getColumnTagAttributes
Returns all attributes that need to be set for a column opening tag.- Parameters:
column
- index of columnvalue
- value of column- Returns:
- all attributes
-
getColumnType
Returns the type of the value to be set as attribute in column opening tag.- Parameters:
value
- value of column- Returns:
- column type
-
printComment
Prints the comment into the stream.- Specified by:
printComment
in interfaceTableWriter
- Overrides:
printComment
in classAbstractTableWriter
- Parameters:
comment
- the comment to write- Throws:
IOException
- when an exception occurs- See Also:
-
printComment
Prints the comment at the given location.- Specified by:
printComment
in interfaceTableWriter
- Overrides:
printComment
in classAbstractTableWriter
- Parameters:
comment
- the comment to writerow
- index of row for commentcolumn
- index of column for comment- Throws:
IOException
- when an exception occurs- See Also:
-
printHeader
protected void printHeader()Prints the header. -
encode
Encodes the object for usage in XML file.- Parameters:
s
- object to encode- Returns:
- XML encoded string
-
getColumnName
Returns the column name at given index. The method will pass on togetDefaultColumnName(int)
if no column header can be found.- Parameters:
index
- index of column- Returns:
- column name
-
getDefaultColumnName
Creates a default name for the column. The name is "column" plus the index- Parameters:
index
- index of column- Returns:
- default column name
-
getTopLevelTagName
Returns the XML root tag name.- Returns:
- the topLevelTagName
-
setTopLevelTagName
Sets the XML root tag name.- Parameters:
topLevelTagName
- the topLevelTagName to set
-
getRowTagName
Returns the name of the row tag.- Returns:
- the rowTagName
-
setRowTagName
Set the name of the row tag.- Parameters:
rowTagName
- the rowTagName to set
-
getColumnTagName
Returns the name of the column tag. This property will be used only whensetUseColumnNameTags(boolean)
was not set.- Returns:
- the columnTagName
-
setColumnTagName
Sets the name of teh column tag. This property will be used only whensetUseColumnNameTags(boolean)
was not set.- Parameters:
columnTagName
- the columnTagName to set
-
isUseColumnNameTags
public boolean isUseColumnNameTags()Returns whether column tag names will be equal to column names.- Returns:
- the useColumnNameTags
-
setUseColumnNameTags
public void setUseColumnNameTags(boolean useColumnNameTags) Sets whether column tag names will be equal to column names.- Parameters:
useColumnNameTags
- the useColumnNameTags to set
-
getColumnNameAttribute
Returns the name of the attribute within column tag that contains the column name. This property will be used only whensetUseColumnNameTags(boolean)
was not set.- Returns:
- the columnNameAttribute
-
setColumnNameAttribute
Sets the name of the attribute within column tag that contains the column name. This property will be used only whensetUseColumnNameTags(boolean)
was not set.- Parameters:
columnNameAttribute
- the columnNameAttribute to set
-
getColumnTypeAttribute
Returns the name of the attribute in the column tag that contains the Java type of the value.- Returns:
- the columnTypeAttribute
-
setColumnTypeAttribute
Sets the name of the attribute in the column tag that contains the Java type of the value.- Parameters:
columnTypeAttribute
- the columnTypeAttribute to set
-
getEncoding
Returns the encoding string for XML header.- Returns:
- the encoding
-
setEncoding
Sets the encoding string for XML header.- Parameters:
encoding
- the encoding to set
-
getHeaderColumns
Returns the header column names.- Returns:
- the headerColumns
-
setHeaderColumns
Sets the header column names explicitely.- Parameters:
headerColumns
- the headerColumns to set
-
isWriteHeaderRow
public boolean isWriteHeaderRow()Returns true when the first row being written contains the column names.- Returns:
- the writeHeaderRow
-
setWriteHeaderRow
public void setWriteHeaderRow(boolean writeHeaderRow) Sets whether the first row being written contains the column names.- Parameters:
writeHeaderRow
- the writeHeaderRow to set
-