ca.cbc.sportwire.servlet
Class SportPageServlet
java.lang.Object
|
+--javax.servlet.GenericServlet
|
+--javax.servlet.http.HttpServlet
|
+--org.apache.velocity.servlet.VelocityServlet
|
+--ca.cbc.sportwire.servlet.VelocityEngineServlet
|
+--ca.cbc.sportwire.servlet.SportPageServlet
- All Implemented Interfaces:
- GlobalCacheProperties, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig, SportPageProperties
- public class SportPageServlet
- extends VelocityEngineServlet
- implements GlobalCacheProperties, SportPageProperties
SportPageServlet: The primary Servlet for the Sports
pages; the servlet is installed as the default page for the webapp,
responding to the url-pattern
"/" (see
src/sportpage.xml).
The servlet extends the VelocityServlet, which leaves Velocity
to manage all of the problems of making the connection, closing out
the buffers and handling the doXXX methods. This servlet takes the
Request URI as a cue to search for a corresponding class, beginning
with the full URI path and working its way back dropping the last
term until it arrives at PageHandler class -- this search may not
be totally optimal as /baseball/update/minn
may want
to share Update.class
instead of requiring a subclass
baseball.Update
; the search behaviour may evolve over
time
Once a PageHandler is found (or we revert to the Default) that
class is asked to set up the context; this is where the specific
URI dictates the starting conditions for each page. For example
baseball.Update
would take the tail of the URI as some
sort of game key value and would fetch the updates for that game,
while also setting the $page
variable to the template
for baseball game updates. Since PageHandlers are invoked before
any template rendering, even the layut template may be changed by
these handlers.
This code is part of the open source SportWire News Aggregation
and Display System - © 2001 The Canadian Broadcasting
Corporation
Created: Thu Nov 29 16:47:42 2001
$Log: SportPageServlet.java,v $
Revision 1.27 2002/01/29 19:33:44 garym
fixed concurrency bug with global config
Revision 1.26 2002/01/28 21:50:04 garym
Improved critical error recovery; headlines now use backup script feed
Revision 1.25 2002/01/27 06:39:57 garym
Added XSL transform and XML output to JDOMFile
Revision 1.24 2002/01/26 06:46:27 garym
authorization bug in lineups
Revision 1.23 2002/01/24 19:50:20 garym
Major restructuring of beans and pagehandlers
Revision 1.22 2002/01/22 22:34:46 garym
Fixed news slug case bug
Revision 1.21 2002/01/22 06:40:45 garym
Bug fix to emergency error; not yet complete.
Revision 1.20 2002/01/21 20:07:14 garym
NewsPage did not include $news; fixed error reporting to be a redirect to 404
Revision 1.19 2002/01/16 23:09:24 garym
Implemented the JDBC pool support and sql property beans
Revision 1.18 2002/01/16 00:56:26 garym
current site on cbc.ca/olympics; checkpoint release
Revision 1.17 2002/01/15 08:28:50 garym
implemented MRU cache for the JDOMFile objects
Revision 1.16 2002/01/14 21:51:46 garym
bug fixes in topics and config files migration to Extended Properties
Revision 1.15 2002/01/09 04:28:59 garym
Added test unit stubs and new News support
Revision 1.14 2002/01/04 06:12:46 garym
default page handling of XML files obsolesces DOMPageHandler
Revision 1.13 2001/12/23 17:55:21 garym
Allow for multiple SportPage apps on one JVM
Revision 1.12 2001/12/23 04:54:16 garym
Added TemplateLineup support and Velocity logfile setting
Revision 1.11 2001/12/18 16:48:39 garym
Adapted to VelocityEngine
Revision 1.10 2001/12/16 22:01:56 garym
fixes to default page handling
Revision 1.9 2001/12/15 02:15:58 garym
initial release to CBC staging server
Revision 1.8 2001/12/14 21:12:29 garym
include file debugging
Revision 1.7 2001/12/13 06:48:40 garym
Implemented a path object that can break up the elements of the path
Revision 1.6 2001/12/08 02:53:15 garym
Defaults are overlaid with the topic defaults
Revision 1.5 2001/12/06 16:29:51 garym
Implemented DOM object support and the Bio page handler
Revision 1.4 2001/12/06 07:26:39 garym
Genertes simple layouts; page parts in Properties
Revision 1.3 2001/12/06 04:57:59 garym
DefaultPage now take template parts from properties
Revision 1.2 2001/12/01 05:08:21 garym
Updated documentation
Revision 1.1 2001/12/01 04:02:40 garym
Initial SportPageServlet files with sample templates
- Version:
- $Id: SportPageServlet.java,v 1.27 2002/01/29 19:33:44 garym Exp $
- Author:
- Gary Lawrence Murphy
- See Also:
- Serialized Form
Field Summary |
private org.apache.commons.collections.ExtendedProperties |
appConfig
|
(package private) static org.apache.log4j.Category |
cat
|
private boolean |
loginit
startLog loads filters and appenders from the
property file specified by sportpage.log4j.conf. |
private MRUCacheMap |
mruCache
|
private TTLCacheMap |
ttlCache
|
Fields inherited from class org.apache.velocity.servlet.VelocityServlet |
CONTENT_TYPE, DEFAULT_CONTENT_TYPE, DEFAULT_OUTPUT_ENCODING, REQUEST, RESPONSE |
Fields inherited from class javax.servlet.http.HttpServlet |
HEADER_IFMODSINCE, HEADER_LASTMOD, LSTRING_FILE, lStrings, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_POST, METHOD_PUT, METHOD_TRACE |
Fields inherited from class javax.servlet.GenericServlet |
config |
Fields inherited from interface ca.cbc.sportwire.servlet.data.SportPageProperties |
BEAN_SUFFIX, BEANFACTORY_VAR, CONTEXT_VAR, DATE_VAR, DEFAULT_EXTS, DEFAULT_INDEXES, DEFAULT_PAGE_SUFFIX, DEFAULT_SAX_DRIVER_CLASS, DEFAULT_TIMEZONE, DEFAULT_TOPIC, DOM_VAR, ERROR_TEMPLATE_VAR, EXCEPTION_VAR, EXTENSIONS_VAR, FALSE, GLOBAL_VAR, HOME_PROPERTY, INCLUDE_EXTS_PROPERTY, INCLUDE_VAR, INDEX_INDICATOR_VAR, INDEX_TEMPLATE_VAR, LAYOUT_TEMPLATE_VAR, MACRO_LIB_PROPERTY, MISSING_TEMPLATE_VAR, OUTPUT_VAR, PAGE_EXPIRE, PAGE_TEMPLATE_VAR, PANIC_404_PAGE, PANIC_404_PROPERTY, PANIC_500_PAGE, PANIC_500_PROPERTY, PARAM_PARSER_VAR, PATH_VAR, REQUEST_VAR, RESPONSE_VAR, SAX_CLASS_PROPERTY, SERVLET_DEBUG, SERVLET_LOGCONF_PROPERTY, SQL_SUFFIX, TEMPLATE_PATHS_PROPERTY, TIMEZONE_PROPERTY, TRUE, URI_VAR, VELOCITY_LOGFILE_DEFAULT, VELOCITY_LOGFILE_PROPERTY, XML_EXTS, XML_EXTS_PROPERTY, XML_PATHS_PROPERTY, XML_SUFFIX, XSL_EXTS, XSL_EXTS_PROPERTY, XSL_PATHS_PROPERTY |
Method Summary |
protected void |
error(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Exception cause)
error : Currently minimcally implemented to avoid
ugly Velocity stack-trace screens; should be expanded later to
provide a more graceful reaction to different classes of
critical template errors. |
org.apache.commons.collections.ExtendedProperties |
getAppConfig()
appConfig is the application-wide configuration; servletContext
is not guaranteed to be unique to each servlet (although it can
be) so the global properties loaded for the servlet are stored
here; anyone got a better place? |
MRUCacheMap |
getMruCache()
Get the value of mruCache. |
java.lang.String |
getServletInfo()
getServletInfo : Returns the version ID of this
file |
protected java.lang.StringBuffer |
getTemplatePath()
|
TTLCacheMap |
getTTLCache()
Get the value of ttlCache. |
org.apache.velocity.Template |
handleRequest(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
org.apache.velocity.context.Context context)
handleRequest : Velocity main request method. |
protected boolean |
handleStaticRequest(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
org.apache.velocity.context.Context context)
handleStaticRequest : For the time being, we have a
problem where static files referenced in the templates cannot
be handled by Apache because the root /sports in
the URL causes Apache to hand it over (JkMount) to tomcat, and
tomcat hands it back to this servlet (because of the '/'
url-pattern. |
protected java.util.Properties |
loadConfiguration(javax.servlet.ServletConfig config)
loadConfiguration : fetch the properties in the
file specified by sportpage.servlet.conf (in
WEB-INF/web.xml) and add them to the ServletContext, and load
up the Velocity configuration (which can be specified
seperately as a "properties" web.xml init-param value. |
protected void |
mergeTemplate(org.apache.velocity.Template template,
org.apache.velocity.context.Context context,
javax.servlet.http.HttpServletResponse response)
mergeTemplate : Overriding this method allows us to
trap errors in the execution of the templates and shunt the
page off to a standard site error page instead of returning the
default stacktrace error page. |
protected void |
setAppConfig(org.apache.commons.collections.ExtendedProperties v)
Set the value of appConfig. |
protected TTLCacheMap |
setCache(java.lang.String cacheVar,
TTLCacheMap cache)
|
protected void |
setMruCache(MRUCacheMap v)
Set the value of mruCache. |
protected void |
setPathProperties(java.lang.String uri,
org.apache.velocity.context.Context context)
setPathProperties : stuffs the context with
variables based on the URI: requestURI is
the full URI of this webapp path is the path
after this webapp as a
ca.cbc.sportpage.servlet.data.PathBean object. |
protected void |
setTTLCache(TTLCacheMap v)
Set the value of ttlCache. |
protected void |
startLog(java.lang.String home)
|
Methods inherited from class org.apache.velocity.servlet.VelocityServlet |
, createContext, doGet, doPost, handleRequest, requestCleanup |
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPut, doTrace, getAllDeclaredMethods, getLastModified, maybeSetLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletContext, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
cat
static org.apache.log4j.Category cat
appConfig
private org.apache.commons.collections.ExtendedProperties appConfig
mruCache
private MRUCacheMap mruCache
ttlCache
private TTLCacheMap ttlCache
loginit
private boolean loginit
startLog
loads filters and appenders from the
property file specified by sportpage.log4j.conf. If
sportpage.debug
is false, messages below
WARN priority will be suppressed. This can be undone in a
production release through the
log4j.disableOverride
property.
SportPageServlet
public SportPageServlet()
getAppConfig
public org.apache.commons.collections.ExtendedProperties getAppConfig()
- appConfig is the application-wide configuration; servletContext
is not guaranteed to be unique to each servlet (although it can
be) so the global properties loaded for the servlet are stored
here; anyone got a better place?
- Returns:
- SportwireConfig value of appConfig.
setAppConfig
protected void setAppConfig(org.apache.commons.collections.ExtendedProperties v)
- Set the value of appConfig. This is only called by the servlet
init so the result is common to all invocations of this
servlet.
- Parameters:
v
- ExtendedProperties object to assign to appConfig.
getMruCache
public MRUCacheMap getMruCache()
- Get the value of mruCache.
- Returns:
- MRUCacheMap value of mruCache.
setMruCache
protected void setMruCache(MRUCacheMap v)
- Set the value of mruCache.
- Parameters:
v
- Value to assign to mruCache.
getTTLCache
public TTLCacheMap getTTLCache()
- Get the value of ttlCache.
- Returns:
- TTLCacheMap value of ttlCache.
setTTLCache
protected void setTTLCache(TTLCacheMap v)
- Set the value of ttlCache.
- Parameters:
v
- Value to assign to ttlCache.
setCache
protected TTLCacheMap setCache(java.lang.String cacheVar,
TTLCacheMap cache)
getTemplatePath
protected java.lang.StringBuffer getTemplatePath()
loadConfiguration
protected java.util.Properties loadConfiguration(javax.servlet.ServletConfig config)
throws java.io.IOException,
java.io.FileNotFoundException
loadConfiguration
: fetch the properties in the
file specified by sportpage.servlet.conf
(in
WEB-INF/web.xml) and add them to the ServletContext, and load
up the Velocity configuration (which can be specified
seperately as a "properties" web.xml init-param value. This
method is only called once, when the Servlet is created.
The SportPageServlet pre-seeds the Velocity engine with the
following properties taken from the SportPage configuration
file specified as spotpage.servlet.conf
in the
web.xml:
templates.home
- if missing, this defaults to the webapp's directory;
otherwise this is added to Velocity.RESOURCE_LOADER_PATH
home
- gets set to the base webapp directory
- Overrides:
loadConfiguration
in class org.apache.velocity.servlet.VelocityServlet
- Parameters:
config
- the current ServletConfig
value- Returns:
- a
Properties
value used to set Velocity - Throws:
java.io.IOException
- if an error occurs reading the filejava.io.FileNotFoundException
- if no config exists
mergeTemplate
protected void mergeTemplate(org.apache.velocity.Template template,
org.apache.velocity.context.Context context,
javax.servlet.http.HttpServletResponse response)
throws org.apache.velocity.exception.ResourceNotFoundException,
org.apache.velocity.exception.ParseErrorException,
org.apache.velocity.exception.MethodInvocationException,
java.io.IOException,
java.io.UnsupportedEncodingException,
java.lang.Exception
mergeTemplate
: Overriding this method allows us to
trap errors in the execution of the templates and shunt the
page off to a standard site error page instead of returning the
default stacktrace error page.
- Overrides:
mergeTemplate
in class VelocityEngineServlet
- Parameters:
template
- a Velocity Template
valuecontext
- a Velocity Context
valueresponse
- a HttpServletResponse
value- Throws:
org.apache.velocity.exception.ResourceNotFoundException
- if no template is foundorg.apache.velocity.exception.ParseErrorException
- if the template has syntax errorsorg.apache.velocity.exception.MethodInvocationException
- if the template makes an illegel call to some embedded objectjava.io.IOException
- if we cannot write to the output port.java.io.UnsupportedEncodingException
- if the template has invalid charsjava.lang.Exception
- if an unknown error occurs
error
protected void error(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Exception cause)
throws javax.servlet.ServletException,
java.io.IOException
error
: Currently minimcally implemented to avoid
ugly Velocity stack-trace screens; should be expanded later to
provide a more graceful reaction to different classes of
critical template errors. Current method just uses a meta-tag
to redirect to a standard 404 error page configured by
panic.404=error.html
config property, and prints
the stack trace in a comment. Keep in mind that this must
redirect outside of the webapp URI space to prevent
recursive error reporting.
- Overrides:
error
in class org.apache.velocity.servlet.VelocityServlet
- Parameters:
request
- a HttpServletRequest
valueresponse
- a HttpServletResponse
valuecause
- an Exception
value- Throws:
javax.servlet.ServletException
- if an error occursjava.io.IOException
- if an error occurs
setPathProperties
protected void setPathProperties(java.lang.String uri,
org.apache.velocity.context.Context context)
setPathProperties
: stuffs the context with
variables based on the URI: requestURI
is
the full URI of this webapp path
is the path
after this webapp as a
ca.cbc.sportpage.servlet.data.PathBean
object. A
PathBean is essentially an ArrayList with some access methods
for Velocity templates to get the current depth or specific
path elements, and methods to resolve default extensions for
regular include files.
- Parameters:
uri
- a String
RequestURIcontext
- a Velocity Context
- See Also:
ca.cbc.sportpage.servlet.data.PathBean
handleStaticRequest
protected boolean handleStaticRequest(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
org.apache.velocity.context.Context context)
handleStaticRequest
: For the time being, we have a
problem where static files referenced in the templates cannot
be handled by Apache because the root /sports
in
the URL causes Apache to hand it over (JkMount) to tomcat, and
tomcat hands it back to this servlet (because of the '/'
url-pattern. A dilemma. Many files we would naturally import
have relative paths to icons and other images. This method is
a temp hack fix: if we suspect the URI intends to receive a
static item, we load it and blast it back at them. At the
present time, we only recognize GIF and JPG files.
- Parameters:
req
- a HttpServletRequest
valueres
- a HttpServletResponse
valuecontext
- a Velocity Context
- Returns:
- a
boolean
true if we handled it
handleRequest
public org.apache.velocity.Template handleRequest(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
org.apache.velocity.context.Context context)
throws java.io.IOException
handleRequest
: Velocity main request method. This
method returns the template to process, or returns null if the
request was handled by some other means (such as dumping a file
back).
- Overrides:
handleRequest
in class org.apache.velocity.servlet.VelocityServlet
- Parameters:
req
- a HttpServletRequest
res
- a HttpServletResponse
context
- a Velocity Context
- Returns:
- a Velocity
Template
- Throws:
java.io.IOException
- if an error occurs
getServletInfo
public java.lang.String getServletInfo()
getServletInfo
: Returns the version ID of this
file
- Overrides:
getServletInfo
in class javax.servlet.GenericServlet
- Returns:
- a
String
value
startLog
protected void startLog(java.lang.String home)