类 VelocityView
java.lang.Object
org.apache.velocity.tools.ToolManager
org.apache.velocity.tools.view.ViewToolManager
org.apache.velocity.tools.view.VelocityView
The class provides the following features:
- renders Velocity templates
- provides support for an auto-loaded, configurable toolbox
- provides transparent access to the servlet request attributes, servlet session attributes and servlet context attributes by auto-searching them
- logs to the logging facility of the servlet API
VelocityView supports the following configuration parameters in web.xml:
- org.apache.velocity.tools
- Path and name of the toolbox configuration file. The path must be relative to the web application root directory. If this parameter is not found, the servlet will check for a toolbox file at '/WEB-INF/tools.xml'.
- org.apache.velocity.properties
- Path and name of the Velocity configuration file. The path must be relative to the web application root directory. If this parameter is not present, Velocity will check for a properties file at '/WEB-INF/velocity.properties'. If no file is found there, then Velocity is initialized with the settings in the classpath at 'org.apache.velocity.tools.view.velocity.properties'.
- 版本:
- $Id: VelocityView.java 511959 2007-02-26 19:24:39Z nbubna $
- 作者:
- Dave Bryson, Jon S. Stevens, Gabe Sidler, Geir Magnusson Jr., Kent Johnson, Daniel Rall, Nathan Bubna
-
字段概要
字段修饰符和类型字段说明static final StringControls removal of tools or data with invalid configurations before initialization is finished.static final StringThe HTTP content type context key.static final StringThe default content type for the responsestatic final StringDefault encoding for the output streamstatic final StringDefault Runtime properties.static final StringControls loading of available default tool configurations provided by VelocityTools.static final StringThe HTTP output encoding.static final StringThis is the string that is looked for when getInitParameter is called ("org.apache.velocity.properties").static final StringKey used to access the ServletContext in the Velocity application attributes.static final StringKey used to access the toolbox configuration file path from the Servlet or webapp init parameters ("org.apache.velocity.tools") or to access a liveFactoryConfigurationpreviously placed in the ServletContext attributes.static final StringControls whether or not templates can overwrite tool and servlet API variables in the local context.static final StringDefault velocity properties file path.static final StringDefault toolbox configuration file path.从类继承的字段 org.apache.velocity.tools.view.ViewToolManager
CREATE_SESSION_PROPERTY, DEFAULT_TOOLBOX_KEY, PUBLISH_TOOLBOXES_PROPERTY, servletContext从类继承的字段 org.apache.velocity.tools.ToolManager
factory, log, velocity -
构造器概要
构造器构造器说明VelocityView(jakarta.servlet.FilterConfig config) VelocityView(jakarta.servlet.ServletConfig config) VelocityView(jakarta.servlet.ServletContext context) VelocityView(JeeConfig config) -
方法概要
修饰符和类型方法说明protected voidprotected voidconfigure(JeeConfig config, ToolboxFactory factory) Here's the configuration lookup/loading order: If loadDefaults is true,ConfigurationUtils.getDefaultTools()Config file optionally specified by servletContextorg.apache.velocity.toolsinit-param Config file optionally at/WEB-INF/tools.xml(conventional location) Config file optionally specified by servletorg.apache.velocity.toolsinit-param Remember that as these configurations are added on top of each other, the newer values will always override the older ones.createContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Creates and returns an initialized Velocity context.protected FactoryConfigurationgetConfiguration(String path) protected FactoryConfigurationgetConfiguration(String path, boolean required) protected FactoryConfigurationprotected InputStreamgetInputStream(String path, boolean required) protected PropertiesgetProperties(String path) protected PropertiesgetProperties(String path, boolean required) protected StringgetProperty(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.TemplategetTemplate(jakarta.servlet.http.HttpServletRequest request) Gets the requested template.org.apache.velocity.TemplategetTemplate(String name) Retrieves the requested template.org.apache.velocity.TemplategetTemplate(String name, String encoding) Retrieves the requested template with the specified character encoding.protected voidInitializes ToolboxFactory, VelocityEngine, and sets default encoding for processing requests.protected voidInitializes the Velocity runtime, first calling loadConfiguration(JeeConfig) to get a java.util.Properties of configuration information and then calling velocityEngine.init().voidmerge(org.apache.velocity.Template template, org.apache.velocity.context.Context context, Writer writer) Merges the template with the context.protected voidperformMerge(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.Contextrender(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) org.apache.velocity.context.ContextvoidsetDefaultContentType(String type) Sets the configured default Content-Type.protected voidsetEncoding(JeeConfig config) voidsetVelocityEngine(org.apache.velocity.app.VelocityEngine engine) Overrides super class to ensure engine is not set to null.从类继承的方法 org.apache.velocity.tools.view.ViewToolManager
addToolboxes, autoConfigure, configure, createContext, findConfig, getCreateSession, getPublishToolboxes, getSessionToolbox, getSessionToolbox, getToolboxKey, hasSessionTools, prepareContext, publishApplicationTools, publishToolboxes, publishToolboxes, setCreateSession, setPublishToolboxes, setToolboxKey, unpublishApplicationTools, updateGlobalProperties从类继承的方法 org.apache.velocity.tools.ToolManager
configure, createContext, createToolbox, getApplicationToolbox, getLog, getRequestToolbox, getToolboxFactory, getUserCanOverwriteTools, getVelocityEngine, hasApplicationTools, hasRequestTools, hasTools, initLog, prepareContext, setToolboxFactory, setUserCanOverwriteTools
-
字段详细资料
-
CONTENT_TYPE_KEY
The HTTP content type context key.- 另请参阅:
-
OUTPUT_ENCODING_KEY
The HTTP output encoding.- 另请参阅:
-
SERVLET_CONTEXT_KEY
Key used to access the ServletContext in the Velocity application attributes. -
DEFAULT_CONTENT_TYPE
The default content type for the response- 另请参阅:
-
DEFAULT_OUTPUT_ENCODING
Default encoding for the output stream- 另请参阅:
-
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 liveFactoryConfigurationpreviously placed in the ServletContext attributes.- 另请参阅:
-
USER_TOOLS_PATH
Default toolbox configuration file path. If no alternate value for this is specified, the servlet will look here.- 另请参阅:
-
DEFAULT_PROPERTIES_PATH
Default Runtime properties.- 另请参阅:
-
PROPERTIES_KEY
This is the string that is looked for when getInitParameter is called ("org.apache.velocity.properties").- 另请参阅:
-
USER_PROPERTIES_PATH
Default velocity properties file path. If no alternate value for this is specified, the servlet will look here.- 另请参阅:
-
LOAD_DEFAULTS_KEY
Controls loading of available default tool configurations provided by VelocityTools. The default is false.- 另请参阅:
-
CLEAN_CONFIGURATION_KEY
Controls removal of tools or data with invalid configurations before initialization is finished. The default is false; set totrueto turn this feature on.- 另请参阅:
-
USER_OVERWRITE_KEY
Controls whether or not templates can overwrite tool and servlet API variables in the local context. The default is true; set tofalseto prevent overwriting of any tool variables.- 另请参阅:
-
-
构造器详细资料
-
VelocityView
public VelocityView(jakarta.servlet.ServletConfig config) -
VelocityView
public VelocityView(jakarta.servlet.FilterConfig config) -
VelocityView
public VelocityView(jakarta.servlet.ServletContext context) -
VelocityView
-
-
方法详细资料
-
setVelocityEngine
public void setVelocityEngine(org.apache.velocity.app.VelocityEngine engine) Overrides super class to ensure engine is not set to null.- 覆盖:
setVelocityEngine在类中ToolManager
-
getDefaultContentType
- 返回:
- the configured default Content-Type.
-
setDefaultContentType
Sets the configured default Content-Type.- 参数:
type- default content type
-
getProperty
Simplifies process of getting a property from VelocityEngine, because the VelocityEngine interface sucks compared to the singleton's. Use of this method assumes thatinit(JeeConfig,VelocityEngine)has already been called.- 参数:
key- property keyalternate- default value- 返回:
- property value
-
init
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 configuation
-
init
Initializes the Velocity runtime, first calling loadConfiguration(JeeConfig) to get a java.util.Properties of configuration information and then calling velocityEngine.init(). Override this to do anything to the environment before the initialization of the singleton takes place, or to initialize the singleton in other ways.- 参数:
config- servlet configuration parametersvelocity- VelocityEngine instance
-
configure
-
configure
Here's the configuration lookup/loading order:- If loadDefaults is true,
ConfigurationUtils.getDefaultTools() - Config file optionally specified by servletContext
org.apache.velocity.toolsinit-param - Config file optionally at
/WEB-INF/tools.xml(conventional location) - Config file optionally specified by servlet
org.apache.velocity.toolsinit-param
org.apache.velocity.tools.cleanConfigurationinit-param to true in either your servlet or servletContext init-params.- 参数:
config- configuration values containerfactory- toolbox factory instance
- If loadDefaults is true,
-
getDefaultToolsConfiguration
-
getInputStream
-
getProperties
-
getProperties
-
getConfiguration
-
getConfiguration
-
setEncoding
-
render
public org.apache.velocity.context.Context render(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException - 参数:
request- HttpServletRequest object containing client requestresponse- HttpServletResponse object for the response- 返回:
- the
Contextprepared and used to perform the rendering to allow proper cleanup afterward - 抛出:
IOException- if thrown by underling code
-
render
public org.apache.velocity.context.Context render(jakarta.servlet.http.HttpServletRequest request, Writer out) throws IOException - 抛出:
IOException
-
createContext
public ViewToolContext createContext(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Creates and returns an initialized Velocity context.
A new context of classViewToolContextis created and initialized.- 覆盖:
createContext在类中ViewToolManager- 参数:
request- servlet request from clientresponse- servlet reponse to client- 返回:
- newly created context
-
getTemplate
public org.apache.velocity.Template getTemplate(jakarta.servlet.http.HttpServletRequest request) Gets the requested template.
- 参数:
request- client request- 返回:
- Velocity Template object or null
-
getTemplate
Retrieves the requested template.- 参数:
name- The file name of the template to retrieve relative to the template root.- 返回:
- The requested template.
- 抛出:
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.
-
getTemplate
Retrieves the requested template with the specified character encoding.- 参数:
name- The file name of the template to retrieve relative to the template root.encoding- the character encoding of the template- 返回:
- The requested template.
- 抛出:
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.
-
merge
public void merge(org.apache.velocity.Template template, org.apache.velocity.context.Context context, Writer writer) throws IOException Merges the template with the context. Only override this if you really, really really need to. (And don't call us with questions if it breaks :)- 参数:
template- template being renderedcontext- Context created by thecreateContext(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)writer- into which the content is rendered- 抛出:
IOException- if thrown by underling code
-
performMerge
protected void performMerge(org.apache.velocity.Template template, org.apache.velocity.context.Context context, Writer writer) throws IOException This is here so developers may override it and gain access to the Writer which the template will be merged into. See VELTOOLS-7 for discussion of this.- 参数:
template- template object returned by the handleRequest() methodcontext- Context created by thecreateContext(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)writer- a VelocityWriter that the template is merged into- 抛出:
IOException- if thrown by underling code
-