|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.evanmclean.evlib.sql.RsXml
public class RsXml
Converts a result set to XML output. In it's simplest form it writes one output record for each input record. It can also output sub-records to any level, based on break values of columns that can change for each row.
Field Summary | |
---|---|
static String |
DEFAULT_DATE_FORMAT
The default format used ("yyyy-MM-dd") to convert a date column to a string. |
static String |
DEFAULT_ENCODING
The default encoding ("ISO-8859-1") which will be written to the XML declaration. |
static String |
DEFAULT_TIME_FORMAT
The default format used ("HH:mm:ss.SSS") to convert a time column to a string. |
static String |
DEFAULT_TIMESTAMP_FORMAT
The default format used ("yyyy-MM-dd HH:mm:ss.SSS") to convert a timestamp column to a string. |
Constructor Summary | |
---|---|
RsXml()
Default constructor. |
|
RsXml(ResultSet rs)
Sets the record set to be used. |
|
RsXml(ResultSet rs,
String record_name)
Sets the record set and single record name to be used, thus writing one record per row returned in the result set, and including all columns. |
|
RsXml(ResultSet rs,
String container_element_name,
String record_name)
Sets the record set, container name and single record name to be used, thus writing one record per row returned in the result set, and including all columns. |
|
RsXml(ResultSet rs,
String record_name,
String[] columns)
Sets the record set and single record name to be used, thus writing one record per row returned in the result set, and including only the specified columns. |
|
RsXml(ResultSet rs,
String container_element_name,
String record_name,
String[] columns)
Sets the record set, container name and single record name to be used, thus writing one record per row returned in the result set, only including the specified columns. |
Method Summary | |
---|---|
void |
clearCdataColumns()
Clear the list of the columns to be wrapped in a <![CDATA[
container instead of the usual XML encoding. |
void |
clearColumnAliases()
Clear all the column aliases. |
void |
clearContainerElementName()
No container element (and hence, no XML declaration) will be written on a call to write. |
void |
clearEncoding()
No encoding attribute will be written in the XML declaration. |
protected void |
closingLevel(Writer out,
int lvl,
String record_name)
Called just before closing the level, allowing any specialised action to take place. |
boolean |
eors()
Indicates if we have reached the end of the record set. |
String[][] |
getBreakColumns()
The break columns being used. |
String[] |
getCdataColumns()
A list of the columns to be wrapped in a <![CDATA[
container instead of the usual XML encoding. |
String[][] |
getColumnAliases()
By default, the column name is used as the element name, however aliases can be used. |
String[][] |
getColumns()
The columns to be written at each level. |
String |
getContainerAttributes()
A snippet of XML attributes that will be written at part of the container element (default none). |
String |
getContainerElementElementName()
The name of the container element that will be written surrounding all the records in the next write. |
protected String |
getDate(Object obj,
String column,
int sql_type)
Converts a date to a string. |
DateFormat |
getDateFormat()
For formatting object used to convert date columns to strings. |
protected String |
getDouble(Object obj,
String column,
int sql_type)
Converts a float or double to a string, trimming any trailing zeros and decimal point. |
String |
getEncoding()
The value of the encoding attribute that will be written in the XML declaration (e.g. |
String |
getLineSeperator()
The line separator to be used after the XML declaration, and for pretty printing (default is system property). |
String |
getNullSnippet()
If the column is null, then then this XML snipped is included in the element being written (default blank). |
Object |
getObject(String name)
Return the specified object from the last row read. |
Object[] |
getObjects()
Return the objects from the last row read. |
String[] |
getRecordNames()
The record names being used. |
ResultSet |
getResultSet()
Gets the result set to be read, or null if it has not been set yet. |
protected String |
getTime(Object obj,
String column,
int sql_type)
Converts a time to a string, removing any trailing zeros or decimal point. |
DateFormat |
getTimeFormat()
For formatting object used to convert time columns to strings. |
protected String |
getTimestamp(Object obj,
String column,
int sql_type)
Converts a timestamp to a string, removing any trailing zeros or decimal point. |
DateFormat |
getTimestampFormat()
For formatting object used to convert timestamp columns to strings. |
protected String |
getValue(Object obj,
String column,
int sql_type)
Converts the object retrieved from the result set to a string. |
boolean |
isEmptyAsOpenAndCloseElement()
By default, elements with an empty (or null) value will be written as a single element (e.g. |
boolean |
isIncludeXmlDeclaration()
Indicates if the XML declaration (i.e. |
boolean |
isLowercase()
Indicates if all column names (not including aliased columns) are forced to lowercase before being written as element names (default true). |
boolean |
isPrettyIndent()
Indicates if the XML is written with newlines and indentation (default true when pretty print is true, false otherwise). |
boolean |
isPrettyPrint()
Indicates if the XML is written with newlines and (possibly) indentation (default false). |
protected void |
openingLevel(Writer out,
int lvl,
String record_name)
Called just after opening the level, allowing any specialised action to take place. |
int |
read()
The number of individual rows read from the record set in the last write operation. |
void |
setCdataColumns(String[] colmns)
A list of the columns to be wrapped in a <![CDATA[
container instead of the usual XML encoding. |
void |
setColumnAliases(Map<? extends String,? extends String> column_aliases)
By default, the column name is used as the element name, however aliases can be used. |
void |
setColumnAliases(String[][] column_aliases)
By default, the column name is used as the element name, however aliases can be used. |
void |
setContainerAttributes(String container_attributes)
A snippet of XML attributes that will be written at part of the container element (default none). |
void |
setContainerElementName(String container_element_name)
The name of the container element that will be written surrounding all the records in the next write. |
void |
setDateFormat(DateFormat date_format)
For formatting object used to convert date columns to strings. |
void |
setEmptyAsOpenAndCloseElement(boolean empty_as_open_and_close_element)
By default, elements with an empty (or null) value will be written as a single element (e.g. |
void |
setEncoding(String enc)
The value of the encoding attribute that will be written in the XML declaration (e.g. |
void |
setIncludeXmlDeclaration(boolean include_xml_declaration)
Indicates if the XML declaration (i.e. |
void |
setLineSeperator(String line_separator)
The line separator to be used after the XML declaration, and for pretty printing (default is system property). |
void |
setLowercase(boolean lwrcase)
Set if all column names (not including aliased columns) are forced to lowercase before being written as element names (default true). |
void |
setNullSnippet(String null_snippet)
If the column is null, then then this XML snipped is included in the element being written (default blank). |
protected Object |
setObject(String name,
Object newobj)
Set the object for the specified column. |
void |
setPretty(boolean pretty_print,
boolean pretty_indent)
Indicates if the XML is written with newlines and indentation (default false). |
void |
setPrettyPrint(boolean pretty_print)
Indicates if the XML is written with newlines and indentation (default false). |
void |
setRecord(String record_name)
Sets the record name to be used, thus writing one record per row returned in the result set, and including all columns. |
void |
setRecord(String record_name,
String[] columns_filter)
Sets the single record name to be used, thus writing one record per row returned in the result set, and including only the specified columns. |
void |
setRecords(String[] record_names,
String[][] break_columns,
String[][] columns_filter)
Sets the details of the XML records to be written, with sub-records possible. |
void |
setResultSet(ResultSet new_rs)
Sets the result set to be read for producing the XML. |
void |
setTimeFormat(DateFormat time_format)
For formatting object used to convert time columns to strings. |
void |
setTimestampFormat(DateFormat timestamp_format)
For formatting object used to convert timestamp columns to strings. |
int |
totalRead()
The total number of individual rows read from the record set across all write operations. |
int |
totalWritten()
The total number of top level records written in across all write operations. |
protected String |
trimTrailingZeros(String str)
Utility function that, if the string contains a decimal point, trims trailing zeros (up to and including the decimal point) off the end of the string. |
void |
write(Writer out)
Write all remaining records from the result set as XML to the specified writer. |
boolean |
write(Writer out,
int limit)
Write records from the result set as XML to the specified writer. |
protected void |
writeElement(Writer out,
String element_name,
String value,
boolean cdata)
|
int |
written()
The number of top level records written in the last write operation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_ENCODING
public static final String DEFAULT_DATE_FORMAT
public static final String DEFAULT_TIME_FORMAT
public static final String DEFAULT_TIMESTAMP_FORMAT
Constructor Detail |
---|
public RsXml()
public RsXml(ResultSet rs)
rs
- Result set to use.public RsXml(ResultSet rs, String record_name)
rs
- Result set to use.record_name
- The single record name to be used.public RsXml(ResultSet rs, String container_element_name, String record_name)
rs
- Result set to use.container_element_name
- The name of container element to be written, surrounding all the
records written.record_name
- The single record name to be used.public RsXml(ResultSet rs, String container_element_name, String record_name, String[] columns)
rs
- Result set to use.container_element_name
- The name of container element to be written, surrounding all the
records written.record_name
- The single record name to be used.columns
- The only columns that will be written in the XML output.public RsXml(ResultSet rs, String record_name, String[] columns)
rs
- Result set to use.record_name
- The single record name to be used.columns
- The only columns that will be written in the XML output.Method Detail |
---|
public void clearCdataColumns()
<![CDATA[
container instead of the usual XML encoding.
public void clearColumnAliases()
public void clearContainerElementName()
public void clearEncoding()
public boolean eors() throws SQLException
SQLException
public String[][] getBreakColumns()
public String[] getCdataColumns()
<![CDATA[
container instead of the usual XML encoding.
public String[][] getColumnAliases()
public String[][] getColumns()
public String getContainerAttributes()
xmlns:h="http://www.w3.org/TR/html4/"
public String getContainerElementElementName()
public DateFormat getDateFormat()
public String getEncoding()
<?xml version="1.0" encoding="ISO-8859-1"?>
"). By default the value is specified by the DEFAULT_ENCODING
field. If this is an empty string then no encoding attribute will be
written.
public String getLineSeperator()
public String getNullSnippet()
null="true"
" then the element will be
written as "<element null="true" />
".
public Object getObject(String name)
name
- The column name.
public Object[] getObjects()
public String[] getRecordNames()
public ResultSet getResultSet()
public DateFormat getTimeFormat()
public DateFormat getTimestampFormat()
public boolean isEmptyAsOpenAndCloseElement()
<element /gt;
"). If
this is true then it will be written as an open element followed by a close
element (e.g. "<element></element>
").
public boolean isIncludeXmlDeclaration()
<?xml version="1.0"?>
" will be
written at the start of the write (default true). Note: The XML
declaration will not be written if a container name has not been specified
regardless of the value of this flag.
public boolean isLowercase()
public boolean isPrettyIndent()
public boolean isPrettyPrint()
public int read()
public void setCdataColumns(String[] colmns)
<![CDATA[
container instead of the usual XML encoding.
colmns
- The list of columns.public void setColumnAliases(Map<? extends String,? extends String> column_aliases)
column_aliases
- The column names and aliases to be used.public void setColumnAliases(String[][] column_aliases)
column_aliases
- The column names and aliases to be used.public void setContainerAttributes(String container_attributes)
xmlns:h="http://www.w3.org/TR/html4/"
container_attributes
- A snippet of XML attributes to be included, or a blank/null string
to indicae no attributes.public void setContainerElementName(String container_element_name)
container_element_name
- The name of the container element, or blank/null to indicate no
container element is to be written.public void setDateFormat(DateFormat date_format)
date_format
- public void setEmptyAsOpenAndCloseElement(boolean empty_as_open_and_close_element)
<element /gt;
"). If
this is true then it will be written as an open element followed by a close
element (e.g. "<element></element>
").
empty_as_open_and_close_element
- public void setEncoding(String enc)
<?xml version="1.0" encoding="ISO-8859-1"?>
"). By default the value is specified by the DEFAULT_ENCODING
field. If this is a blank string or null then no encoding attribute will be
written.
enc
- The value of the encoding attribute, or a blank/null string to
indicate no encoding attribute is to be written.public void setIncludeXmlDeclaration(boolean include_xml_declaration)
<?xml version="1.0"?>
") will be
written at the start of the write (default true). Note: The XML
declaration will not be written if a container name has not been specified
regardless of the value of this flag.
include_xml_declaration
- public void setLineSeperator(String line_separator)
line_separator
- The line separator string to use. If empty or null then the system
default will be used.public void setLowercase(boolean lwrcase)
lwrcase
- True if all column names are forced to lowercase before being
written.public void setNullSnippet(String null_snippet)
null="true"
" then the element will be
written as "<element null="true" />
".
null_snippet
- public void setPretty(boolean pretty_print, boolean pretty_indent)
pretty_print
- pretty_indent
- public void setPrettyPrint(boolean pretty_print)
pretty_print
- public void setRecord(String record_name)
record_name
- The single record name to be used.public void setRecord(String record_name, String[] columns_filter)
record_name
- The single record name to be used.columns_filter
- The only columns that will be written in the XML output.public void setRecords(String[] record_names, String[][] break_columns, String[][] columns_filter)
record_names
- The record element names to be used for each level.break_columns
- The columns used at each level to indicate when a new sub record is
to be written. The length of this array is one less than then
record_names.columns_filter
- The columns to be written at each record level. It's length is
usually equal to the length of the record names array, however if it
is one less, then all the columns that have not been specified so
far are written in the lowest level record.public void setResultSet(ResultSet new_rs)
new_rs
- The result set to be read to product the XML. May not be null.public void setTimeFormat(DateFormat time_format)
time_format
- public void setTimestampFormat(DateFormat timestamp_format)
timestamp_format
- public int totalRead()
public int totalWritten()
totalRead()
value.
public void write(Writer out) throws IOException, SQLException
eors()
to avoid this.
out
- The writer to write the XML to.
IOException
SQLException
public boolean write(Writer out, int limit) throws IOException, SQLException
eors()
to
avoid this.
out
- The writer to write the XML to.limit
- The maximum number of (top-level) records to write (or 0 for all
remaining records).
IOException
SQLException
public int written()
read()
value.
protected void closingLevel(Writer out, int lvl, String record_name) throws IOException
out
- The writer we are sending our XML to.lvl
- The level that is being closed.record_name
- The record that is being closed.
IOException
- Can be thrown if there is an issue.protected String getDate(Object obj, String column, int sql_type)
obj
- column
- sql_type
-
protected String getDouble(Object obj, String column, int sql_type)
obj
- column
- sql_type
-
protected String getTime(Object obj, String column, int sql_type)
obj
- column
- sql_type
-
protected String getTimestamp(Object obj, String column, int sql_type)
obj
- column
- sql_type
-
protected String getValue(Object obj, String column, int sql_type)
obj
- The object from the result set.column
- The name of the column.sql_type
- The SQL type of the column, a constant from java.sql.Types.
protected void openingLevel(Writer out, int lvl, String record_name)
out
- The writer we are sending our XML to.lvl
- The level that is being closed.record_name
- The record that is being closed.protected Object setObject(String name, Object newobj)
name
- The column name.newobj
- The new object to put in it's place.
protected String trimTrailingZeros(String str)
str
-
protected void writeElement(Writer out, String element_name, String value, boolean cdata) throws IOException
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |