Package com.atlassian.jira.util.velocity
Class DefaultVelocityRequestContextFactory
java.lang.Object
com.atlassian.jira.util.velocity.DefaultVelocityRequestContextFactory
- All Implemented Interfaces:
VelocityRequestContextFactory
public class DefaultVelocityRequestContextFactory
extends Object
implements VelocityRequestContextFactory
Return an instance of
VelocityRequestContext
, depending on whether we are called from a web or non-web context.
The original intention of this class is to get around bugs such as JRA-11038, where velocity fragments are called from both
web and non-web contexts. Originally we tried to proxy HttpServletRequest, but it makes more sense to have a specific interface
VelocityRequestContext
.
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.DefaultVelocityRequestContextFactory
(ApplicationProperties applicationProperties) -
Method Summary
Modifier and TypeMethodDescriptionvoid
cacheVelocityRequestContext
(VelocityRequestContext velocityRequestContext) Deprecated.static void
cacheVelocityRequestContext
(String baseUrl, javax.servlet.http.HttpServletRequest request) static void
cacheVelocityRequestContext
(javax.servlet.http.HttpServletRequest request) Deprecated.void
Resets the thread local storage as if no request has occurred, effectively nulling out the current thread local velocity request context.getDefaultVelocityParams
(Map<String, Object> startingParams, JiraAuthenticationContext authenticationContext) Constructs a map with a number of common parameters used by velocity templates.Get the request context.<I,
O> O runWithStaticBaseUrl
(I input, com.google.common.base.Function<I, O> runnable) Run the passed function in an environment where JIRA's configuredbaseURL
is always used.void
setVelocityRequestContext
(VelocityRequestContext velocityRequestContext) Update the thread-local storage with the given velocityRequestContext.void
setVelocityRequestContext
(String baseUrl, javax.servlet.http.HttpServletRequest request) Update the thread-local storage with the given request information.void
setVelocityRequestContext
(javax.servlet.http.HttpServletRequest request) Update the thread-local storage with the given request information.
-
Constructor Details
-
DefaultVelocityRequestContextFactory
-
DefaultVelocityRequestContextFactory
public DefaultVelocityRequestContextFactory()Deprecated.
-
-
Method Details
-
getJiraVelocityRequestContext
Description copied from interface:VelocityRequestContextFactory
Get the request context.- Specified by:
getJiraVelocityRequestContext
in interfaceVelocityRequestContextFactory
- Returns:
- The request context.
-
getDefaultVelocityParams
public Map<String,Object> getDefaultVelocityParams(Map<String, Object> startingParams, JiraAuthenticationContext authenticationContext) Description copied from interface:VelocityRequestContextFactory
Constructs a map with a number of common parameters used by velocity templates.- Specified by:
getDefaultVelocityParams
in interfaceVelocityRequestContextFactory
- Parameters:
startingParams
- Map of parameters that may be used to override any of the parameters set here.authenticationContext
- JiraAuthenticationContext- Returns:
- a Map with common velocity parameters
-
cacheVelocityRequestContext
public static void cacheVelocityRequestContext(javax.servlet.http.HttpServletRequest request) Deprecated.UseVelocityRequestContextFactory.setVelocityRequestContext(javax.servlet.http.HttpServletRequest)
instead. Since v5.0.Called from a servlet filter. Passes theHttpServletRequest.getContextPath()
along as the baseUrl.- Parameters:
request
- The HttpServletRequest used to construct theRequestContextParameterHolder
-
setVelocityRequestContext
public void setVelocityRequestContext(javax.servlet.http.HttpServletRequest request) Description copied from interface:VelocityRequestContextFactory
Update the thread-local storage with the given request information.- Specified by:
setVelocityRequestContext
in interfaceVelocityRequestContextFactory
- Parameters:
request
- The http request context to store.
-
cacheVelocityRequestContext
public static void cacheVelocityRequestContext(String baseUrl, javax.servlet.http.HttpServletRequest request) Deprecated.Should be called from a servlet filter before the request gets a chance to run- Parameters:
baseUrl
- Should pass inHttpServletRequest.getContextPath()
request
- The HttpServletRequest used to construct theRequestContextParameterHolder
-
setVelocityRequestContext
public void setVelocityRequestContext(String baseUrl, javax.servlet.http.HttpServletRequest request) Description copied from interface:VelocityRequestContextFactory
Update the thread-local storage with the given request information.- Specified by:
setVelocityRequestContext
in interfaceVelocityRequestContextFactory
- Parameters:
baseUrl
- of the request.request
- The http request context to store.
-
cacheVelocityRequestContext
Deprecated.UseVelocityRequestContextFactory.setVelocityRequestContext(VelocityRequestContext)
instead. Since v5.0.Description copied from interface:VelocityRequestContextFactory
Update the thread-local storage with the given velocityRequestContext.- Specified by:
cacheVelocityRequestContext
in interfaceVelocityRequestContextFactory
- Parameters:
velocityRequestContext
- The velocity request context to store.
-
setVelocityRequestContext
Description copied from interface:VelocityRequestContextFactory
Update the thread-local storage with the given velocityRequestContext.- Specified by:
setVelocityRequestContext
in interfaceVelocityRequestContextFactory
- Parameters:
velocityRequestContext
- The velocity request context to store.
-
runWithStaticBaseUrl
public <I,O> O runWithStaticBaseUrl(I input, @Nonnull com.google.common.base.Function<I, O> runnable) Description copied from interface:VelocityRequestContextFactory
Run the passed function in an environment where JIRA's configuredbaseURL
is always used. This basically makes the passed function ignore any smartbaseURL
that can be generated from the request associated with the calling thread.- Specified by:
runWithStaticBaseUrl
in interfaceVelocityRequestContextFactory
- Parameters:
input
- input to pass to the function.runnable
- the function to execute.- Returns:
- the result of the function.
-
clearVelocityRequestContext
public void clearVelocityRequestContext()Description copied from interface:VelocityRequestContextFactory
Resets the thread local storage as if no request has occurred, effectively nulling out the current thread local velocity request context.- Specified by:
clearVelocityRequestContext
in interfaceVelocityRequestContextFactory
-
DefaultVelocityRequestContextFactory(com.atlassian.jira.config.properties.ApplicationProperties)
instead