public class

DefaultVelocityRequestContextFactory

extends Object
implements VelocityRequestContextFactory
java.lang.Object
   ↳ com.atlassian.jira.util.velocity.DefaultVelocityRequestContextFactory

Class Overview

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.

Summary

Public Constructors
DefaultVelocityRequestContextFactory(ApplicationProperties applicationProperties)
DefaultVelocityRequestContextFactory()
Public Methods
static void cacheVelocityRequestContext(HttpServletRequest request)
This method is deprecated. Use setVelocityRequestContext(javax.servlet.http.HttpServletRequest) instead. Since v5.0.
void cacheVelocityRequestContext(VelocityRequestContext velocityRequestContext)
This method is deprecated. Use setVelocityRequestContext(VelocityRequestContext) instead. Since v5.0.
static void cacheVelocityRequestContext(String baseUrl, HttpServletRequest request)
This method is deprecated. Use setVelocityRequestContext(String, javax.servlet.http.HttpServletRequest) instead. Since v5.0.
void clearVelocityRequestContext()
Resets the thread local storage as if no request has occurred, effectively nulling out the current thread local velocity request context.
Map<StringObject> getDefaultVelocityParams(Map<StringObject> startingParams, JiraAuthenticationContext authenticationContext)
Constructs a map with a number of common parameters used by velocity templates.
VelocityRequestContext getJiraVelocityRequestContext()
Get the request context.
<I, O> O runWithStaticBaseUrl(I input, Function<I, O> runnable)
Run the passed function in an environment where JIRA's configured baseURL is always used.
void setVelocityRequestContext(HttpServletRequest request)
Update the thread-local storage with the given request information.
void setVelocityRequestContext(String baseUrl, HttpServletRequest request)
Update the thread-local storage with the given request information.
void setVelocityRequestContext(VelocityRequestContext velocityRequestContext)
Update the thread-local storage with the given velocityRequestContext.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.util.velocity.VelocityRequestContextFactory

Public Constructors

public DefaultVelocityRequestContextFactory (ApplicationProperties applicationProperties)

public DefaultVelocityRequestContextFactory ()

Public Methods

public static void cacheVelocityRequestContext (HttpServletRequest request)

This method is deprecated.
Use setVelocityRequestContext(javax.servlet.http.HttpServletRequest) instead. Since v5.0.

Called from a servlet filter. Passes the getContextPath() along as the baseUrl.

Parameters
request The HttpServletRequest used to construct the RequestContextParameterHolder

public void cacheVelocityRequestContext (VelocityRequestContext velocityRequestContext)

This method is deprecated.
Use setVelocityRequestContext(VelocityRequestContext) instead. Since v5.0.

Update the thread-local storage with the given velocityRequestContext.

Parameters
velocityRequestContext The velocity request context to store.

public static void cacheVelocityRequestContext (String baseUrl, HttpServletRequest request)

This method is deprecated.
Use setVelocityRequestContext(String, javax.servlet.http.HttpServletRequest) instead. Since v5.0.

Should be called from a servlet filter before the request gets a chance to run

Parameters
baseUrl Should pass in getContextPath()
request The HttpServletRequest used to construct the RequestContextParameterHolder

public void clearVelocityRequestContext ()

Resets the thread local storage as if no request has occurred, effectively nulling out the current thread local velocity request context.

public Map<StringObject> getDefaultVelocityParams (Map<StringObject> startingParams, JiraAuthenticationContext authenticationContext)

Constructs a map with a number of common parameters used by velocity templates.

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

public VelocityRequestContext getJiraVelocityRequestContext ()

Get the request context.

Returns
  • The request context.

public O runWithStaticBaseUrl (I input, Function<I, O> runnable)

Run the passed function in an environment where JIRA's configured baseURL is always used. This basically makes the passed function ignore any smart baseURL that can be generated from the request associated with the calling thread.

Parameters
input input to pass to the function.
runnable the function to execute.
Returns
  • the result of the function.

public void setVelocityRequestContext (HttpServletRequest request)

Update the thread-local storage with the given request information.

Parameters
request The http request context to store.

public void setVelocityRequestContext (String baseUrl, HttpServletRequest request)

Update the thread-local storage with the given request information.

Parameters
baseUrl of the request.
request The http request context to store.

public void setVelocityRequestContext (VelocityRequestContext velocityRequestContext)

Update the thread-local storage with the given velocityRequestContext.

Parameters
velocityRequestContext The velocity request context to store.