|
MDi JLib 1.7.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.microdeveloper.servlets.io.DbFileDriver
public abstract class DbFileDriver
Abstract servlet for SQL output as download responses in the form of a file download. Extend this class as the basis for taking SQL queries and sending the formatted results back to the client in the form of a file download. The type sent is controlled by the response header which is defined in the returnFile method. The connection to the database is managed by the db package and referenced in this class. The connection criteria is derived from the environment by locating the session variables, validated, userId, password, and dbUrlPrefix. If the user is not validated, the standard response is to redirect to the site index.
Field Summary | |
---|---|
protected String[] |
credentials
Full database credential string |
protected String |
CRLF
Field CRLF |
protected String |
ERRAUTHORIZED
Error response given when the user attempts to run a report for which they have no authorization |
protected String |
ERRDBCONN
Error response when the database connection fails |
protected String |
ERRHEADING
Error response heading |
protected String |
ERRINITPARM
Error response given when an invalid open parameter is processed |
protected String |
ERRNODATA
Error response when no data is found that match the report criteria |
protected String |
ERRNOPARMS
Error response when no parameters are given and parameters are expected |
protected String |
ERRSQL
Error response given when the SQL instruction fails |
protected String |
ERRVALIDATED
Error response when the user is not validated. |
protected String |
outFile
Fully qualified filename of the desired output file |
protected String |
parameterForm
URL to the parameter form if any |
protected HashMap |
parameterMap
Parameter map for a given report |
protected String |
reportName
Name of the report |
protected HttpSession |
session
HTTP session variable |
protected String |
TITLE
Report title |
Constructor Summary | |
---|---|
DbFileDriver()
|
Method Summary | |
---|---|
void |
destroy()
Destroys the servlet. |
protected void |
doGet(HttpServletRequest request,
HttpServletResponse response)
Handles the HTTP GET method. |
protected void |
doPost(HttpServletRequest request,
HttpServletResponse response)
Handles the HTTP POST method. |
HashMap |
getParameterMap(HttpServletRequest request,
HttpServletResponse response)
Returns the parameter map for the servlet |
String |
getParameterValue(Object key)
Returns the value for a given parameter. |
String |
getServletInfo()
Returns a short description of the servlet. |
void |
init(ServletConfig config)
Initializes the servlet. |
boolean |
isAuthorized(String reportName)
Determines if the user is authorized to run the report or not |
boolean |
isKeyInMap(Object key)
Determines if the parameter object key exists in the parameter map or not |
void |
parameterPage(HttpServletRequest request,
HttpServletResponse response)
Returns the parameter page for the give report servlet. |
protected void |
processRequest(HttpServletRequest request,
HttpServletResponse response)
Processes requests for both HTTP GET and POST methods. |
void |
returnError(String message,
HttpServletRequest request,
HttpServletResponse response)
Returns the error response using a standard HTML response template. |
abstract void |
returnFile(Connection conn,
HttpServletRequest request,
HttpServletResponse response)
Returns the result of the SQL query as a file download. |
void |
writeOutput(PreparedStatement stmt,
HttpServletRequest request,
HttpServletResponse response)
Writes the output to the response writer. |
Methods inherited from class javax.servlet.http.HttpServlet |
---|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
---|
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface javax.servlet.Servlet |
---|
getServletConfig, service |
Field Detail |
---|
protected HashMap parameterMap
protected final String TITLE
protected final String ERRHEADING
protected final String ERRDBCONN
protected final String ERRNOPARMS
protected final String ERRNODATA
protected final String ERRSQL
protected final String ERRINITPARM
protected final String ERRVALIDATED
protected final String ERRAUTHORIZED
protected String parameterForm
protected String[] credentials
protected HttpSession session
protected String reportName
protected String outFile
protected final String CRLF
Constructor Detail |
---|
public DbFileDriver()
Method Detail |
---|
public void init(ServletConfig config) throws ServletException
init
in interface Servlet
init
in class GenericServlet
config
- Determines where to locate the configuration parameters for a given report
ServletException
- Thrown when a servlet exception occurspublic void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
public abstract void returnFile(Connection conn, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException
conn
- the database connection objectrequest
- servlet requestresponse
- servlet response
ServletException
- Thrown when a servlet exception occurs
IOException
SQLException
public String getServletInfo()
getServletInfo
in interface Servlet
getServletInfo
in class GenericServlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
GET
and POST
methods.
request
- servlet requestresponse
- servlet response
ServletException
- Thrown when a servlet exception occurs
IOException
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
GET
method.
doGet
in class HttpServlet
request
- servlet requestresponse
- servlet response
ServletException
- Thrown when a servlet exception occurs
IOException
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
POST
method.
doPost
in class HttpServlet
request
- servlet requestresponse
- servlet response
ServletException
- Thrown when a servlet exception occurs
IOException
public void returnError(String message, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
message
- the error message or html to returnrequest
- servlet requestresponse
- servlet response
ServletException
- Thrown when a servlet exception occurs
IOException
public String getParameterValue(Object key)
key
- the parameter object name
public boolean isKeyInMap(Object key)
key
- the parameter object name
public boolean isAuthorized(String reportName)
reportName
- Name of the report to check authorization for
public HashMap getParameterMap(HttpServletRequest request, HttpServletResponse response) throws ServletException
request
- servlet requestresponse
- servlet response
ServletException
- Thrown when a servlet exception occurspublic void parameterPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
request
- servlet requestresponse
- servlet response
ServletException
- Thrown when a servlet exception occurs
IOException
public void writeOutput(PreparedStatement stmt, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException
stmt
- an opened but not executed prepared statement (java.sql.PreparedStatement)request
- the HttpServletRequest requestresponse
- the HttpServletResponse response
ServletException
- if an error occurs reading or writing the request or response
IOException
SQLException
|
MDi JLib 1.7.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |