Class StrutsVelocityManager
java.lang.Object
org.apache.struts2.views.velocity.StrutsVelocityManager
- All Implemented Interfaces:
- VelocityManager
Manages the environment for Velocity result types
- Since:
- 7.0
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected org.apache.velocity.context.ContextbuildContext(ValueStack stack, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) org.apache.velocity.context.ContextcreateContext(ValueStack stack, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) This method is responsible for creating the standard VelocityContext used by all Struts Velocity views.org.apache.velocity.app.VelocityEnginevoidinit(jakarta.servlet.ServletContext context) initializes the StrutsVelocityManager.protected PropertiesloadConfiguration(jakarta.servlet.ServletContext context) protected org.apache.velocity.app.VelocityEnginenewVelocityEngine(jakarta.servlet.ServletContext context) Instantiates a new VelocityEngine.protected List<org.apache.velocity.VelocityContext>prepareChainedContexts(jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.servlet.http.HttpServletResponse servletResponse, Map<String, Object> extraContext) Constructs contexts for chaining on this request.voidsetChainedContexts(String contexts) Allow users to specify via the struts.properties file a set of additional VelocityContexts to chain to the StrutsVelocityContext.voidsetContainer(Container container) voidsetCustomConfigFile(String customConfigFile) voidvoidsetToolBoxLocation(String toolboxLocation) voidsetVelocityProperties(Properties velocityProperties) 
- 
Field Details- 
DEFAULT_CONFIG_FILE- See Also:
 
- 
KEY_VELOCITY_STRUTS_CONTEXT- See Also:
 
 
- 
- 
Constructor Details- 
StrutsVelocityManagerpublic StrutsVelocityManager()
 
- 
- 
Method Details- 
setObjectFactory
- 
setContainer
- 
getVelocityEnginepublic org.apache.velocity.app.VelocityEngine getVelocityEngine()- Specified by:
- getVelocityEnginein interface- VelocityManager
- Returns:
- a reference to the VelocityEngine used by all Struts Velocity results except directly accessed *.vm pages (unless otherwise configured)
 
- 
createContextpublic org.apache.velocity.context.Context createContext(ValueStack stack, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) This method is responsible for creating the standard VelocityContext used by all Struts Velocity views.- Specified by:
- createContextin interface- VelocityManager
- Parameters:
- stack- the current- ValueStack
- req- the current HttpServletRequest
- res- the current HttpServletResponse
- Returns:
- a new StrutsVelocityContext
 
- 
buildContextprotected org.apache.velocity.context.Context buildContext(ValueStack stack, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) 
- 
prepareChainedContextsprotected List<org.apache.velocity.VelocityContext> prepareChainedContexts(jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.servlet.http.HttpServletResponse servletResponse, Map<String, Object> extraContext) Constructs contexts for chaining on this request. This method does not perform any initialization of the contexts. All that must be done in the context itself.- Parameters:
- servletRequest- the servlet request object
- servletResponse- the servlet response object
- extraContext- map with extra context
- Returns:
- a List of contexts to chain or an empty list
 
- 
initpublic void init(jakarta.servlet.ServletContext context) initializes the StrutsVelocityManager. this should be called during the initialization process, say by ServletDispatcher. this may be called multiple times safely although calls beyond the first won't do anything- Specified by:
- initin interface- VelocityManager
- Parameters:
- context- the current servlet context
 
- 
loadConfiguration
- 
setCustomConfigFile
- 
setToolBoxLocation
- 
getVelocityTools
- 
setChainedContextsAllow users to specify via the struts.properties file a set of additional VelocityContexts to chain to the StrutsVelocityContext. The intent is to allow these contexts to store helper objects that the ui developer may want access to. Examples of reasonable VelocityContexts would be an IoCVelocityContext, a SpringReferenceVelocityContext, and a ToolboxVelocityContext- Parameters:
- contexts- comma separated velocity context's
 
- 
newVelocityEngineprotected org.apache.velocity.app.VelocityEngine newVelocityEngine(jakarta.servlet.ServletContext context) Instantiates a new VelocityEngine.The following is the default Velocity configuration resource.loader = file, class file.resource.loader.path = real path of webapp class.resource.loader.description = Velocity Classpath Resource Loader class.resource.loader.class = org.apache.struts2.views.velocity.StrutsResourceLoader This default configuration can be overridden by specifying a struts.velocity.configfile property in the struts.properties file. the specified config file will be searched for in the following order:- relative to the servlet context path
- relative to the WEB-INF directory
- on the classpath
 - Parameters:
- context- the current ServletContext. may not be null
- Returns:
- the new velocity engine
 
- 
getVelocityProperties- Returns:
- the velocityProperties
 
- 
setVelocityProperties- Parameters:
- velocityProperties- the velocityProperties to set
 
 
-