public class VelocityViewFilter extends Object implements javax.servlet.Filter
A filter to ensure VelocityTools Toolbox
es are
available in the request/session/application scopes. This
can simplify the process of integration with other frameworks.
VelocityViewFilter supports the following configuration parameters in web.xml:
false
. If set to true
, then
the default toolbox configuration will be added prior to your (if any)
custom configuration.false
. If set to true
, then
then the final toolbox configuration (the combination of any custom
one(s) provided by yourself and/or the default configuration(s))
will have all invalid tools, properties, and/or data removed prior to
configuring the ToolboxFactory for this servlet by a
ConfigurationCleaner
true
. If set to false
, then
the VelocityView
used by this filter will not be shared
with other VelocityViewFilters, VelocityViewServlet
s or
org.apache.velocity.tools.view.jsp.VelocityViewTag's in the
application.ViewToolContext
for each request, and then
place it into the request attributes under the key you set. This
is primarily for those who use this filter WITHOUT sharing a config
(i.e. non-shared VelocityView), letting them retrieve the context
as the request attribute.Modifier and Type | Field and Description |
---|---|
static String |
CONTEXT_KEY |
Constructor and Description |
---|
VelocityViewFilter() |
Modifier and Type | Method and Description |
---|---|
protected org.apache.velocity.context.Context |
createContext(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
Simply prepares the request (and/or session) toolbox(es)
for other filters, servlets or whatnot to use.
|
protected String |
findInitParameter(String key)
Looks up an init parameter with the specified key in either the
FilterConfig or, failing that, in the ServletContext.
|
protected String |
getContextKey() |
protected javax.servlet.FilterConfig |
getFilterConfig() |
protected VelocityView |
getVelocityView() |
void |
init(javax.servlet.FilterConfig config)
Initializes VelocityView used to process requests.
|
public static final String CONTEXT_KEY
public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException
Initializes VelocityView used to process requests. Called by the servlet container on loading.
init
in interface javax.servlet.Filter
config
- filter configuationjavax.servlet.ServletException
protected javax.servlet.FilterConfig getFilterConfig()
protected VelocityView getVelocityView()
protected String getContextKey()
protected String findInitParameter(String key)
key
- init parameter keypublic void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException
ViewToolContext
and put
it in the request attributes under that key.doFilter
in interface javax.servlet.Filter
IOException
javax.servlet.ServletException
protected org.apache.velocity.context.Context createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
public void destroy()
destroy
in interface javax.servlet.Filter
Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.