org.thymeleaf.context
Class WebContext

Object
  extended by org.thymeleaf.context.AbstractContext
      extended by org.thymeleaf.context.WebContext
All Implemented Interfaces:
IContext, IWebContext

public class WebContext
extends AbstractContext
implements IWebContext

Standard implementation for the IWebContext interface.

This IContext implementation uses a WebContextExecutionInfo object as its IContextExecutionInfo implementation.

Since:
1.0
Author:
Daniel Fernández

Field Summary
static String APPLICATION_VARIABLE_NAME
           Name of the context variable that contains the application (servlet context) attributes.
static String PARAM_VARIABLE_NAME
           Name of the context variable that contains the request parameters.
static String SESSION_VARIABLE_NAME
           Name of the context variable that contains the session attributes.
 
Fields inherited from class org.thymeleaf.context.AbstractContext
EXEC_INFO_VARIABLE_NAME
 
Constructor Summary
WebContext(javax.servlet.http.HttpServletRequest request)
           Create an instance without specifying a locale.
WebContext(javax.servlet.http.HttpServletRequest request, Locale locale)
           Create an instance specifying a locale.
WebContext(javax.servlet.http.HttpServletRequest request, Locale locale, Map<String,?> variables)
           Create an instance specifying a locale and an initial set of context variables.
 
Method Summary
protected  IContextExecutionInfo buildContextExecutionInfo(String templateName)
           Creates the specific instance of IContextExecutionInfo to be added to the context as the execInfo variable.
 VariablesMap<String,Object> getApplicationAttributes()
           Returns a VariablesMap object with all the attributes associated with the ServletContext object linked to the HttpServletRequest used for creating the context.
 String getContextPath()
           Returns the context path associated with the web application.
 VariablesMap<String,Object> getRequestAttributes()
           Returns a VariablesMap object with all the attributes associated with the HttpServletRequest used for creating the context.
 VariablesMap<String,String[]> getRequestParameters()
           Returns a VariablesMap object with all the parameters associated with the HttpServletRequest used for creating the context.
 javax.servlet.ServletContext getServletContext()
           Returns the ServletContext object associated with the web application.
 VariablesMap<String,Object> getSessionAttributes()
           Returns a VariablesMap object with all the attributes associated with the HttpSession object linked to the HttpServletRequest used for creating the context.
 String getSessionID()
           Returns the session ID associated with the current execution of the template engine.
 boolean isSessionIdFromCookie()
           Returns whether the session ID is currently being kept by using cookies or an URL fragment.
 
Methods inherited from class org.thymeleaf.context.AbstractContext
addContextExecutionInfo, clearVariables, getLocale, getVariables, setLocale, setVariable, setVariables
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.thymeleaf.context.IContext
addContextExecutionInfo, getLocale, getVariables
 

Field Detail

PARAM_VARIABLE_NAME

public static final String PARAM_VARIABLE_NAME

Name of the context variable that contains the request parameters.

See Also:
Constant Field Values

SESSION_VARIABLE_NAME

public static final String SESSION_VARIABLE_NAME

Name of the context variable that contains the session attributes.

See Also:
Constant Field Values

APPLICATION_VARIABLE_NAME

public static final String APPLICATION_VARIABLE_NAME

Name of the context variable that contains the application (servlet context) attributes.

See Also:
Constant Field Values
Constructor Detail

WebContext

public WebContext(javax.servlet.http.HttpServletRequest request)

Create an instance without specifying a locale. Using this constructor, the default locale (Locale.getDefault()) will be used.

Parameters:
request - the HttpServletRequest that this context will be related to.

WebContext

public WebContext(javax.servlet.http.HttpServletRequest request,
                  Locale locale)

Create an instance specifying a locale.

Parameters:
request - the HttpServletRequest that this context will be related to.
locale - the locale to be used.

WebContext

public WebContext(javax.servlet.http.HttpServletRequest request,
                  Locale locale,
                  Map<String,?> variables)

Create an instance specifying a locale and an initial set of context variables.

Parameters:
request - the HttpServletRequest that this context will be related to.
locale - the locale to be used.
variables - the initial set of context variables.
Method Detail

getServletContext

public javax.servlet.ServletContext getServletContext()
Description copied from interface: IWebContext

Returns the ServletContext object associated with the web application.

Specified by:
getServletContext in interface IWebContext
Returns:
the servlet context.

getContextPath

public String getContextPath()
Description copied from interface: IWebContext

Returns the context path associated with the web application.

Specified by:
getContextPath in interface IWebContext
Returns:
the context path of the web application.

getSessionID

public String getSessionID()
Description copied from interface: IWebContext

Returns the session ID associated with the current execution of the template engine. This ID corresponds with the jsessionid URL fragment or cookie from the HTTP request.

Specified by:
getSessionID in interface IWebContext
Returns:
the session ID.

isSessionIdFromCookie

public boolean isSessionIdFromCookie()
Description copied from interface: IWebContext

Returns whether the session ID is currently being kept by using cookies or an URL fragment.

Specified by:
isSessionIdFromCookie in interface IWebContext
Returns:
true if a JSESSIONID cookie is being used, false if a ";jsessionid=..." URL fragment is being used.

getRequestParameters

public VariablesMap<String,String[]> getRequestParameters()
Description copied from interface: IWebContext

Returns a VariablesMap object with all the parameters associated with the HttpServletRequest used for creating the context.

Specified by:
getRequestParameters in interface IWebContext
Returns:
the maps of request parameters.

getRequestAttributes

public VariablesMap<String,Object> getRequestAttributes()
Description copied from interface: IWebContext

Returns a VariablesMap object with all the attributes associated with the HttpServletRequest used for creating the context.

Specified by:
getRequestAttributes in interface IWebContext
Returns:
the maps of request attributes.

getSessionAttributes

public VariablesMap<String,Object> getSessionAttributes()
Description copied from interface: IWebContext

Returns a VariablesMap object with all the attributes associated with the HttpSession object linked to the HttpServletRequest used for creating the context.

Specified by:
getSessionAttributes in interface IWebContext
Returns:
the maps of session attributes.

getApplicationAttributes

public VariablesMap<String,Object> getApplicationAttributes()
Description copied from interface: IWebContext

Returns a VariablesMap object with all the attributes associated with the ServletContext object linked to the HttpServletRequest used for creating the context.

Specified by:
getApplicationAttributes in interface IWebContext
Returns:
the maps of application attributes.

buildContextExecutionInfo

protected IContextExecutionInfo buildContextExecutionInfo(String templateName)
Description copied from class: AbstractContext

Creates the specific instance of IContextExecutionInfo to be added to the context as the execInfo variable.

Specified by:
buildContextExecutionInfo in class AbstractContext
Parameters:
templateName - the name of the template being executed
Returns:
the execution info object


Copyright © 2011 The THYMELEAF team. All Rights Reserved.