public class VelocityView extends ViewToolManager
The class provides the following features:
VelocityView supports the following configuration parameters in web.xml:
Modifier and Type | Field and Description |
---|---|
static String |
CLEAN_CONFIGURATION_KEY
Controls removal of tools or data with invalid configurations
before initialization is finished.
|
static String |
CONTENT_TYPE_KEY
The HTTP content type context key.
|
static String |
DEFAULT_CONTENT_TYPE
The default content type for the response
|
static String |
DEFAULT_OUTPUT_ENCODING
Default encoding for the output stream
|
static String |
DEFAULT_PROPERTIES_PATH
Default Runtime properties.
|
static String |
LOAD_DEFAULTS_KEY
Controls loading of available default tool configurations
provided by VelocityTools.
|
static String |
OUTPUT_ENCODING_KEY
The HTTP output encoding.
|
static String |
PROPERTIES_KEY
This is the string that is looked for when getInitParameter is
called ("org.apache.velocity.properties").
|
static String |
SERVLET_CONTEXT_KEY
Key used to access the ServletContext in
the Velocity application attributes.
|
static String |
TOOLS_KEY
Key used to access the toolbox configuration file path from the
Servlet or webapp init parameters ("org.apache.velocity.tools")
or to access a live
FactoryConfiguration previously
placed in the ServletContext attributes. |
static String |
USER_OVERWRITE_KEY
Controls whether or not templates can overwrite tool and servlet API
variables in the local context.
|
static String |
USER_PROPERTIES_PATH
Default velocity properties file path.
|
static String |
USER_TOOLS_PATH
Default toolbox configuration file path.
|
CREATE_SESSION_PROPERTY, DEFAULT_TOOLBOX_KEY, PUBLISH_TOOLBOXES_PROPERTY, servletContext
factory, log, velocity
Constructor and Description |
---|
VelocityView(javax.servlet.FilterConfig config) |
VelocityView(JeeConfig config) |
VelocityView(javax.servlet.ServletConfig config) |
VelocityView(javax.servlet.ServletContext context) |
Modifier and Type | Method and Description |
---|---|
protected void |
configure(JeeConfig config,
ToolboxFactory factory)
Here's the configuration lookup/loading order:
If loadDefaults is true,
ConfigurationUtils.getDefaultTools()
Config file optionally specified by servletContext org.apache.velocity.tools init-param
Config file optionally at /WEB-INF/tools.xml (conventional location)
Config file optionally specified by servlet org.apache.velocity.tools init-param
Remember that as these configurations are added on top of each other,
the newer values will always override the older ones. |
protected void |
configure(JeeConfig config,
org.apache.velocity.app.VelocityEngine velocity) |
ViewToolContext |
createContext(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Creates and returns an initialized Velocity context.
|
protected FactoryConfiguration |
getConfiguration(String path) |
protected FactoryConfiguration |
getConfiguration(String path,
boolean required) |
String |
getDefaultContentType() |
protected FactoryConfiguration |
getDefaultToolsConfiguration() |
protected InputStream |
getInputStream(String path,
boolean required) |
protected Properties |
getProperties(String path) |
protected Properties |
getProperties(String path,
boolean required) |
protected String |
getProperty(String key,
String alternate)
Simplifies process of getting a property from VelocityEngine,
because the VelocityEngine interface sucks compared to the singleton's.
|
org.apache.velocity.Template |
getTemplate(javax.servlet.http.HttpServletRequest request)
Gets the requested template.
|
org.apache.velocity.Template |
getTemplate(String name)
Retrieves the requested template.
|
org.apache.velocity.Template |
getTemplate(String name,
String encoding)
Retrieves the requested template with the specified character encoding.
|
protected void |
init(JeeConfig config)
Initializes ToolboxFactory, VelocityEngine, and sets default
encoding for processing requests.
|
protected void |
init(JeeConfig config,
org.apache.velocity.app.VelocityEngine velocity)
Initializes the Velocity runtime, first calling
loadConfiguration(JeeConfig) to get a
java.util.Properties
of configuration information
and then calling velocityEngine.init().
|
void |
merge(org.apache.velocity.Template template,
org.apache.velocity.context.Context context,
Writer writer)
Merges the template with the context.
|
protected void |
performMerge(org.apache.velocity.Template template,
org.apache.velocity.context.Context context,
Writer writer)
This is here so developers may override it and gain access to the
Writer which the template will be merged into.
|
org.apache.velocity.context.Context |
render(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
org.apache.velocity.context.Context |
render(javax.servlet.http.HttpServletRequest request,
Writer out) |
void |
setDefaultContentType(String type)
Sets the configured default Content-Type.
|
protected void |
setEncoding(JeeConfig config) |
void |
setVelocityEngine(org.apache.velocity.app.VelocityEngine engine)
Overrides super class to ensure engine is not set to null.
|
addToolboxes, autoConfigure, configure, createContext, findConfig, getCreateSession, getPublishToolboxes, getSessionToolbox, getSessionToolbox, getToolboxKey, hasSessionTools, prepareContext, publishApplicationTools, publishToolboxes, publishToolboxes, setCreateSession, setPublishToolboxes, setToolboxKey, unpublishApplicationTools, updateGlobalProperties
configure, createContext, createToolbox, getApplicationToolbox, getLog, getRequestToolbox, getToolboxFactory, getUserCanOverwriteTools, getVelocityEngine, hasApplicationTools, hasRequestTools, hasTools, initLog, prepareContext, setToolboxFactory, setUserCanOverwriteTools
public static final String CONTENT_TYPE_KEY
public static final String OUTPUT_ENCODING_KEY
public static final String SERVLET_CONTEXT_KEY
public static final String DEFAULT_CONTENT_TYPE
public static final String DEFAULT_OUTPUT_ENCODING
public static final String TOOLS_KEY
FactoryConfiguration
previously
placed in the ServletContext attributes.public static final String USER_TOOLS_PATH
public static final String DEFAULT_PROPERTIES_PATH
public static final String PROPERTIES_KEY
public static final String USER_PROPERTIES_PATH
public static final String LOAD_DEFAULTS_KEY
public static final String CLEAN_CONFIGURATION_KEY
true
to turn this feature on.public static final String USER_OVERWRITE_KEY
false
to prevent overwriting of any tool variables.public VelocityView(javax.servlet.ServletConfig config)
public VelocityView(javax.servlet.FilterConfig config)
public VelocityView(javax.servlet.ServletContext context)
public VelocityView(JeeConfig config)
public void setVelocityEngine(org.apache.velocity.app.VelocityEngine engine)
setVelocityEngine
in class ToolManager
engine
- VelocityEngine instancepublic String getDefaultContentType()
public void setDefaultContentType(String type)
type
- default content typeprotected String getProperty(String key, String alternate)
init(JeeConfig,VelocityEngine)
has already been called.key
- property keyalternate
- default valueprotected void init(JeeConfig config)
Initializes ToolboxFactory, VelocityEngine, and sets default encoding for processing requests.
NOTE: If no charset is specified in the default.contentType property (in your velocity.properties) and you have specified an output.encoding property, then that will be used as the charset for the default content-type of pages served by this servlet.
config
- servlet configuationprotected void init(JeeConfig config, org.apache.velocity.app.VelocityEngine velocity)
config
- servlet configuration parametersvelocity
- VelocityEngine instanceprotected void configure(JeeConfig config, org.apache.velocity.app.VelocityEngine velocity)
protected void configure(JeeConfig config, ToolboxFactory factory)
ConfigurationUtils.getDefaultTools()
org.apache.velocity.tools
init-param/WEB-INF/tools.xml
(conventional location)org.apache.velocity.tools
init-paramorg.apache.velocity.tools.cleanConfiguration
init-param to true in
either your servlet or servletContext init-params.config
- configuration values containerfactory
- toolbox factory instanceprotected FactoryConfiguration getDefaultToolsConfiguration()
protected InputStream getInputStream(String path, boolean required)
protected Properties getProperties(String path)
protected Properties getProperties(String path, boolean required)
protected FactoryConfiguration getConfiguration(String path)
protected FactoryConfiguration getConfiguration(String path, boolean required)
protected void setEncoding(JeeConfig config)
public org.apache.velocity.context.Context render(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
request
- HttpServletRequest object containing client requestresponse
- HttpServletResponse object for the responseContext
prepared and used to perform the rendering
to allow proper cleanup afterwardIOException
- if thrown by underling codepublic org.apache.velocity.context.Context render(javax.servlet.http.HttpServletRequest request, Writer out) throws IOException
IOException
public ViewToolContext createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Creates and returns an initialized Velocity context.
A new context of classViewToolContext
is created and
initialized.createContext
in class ViewToolManager
request
- servlet request from clientresponse
- servlet reponse to clientpublic org.apache.velocity.Template getTemplate(javax.servlet.http.HttpServletRequest request)
Gets the requested template.
request
- client requestpublic org.apache.velocity.Template getTemplate(String name)
name
- The file name of the template to retrieve relative to the
template root.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.public org.apache.velocity.Template getTemplate(String name, String encoding)
name
- The file name of the template to retrieve relative to the
template root.encoding
- the character encoding of the templateorg.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.public void merge(org.apache.velocity.Template template, org.apache.velocity.context.Context context, Writer writer) throws IOException
template
- template being renderedcontext
- Context created by the createContext(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
writer
- into which the content is renderedIOException
- if thrown by underling codeprotected void performMerge(org.apache.velocity.Template template, org.apache.velocity.context.Context context, Writer writer) throws IOException
template
- template object returned by the handleRequest() methodcontext
- Context created by the createContext(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
writer
- a VelocityWriter that the template is merged intoIOException
- if thrown by underling codeCopyright © 2002–2021 The Apache Software Foundation. All rights reserved.