com.jrefinery.chart.demo.jdbc.servlet
Class BaseImageServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--com.jrefinery.chart.demo.jdbc.servlet.BaseImageServlet
All Implemented Interfaces:
Constants, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ImageDataAvailable, ImageDemoPie, ImageSelectSQL

public class BaseImageServlet
extends javax.servlet.http.HttpServlet
implements Constants

A Base image servlet generator. Used to provide common base and methods to servlets which need to generate a chart from sql data sources To extend overwrite method : generateSQL. Will attempt to get configuration constants from the firstly the servlet container configuration and then secondly the servlet's initialization parameters. The servlets initialization parameters taking precedence. Available configuration options are:
DBuser The database user to connect as
DBpwd The password for the database user
DBschemaThe schema to utilise
DBurl The connection URL to the database
DBdriverThe JDBC driver to utilise to connect to the database
The servlet will check to see if a connection is shared amongst the servlets context already. If not it will create a connection and share via the servlet container. Supports the following url options:
NAME TYPE NOTES
type integer the type of chart to generate. eg moving average, linear fit etc under development.
width integer The width of output in pixels. Clipped into the range 10-2000
height integer The height of the output in pixels. Clipped into the range 10-1000
initColor integer Between 0-11, used to indicate the initial shading of the background finalColor integer Between 0-11, used to indicate the final shading of the background
title String The chart title
xaxistitle String The x axis title
yaxistitle String The y axis title
zero String if passed a value of 'true' then the chart will include zero
showLegend String if passed a value of 'false' then the chart will not include legend
output String Selection of the type of output requested. jpeg, gif, svg
CAUTION : THE FOLLOWING ARE UNTESTED / UNDER DEVELOPMENT

  1. SVG support using apache batik.
  2. PDF support
  3. Charting options such as moving average, linear fit.

See Also:
JFreeChart, JFreeChartServletDemo, Serialized Form

Field Summary
protected  java.lang.String chartTitle
          Title of the chart
protected  boolean debug
          Whether or not to enable debug information output
protected  java.lang.String servletName
          The servlets name
protected  int sqlServerType
           
protected  java.lang.String xAxisTitle
          Title of the x axis
protected  java.lang.String yAxisTitle
          Title of the y axis
 
Fields inherited from interface com.jrefinery.chart.demo.jdbc.servlet.Constants
CAUTION_FILE, CONTENT_TYPE, DB_CONNECTION, DB_DRIVER, DB_PASSWORD, DB_SCHEMA, DB_SERVER, DB_URL, DB_USER, DEBUG, FOOTER, FOOTER_FILE, HEADER, HEADER_FILE, IMAGE_URL, MYSQL, ORACLE, ORGANISATION, REPLACE_SCHEMA, RESPONSE_HTML, RESPONSE_JPEG, RESPONSE_PDF, RESPONSE_PNG, RESPONSE_PS, RESPONSE_SVG, SHARED_DB, SHARED_DB_OPENER, SHARED_VOYAGES, SHARED_VOYAGES_TIME
 
Constructor Summary
BaseImageServlet()
           
 
Method Summary
protected  JFreeChart createCategoryChart(int type, java.lang.String sql)
          Create a chart
protected  JFreeChart createChart(int type, java.lang.String sql)
           
protected  JFreeChart createPieChart(int type, java.lang.String sql)
          Create a chart
protected  JFreeChart createXYChart(int type, java.lang.String sql)
          Create a chart
 void destroy()
          Description of the Method
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Basic servlet method, answers requests from the browser.
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Process the HTTP Post request
protected  java.awt.image.BufferedImage draw(JFreeChart chart, int width, int height)
           
protected  java.lang.String generateSQL(javax.servlet.http.HttpServletRequest request)
          Generate the SQL required from the http request
protected  java.awt.Color getColor(int color)
          Gets the color attribute of the passed integer
 void init(javax.servlet.ServletConfig config)
          Override init() to set up data used by invocations of this servlet.
 void modifyChart(JFreeChart chart, javax.servlet.http.HttpServletRequest request)
          Override this method if you would like to modify the generated chart parameters / options
protected  void openConnection()
          Description of the Method
protected  boolean testConnection()
          Description of the Method
protected  void writeErrorPage(javax.servlet.http.HttpServletResponse response, java.lang.String message)
           
 
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, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sqlServerType

protected int sqlServerType

servletName

protected java.lang.String servletName
The servlets name

debug

protected boolean debug
Whether or not to enable debug information output

chartTitle

protected java.lang.String chartTitle
Title of the chart

xAxisTitle

protected java.lang.String xAxisTitle
Title of the x axis

yAxisTitle

protected java.lang.String yAxisTitle
Title of the y axis
Constructor Detail

BaseImageServlet

public BaseImageServlet()
Method Detail

getColor

protected java.awt.Color getColor(int color)
Gets the color attribute of the passed integer
Parameters:
color - The colour index
Returns:
The color value

createChart

protected JFreeChart createChart(int type,
                                 java.lang.String sql)

createXYChart

protected JFreeChart createXYChart(int type,
                                   java.lang.String sql)
Create a chart
Parameters:
type - Type of chart to create. Currently not supported.
sql - SQL to execute. 1st column is x values, following columns are y values
Returns:
The chart of the data

createPieChart

protected JFreeChart createPieChart(int type,
                                    java.lang.String sql)
Create a chart
Parameters:
type - Type of chart to create. Currently not supported.
sql - SQL to execute. 1st column is category, followed by value
Returns:
The chart of the data

createCategoryChart

protected JFreeChart createCategoryChart(int type,
                                         java.lang.String sql)
Create a chart
Parameters:
type - Type of chart to create. Currently not supported.
sql - SQL to execute. 1st column is category, followed by value
Returns:
The chart of the data

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Override init() to set up data used by invocations of this servlet.
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - Description of the Parameter
Throws:
javax.servlet.ServletException - Description of the Exception

generateSQL

protected java.lang.String generateSQL(javax.servlet.http.HttpServletRequest request)
Generate the SQL required from the http request
Parameters:
request - The servlets request parameters
Returns:
The generated sql string

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws javax.servlet.ServletException,
                  java.io.IOException
Basic servlet method, answers requests from the browser.
Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - HTTPServletRequest
response - HTTPServletResponse
Throws:
javax.servlet.ServletException - Description of the Exception
java.io.IOException - Description of the Exception

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws javax.servlet.ServletException,
                   java.io.IOException
Process the HTTP Post request
Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
request - Description of the Parameter
response - Description of the Parameter
Throws:
javax.servlet.ServletException - Description of the Exception
java.io.IOException - Description of the Exception

draw

protected java.awt.image.BufferedImage draw(JFreeChart chart,
                                            int width,
                                            int height)
Parameters:
chart - Description of the Parameter
width - Description of the Parameter
height - Description of the Parameter
Returns:
Description of the Return Value

modifyChart

public void modifyChart(JFreeChart chart,
                        javax.servlet.http.HttpServletRequest request)
Override this method if you would like to modify the generated chart parameters / options
Parameters:
chart - The generated chart.
request - The HTTP request.

destroy

public void destroy()
Description of the Method
Overrides:
destroy in class javax.servlet.GenericServlet

openConnection

protected void openConnection()
Description of the Method

testConnection

protected boolean testConnection()
Description of the Method
Returns:
Description of the Return Value

writeErrorPage

protected void writeErrorPage(javax.servlet.http.HttpServletResponse response,
                              java.lang.String message)