public abstract class csvWriter2 extends HttpServlet
The methods getResultSet and makeConnection are abstract and will need to be overridden before this class can be used. The user may also wish to override several of the methods for formatting information.
This is the class that is currently used by com.amtrak.eng.servlets.downloadDataServlet and com.amtrak.eng.tests.testServlet. After bradleyross.library.servlets.csvWriter is modified to make the variables local to the service method, the classes in com.amtrak.eng should be modified to make use of that version.
Modifier and Type | Field and Description |
---|---|
protected int |
columnCount
Deprecated.
Number of columns in result set
|
protected ServletConfig |
config
Deprecated.
ServletConfig object as passed to the init method.
|
protected DatabaseProperties |
data
Deprecated.
Object containing database connection information.
|
protected String |
message
Deprecated.
String to be placed in CSV file as the first line in the file.
|
protected PrintWriter |
output
Deprecated.
Object representing the output to the HTTP response.
|
protected String |
outputFilename
Deprecated.
File name to be used when creating file.
|
protected ResultSet |
rs
Deprecated.
Object containing the result set.
|
protected ResultSetMetaData |
rsmd
Deprecated.
Object containing meta data on result set.
|
private static long |
serialVersionUID
Deprecated.
|
Constructor and Description |
---|
csvWriter2()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Deprecated.
|
protected String |
formatDateTime(Date valueIn)
Deprecated.
Alternate calling sequence, leaving out the column number
|
protected String |
formatDateTime(Date valueIn,
int column)
Deprecated.
Formatter for values involving date and time.
|
protected String |
formatDouble(double valueIn)
Deprecated.
Alternate calling sequence, leaving out the column number.
|
protected String |
formatDouble(double valueIn,
int column)
Deprecated.
Formatter for floating point numbers.
|
protected String |
formatInteger(int valueIn)
Deprecated.
Alternate calling sequence, omitting the column number.
|
protected String |
formatInteger(int valueIn,
int column)
Deprecated.
Formatter for integer values.
|
protected String |
formatString(String valueIn)
Deprecated.
Method of calling formatString when it doesn't
depend on the column in the result set.
|
protected String |
formatString(String valueIn,
int column)
Deprecated.
Double up on all double quotes in string and surround the string with
double quotes so that it will be in the proper format for the CSV file.
|
protected abstract ResultSet |
getResultSet(HttpServletRequest req)
Deprecated.
Will be overridden with the method for obtaining the SQL
result set.
|
void |
init(ServletConfig configIn)
Deprecated.
|
protected abstract DatabaseProperties |
makeConnection()
Deprecated.
Obtain the database connection information.
|
protected void |
printHeader()
Deprecated.
Will print header line for CSV file.
|
protected void |
printLine()
Deprecated.
Will print one line of CSV file.
|
void |
service(HttpServletRequest req,
HttpServletResponse res)
Deprecated.
|
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
private static final long serialVersionUID
protected String outputFilename
Changes to this field can be placed in the method getResultSet.
protected String message
Changes to this field can be placed in the method getResultSet.
protected DatabaseProperties data
This field is set by the makeConnection method.
makeConnection()
protected ResultSet rs
This object is created by the getResultMethod method which is called by the service method.
protected ResultSetMetaData rsmd
This object is created by the service method after the execution of the getResultSet method and before the execution of the printHeader method.
protected PrintWriter output
protected int columnCount
protected ServletConfig config
public csvWriter2()
public void init(ServletConfig configIn) throws ServletException
init
in interface Servlet
init
in class GenericServlet
ServletException
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException
service
in class HttpServlet
req
- Object containing request informationres
- Object containing response informationIOException
protected abstract DatabaseProperties makeConnection() throws IOException
IOException
protected abstract ResultSet getResultSet(HttpServletRequest req) throws IOException
Changes to fields such as message and outputFilename can go in this method.
req
- Request informationIOException
message
,
outputFilename
protected void printHeader() throws IOException
IOException
protected void printLine() throws IOException
This method will be changed at a later time to allow the specification of overriding methods for formatting timestamps, integers, floating point numbers, character strings, etc.
IOException
protected String formatString(String valueIn)
valueIn
- String to be processedprotected String formatString(String valueIn, int column)
valueIn
- String to be processedcolumn
- Column number of item (not used unless method overriden)protected String formatDouble(double valueIn)
valueIn
- Floating point number to be formattedprotected String formatDouble(double valueIn, int column)
This method can be overridden to control printing of the values in the CSV file.
valueIn
- Floating point number to be processedcolumn
- Column numberprotected String formatInteger(int valueIn)
valueIn
- Integer value to be formattedprotected String formatInteger(int valueIn, int column)
This method can be overridden to control printing of the values in the CSV file.
valueIn
- Integer to be formattedcolumn
- Column numberprotected String formatDateTime(Date valueIn)
valueIn
- java.util.Date object containing date and timeprotected String formatDateTime(Date valueIn, int column)
This method can be overridden to control printing of the values in the CSV file.
valueIn
- java.util.Date object containing date and timecolumn
- Column number