ca.cbc.sportwire.servlet
Class VelocityEngineServlet
java.lang.Object
|
+--javax.servlet.GenericServlet
|
+--javax.servlet.http.HttpServlet
|
+--org.apache.velocity.servlet.VelocityServlet
|
+--ca.cbc.sportwire.servlet.VelocityEngineServlet
- All Implemented Interfaces:
- java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
- Direct Known Subclasses:
- SportPageServlet
- public abstract class VelocityEngineServlet
- extends org.apache.velocity.servlet.VelocityServlet
VelocityEngineServlet: Equivalent to the VelocityServlet,
but using the VelocityEngine instead of the singleton.
Base class which simplifies the use of VelocityEngine with Servlets.
Extend this class, implement the handleRequest()
method,
and add your data to the context. Then call
getTemplate("myTemplate.wm")
.
This class puts some things into the context object that you should
be aware of:
"req" - The HttpServletRequest object
"res" - The HttpServletResponse object
The Apache Software License, Version 1.1
Copyright (c) 2000-2001 The Apache Software Foundation. All rights
reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the conditions specified
in the Jakarta-Apache Velocity package.
$Log: VelocityEngineServlet.java,v $
Revision 1.3 2002/01/22 22:34:46 garym
Fixed news slug case bug
Revision 1.2 2002/01/14 21:51:46 garym
bug fixes in topics and config files migration to Extended Properties
Revision 1.1 2001/12/18 16:49:43 garym
initial edition
- Version:
- $Id: VelocityEngineServlet.java,v 1.3 2002/01/22 22:34:46 garym Exp $
- Author:
- Gary Lawrence Murphy
- See Also:
- Serialized Form
Field Summary |
(package private) static org.apache.log4j.Category |
cat
|
private static java.lang.String |
defaultContentType
The default content type. |
private static java.lang.String |
encoding
The encoding to use when generating outputing. |
protected static java.lang.String |
INIT_PROPS_KEY
This is the string that is looked for when getInitParameter is
called. |
private javax.servlet.ServletConfig |
servletConfig
|
private org.apache.velocity.app.VelocityEngine |
velocity
|
private static org.apache.velocity.util.SimplePool |
writerPool
|
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 |
Method Summary |
protected void |
doRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handles all requests |
javax.servlet.ServletConfig |
getServletConfig()
emulate the HttpServlet.getServletConfig -- we can't call the
parent class init, so we have to emulate the grandparent. |
org.apache.velocity.Template |
getTemplate(java.lang.String name)
Retrieves the requested template. |
org.apache.velocity.Template |
getTemplate(java.lang.String name,
java.lang.String encoding)
Retrieves the requested template with the specified
character encoding. |
protected org.apache.velocity.app.VelocityEngine |
getVelocity()
Get the current velocityEngine. |
void |
init(javax.servlet.ServletConfig config)
Performs initialization of this servlet. |
protected void |
mergeTemplate(org.apache.velocity.Template template,
org.apache.velocity.context.Context context,
javax.servlet.http.HttpServletResponse response)
merges the template with the context. |
protected void |
setContentType(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
|
protected void |
setVelocity(org.apache.velocity.app.VelocityEngine v)
Set the velocityEngine. |
Methods inherited from class org.apache.velocity.servlet.VelocityServlet |
, createContext, doGet, doPost, error, handleRequest, handleRequest, loadConfiguration, 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, getServletInfo, 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
velocity
private org.apache.velocity.app.VelocityEngine velocity
INIT_PROPS_KEY
protected static final java.lang.String INIT_PROPS_KEY
- This is the string that is looked for when getInitParameter is
called. set to a unique value from the parent class.
encoding
private static java.lang.String encoding
- The encoding to use when generating outputing.
defaultContentType
private static java.lang.String defaultContentType
- The default content type.
servletConfig
private javax.servlet.ServletConfig servletConfig
writerPool
private static org.apache.velocity.util.SimplePool writerPool
VelocityEngineServlet
public VelocityEngineServlet()
getVelocity
protected org.apache.velocity.app.VelocityEngine getVelocity()
- Get the current velocityEngine.
- Returns:
- VelocityEngine
setVelocity
protected void setVelocity(org.apache.velocity.app.VelocityEngine v)
- Set the velocityEngine.
- Parameters:
v
- Value to assign to velocity.
setContentType
protected void setContentType(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
- Overrides:
setContentType
in class org.apache.velocity.servlet.VelocityServlet
getServletConfig
public javax.servlet.ServletConfig getServletConfig()
- emulate the HttpServlet.getServletConfig -- we can't call the
parent class init, so we have to emulate the grandparent.
- Overrides:
getServletConfig
in class javax.servlet.GenericServlet
init
public void init(javax.servlet.ServletConfig config)
throws javax.servlet.ServletException
- Performs initialization of this servlet. Called by the servlet
container on loading. This method does not call the parent
class method because it loads a VelocityEngine
- Overrides:
init
in class org.apache.velocity.servlet.VelocityServlet
- Parameters:
config
- The servlet configuration to apply.- Throws:
javax.servlet.ServletException
-
doRequest
protected void doRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
- Handles all requests
- Overrides:
doRequest
in class org.apache.velocity.servlet.VelocityServlet
- Parameters:
request
- HttpServletRequest containing client requestresponse
- HttpServletResponse for the response- Throws:
javax.servlet.ServletException
- if an error occursjava.io.IOException
- if an error occurs
getTemplate
public org.apache.velocity.Template getTemplate(java.lang.String name)
throws org.apache.velocity.exception.ResourceNotFoundException,
org.apache.velocity.exception.ParseErrorException,
java.lang.Exception
- Retrieves the requested template. These methods use the
current VelocityEngine to generate the Template object.
- Overrides:
getTemplate
in class org.apache.velocity.servlet.VelocityServlet
- Parameters:
name
- The template file to retrieve relative to the
template root.- Returns:
- The requested template.
- Throws:
org.apache.velocity.exception.ResourceNotFoundException
- if template not found
from any available source.org.apache.velocity.exception.ParseErrorException
- if template cannot be parsed due
to syntax (or other) error.java.lang.Exception
- if an error occurs in template initialization
getTemplate
public org.apache.velocity.Template getTemplate(java.lang.String name,
java.lang.String encoding)
throws org.apache.velocity.exception.ResourceNotFoundException,
org.apache.velocity.exception.ParseErrorException,
java.lang.Exception
- Retrieves the requested template with the specified
character encoding.
- Overrides:
getTemplate
in class org.apache.velocity.servlet.VelocityServlet
- Parameters:
name
- The file name of the template to retrieve relative to the
template root.encoding
- the character encoding of the template- Returns:
- The requested template.
- Throws:
org.apache.velocity.exception.ResourceNotFoundException
- if template not found
from any available source.org.apache.velocity.exception.ParseErrorException
- if template cannot be parsed due
to syntax (or other) error.java.lang.Exception
- if an error occurs in template initialization- Since:
- Velocity v1.1
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
- merges the template with the context. This method had to be
replaced because the parent method uses a private encoding
attribute (does not use access methods) and we cannot call the
parent init for other reasons.
- Overrides:
mergeTemplate
in class org.apache.velocity.servlet.VelocityServlet
- Parameters:
template
- template object returned by the handleRequest() methodcontext
- context created by the createContext() methodresponse
- servlet reponse (use this to get the output stream or Writer