Package org.apache.velocity.tools.view
Class ServletUtils
- java.lang.Object
-
- org.apache.velocity.tools.view.ServletUtils
-
public class ServletUtils extends java.lang.ObjectA set of utility methods for supporting and using VelocityTools in the servlet environment.
- Version:
- $Id: ServletUtils.java 471244 2006-11-04 18:34:38Z henning $
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringALT_VELOCITY_VIEW_KEYstatic java.lang.StringCONFIGURATION_KEYKey used to access a liveFactoryConfigurationpreviously placed in the ServletContext attributes.static ServletUtilsINSTANCEstatic java.lang.StringSHARED_CONFIG_PARAMstatic java.lang.StringVELOCITY_VIEW_KEY
-
Constructor Summary
Constructors Modifier Constructor Description protectedServletUtils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcombinePath(java.lang.String before, java.lang.String after)If end is null, this will return start and vice versa.static java.lang.ObjectfindTool(java.lang.String key, java.lang.String toolboxKey, javax.servlet.http.HttpServletRequest request)static java.lang.ObjectfindTool(java.lang.String key, java.lang.String toolboxKey, javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext application)static java.lang.ObjectfindTool(java.lang.String key, java.lang.String toolboxKey, javax.servlet.ServletContext application)static java.lang.ObjectfindTool(java.lang.String key, javax.servlet.http.HttpServletRequest request)static java.lang.ObjectfindTool(java.lang.String key, javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext application)static java.lang.ObjectfindTool(java.lang.String key, javax.servlet.ServletContext application)static org.apache.velocity.tools.config.FactoryConfigurationgetConfiguration(java.lang.String path, javax.servlet.ServletContext application)static org.apache.velocity.tools.config.FactoryConfigurationgetConfiguration(javax.servlet.ServletContext application)static java.io.InputStreamgetInputStream(java.lang.String path, javax.servlet.ServletContext application)ServletUtilsgetInstance()static java.lang.ObjectgetMutex(javax.servlet.http.HttpSession session, java.lang.String key, java.lang.Object caller)Returns a mutex (lock object) unique to the specified session and stored under the specified key to allow for reliable synchronization on the session.static java.lang.StringgetPath(javax.servlet.http.HttpServletRequest request)Retrieves the path for the specified request regardless of whether this is a direct request or an include by the RequestDispatcher.static java.net.URLgetURL(java.lang.String path, javax.servlet.ServletContext application)static VelocityViewgetVelocityView(javax.servlet.FilterConfig config)Returns the sharedVelocityViewfor the specifiedFilterConfig's context.static VelocityViewgetVelocityView(javax.servlet.ServletConfig config)Returns the sharedVelocityViewfor the specifiedServletConfig's context.static VelocityViewgetVelocityView(javax.servlet.ServletContext application)Returns the sharedVelocityViewfor the specifiedServletContext.static VelocityViewgetVelocityView(javax.servlet.ServletContext application, boolean createIfMissing)Returns the sharedVelocityViewfor the specifiedServletContext.static VelocityViewgetVelocityView(JeeConfig config)Returns the sharedVelocityViewfor the specifiedJeeConfig's context.protected static booleanisWebappResource(java.lang.String path)
-
-
-
Field Detail
-
VELOCITY_VIEW_KEY
public static final java.lang.String VELOCITY_VIEW_KEY
-
SHARED_CONFIG_PARAM
public static final java.lang.String SHARED_CONFIG_PARAM
- See Also:
- Constant Field Values
-
ALT_VELOCITY_VIEW_KEY
public static final java.lang.String ALT_VELOCITY_VIEW_KEY
- See Also:
- Constant Field Values
-
CONFIGURATION_KEY
public static final java.lang.String CONFIGURATION_KEY
Key used to access a liveFactoryConfigurationpreviously placed in the ServletContext attributes.- See Also:
- Constant Field Values
-
INSTANCE
public static final ServletUtils INSTANCE
-
-
Method Detail
-
getInstance
public ServletUtils getInstance()
-
getPath
public static java.lang.String getPath(javax.servlet.http.HttpServletRequest request)
Retrieves the path for the specified request regardless of whether this is a direct request or an include by the RequestDispatcher.- Parameters:
request- servlet request- Returns:
- request path
-
getVelocityView
public static VelocityView getVelocityView(javax.servlet.ServletConfig config)
Returns the sharedVelocityViewfor the specifiedServletConfig's context. If one has not yet been created, it will create, store it for future access, and then return it.- Parameters:
config- servlet config- Returns:
- VelocityView instance
-
getVelocityView
public static VelocityView getVelocityView(javax.servlet.FilterConfig config)
Returns the sharedVelocityViewfor the specifiedFilterConfig's context. If one has not yet been created, it will create, store it for future access, and then return it.- Parameters:
config- filter config- Returns:
- VelocityView instance
-
getVelocityView
public static VelocityView getVelocityView(JeeConfig config)
Returns the sharedVelocityViewfor the specifiedJeeConfig's context. If one has not yet been created, it will create, store it for future access, and then return it.- Parameters:
config- configuration parameters container (webapp, servlet or filter)- Returns:
- VelocityView instance
-
getVelocityView
public static VelocityView getVelocityView(javax.servlet.ServletContext application)
Returns the sharedVelocityViewfor the specifiedServletContext. If one has not yet been created, it will create one, store it for future access, and then return it.- Parameters:
application- servlet context- Returns:
- VelocityView instance
-
getVelocityView
public static VelocityView getVelocityView(javax.servlet.ServletContext application, boolean createIfMissing)
Returns the sharedVelocityViewfor the specifiedServletContext. If one has not yet been created and the second parameter istrue, then it will create one, store it for future access, and return it.- Parameters:
application- servlet contextcreateIfMissing- whether to create VelocityView if not yet built- Returns:
- VelocityView instance
-
findTool
public static java.lang.Object findTool(java.lang.String key, javax.servlet.ServletContext application)
-
findTool
public static java.lang.Object findTool(java.lang.String key, java.lang.String toolboxKey, javax.servlet.ServletContext application)
-
findTool
public static java.lang.Object findTool(java.lang.String key, javax.servlet.http.HttpServletRequest request)
-
findTool
public static java.lang.Object findTool(java.lang.String key, java.lang.String toolboxKey, javax.servlet.http.HttpServletRequest request)
-
findTool
public static java.lang.Object findTool(java.lang.String key, javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext application)
-
findTool
public static java.lang.Object findTool(java.lang.String key, java.lang.String toolboxKey, javax.servlet.http.HttpServletRequest request, javax.servlet.ServletContext application)
-
isWebappResource
protected static boolean isWebappResource(java.lang.String path)
-
getInputStream
public static java.io.InputStream getInputStream(java.lang.String path, javax.servlet.ServletContext application)
-
getURL
public static java.net.URL getURL(java.lang.String path, javax.servlet.ServletContext application)
-
getConfiguration
public static org.apache.velocity.tools.config.FactoryConfiguration getConfiguration(javax.servlet.ServletContext application)
-
getConfiguration
public static org.apache.velocity.tools.config.FactoryConfiguration getConfiguration(java.lang.String path, javax.servlet.ServletContext application)
-
getMutex
public static java.lang.Object getMutex(javax.servlet.http.HttpSession session, java.lang.String key, java.lang.Object caller)Returns a mutex (lock object) unique to the specified session and stored under the specified key to allow for reliable synchronization on the session.- Parameters:
session- HTTP sessionkey- mutex keycaller- caller object- Returns:
- session mutex object
-
combinePath
public static java.lang.String combinePath(java.lang.String before, java.lang.String after)If end is null, this will return start and vice versa. If neither is null, this will append the end to the start, making sure that there is only one '/' character between the two values.- Parameters:
before- start pathafter- end path- Returns:
- combined path
-
-