JSF-Spring

de.mindmatters.faces.context
Class ServletExternalContextFake

java.lang.Object
  extended by javax.faces.context.ExternalContext
      extended by de.mindmatters.faces.context.ServletExternalContextFake
All Implemented Interfaces:
DisposableBean

public class ServletExternalContextFake
extends ExternalContext
implements DisposableBean

This class allows the Faces API to be unaware of the nature of its containing application environment.

Note: documentation copied from specification

This class implements the nature of a servlet applicaton environment. As it's name says this class fakes the behavior described in the specifications. This class implements the specified behavior which delegates to the ServletContext. Specified behavior which delegates to the ServletRequest or ServletResponse is not implemented (In fact a UnsupportedOperationException will be thrown).

This class is used on startup time to preinstantiate singletons declared in any Spring-based configuration context which needs a FacesContext for instantiation.

Author:
andreas.kuhrwahl

Field Summary
protected  org.apache.commons.logging.Log logger
          For logging.
 
Fields inherited from class javax.faces.context.ExternalContext
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
ServletExternalContextFake(javax.servlet.ServletContext servletContext)
          Constructs an ExternalContext with the given ServletContext servletContext.
 
Method Summary
 void destroy()
          Invoked by a BeanFactory on destruction of a singleton.
 void dispatch(java.lang.String path)
          

Dispatch a request to the specified resource to create output for this response.

 java.lang.String encodeActionURL(java.lang.String url)
          

Return the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable action in the current application.

 java.lang.String encodeNamespace(java.lang.String name)
          

Return the specified name, after prefixing it with a namespace that ensures that it will be unique within the context of a particular page.

 java.lang.String encodeResourceURL(java.lang.String url)
          

Return the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable resource in the current application.

 java.util.Map getApplicationMap()
          

Return a mutable Map representing the application scope attributes for the current application.

 java.lang.String getAuthType()
          

Return the name of the authentication scheme used to authenticate the current user, if any; otherwise, return null.

 java.lang.Object getContext()
          

Return the application environment object instance for the current appication.

 java.lang.String getInitParameter(java.lang.String name)
          

Return the value of the specified application initialization parameter (if any).

 java.util.Map getInitParameterMap()
          

Return an immutable Map whose keys are the set of application initialization parameter names configured for this application, and whose values are the corresponding parameter values.

 java.lang.String getRemoteUser()
          

Return the login name of the user making the current request if any; otherwise, return null.

 java.lang.Object getRequest()
          

Return the environment-specific object instance for the current request.

 java.lang.String getRequestContextPath()
          

Return the portion of the request URI that identifies the web application context for this request.

 java.util.Map getRequestCookieMap()
          

Return an immutable Map whose keys are the set of cookie names included in the current request, and whose values (of type javax.servlet.http.Cookie) are the first (or only) cookie for each cookie name returned by the underlying request.

 java.util.Map getRequestHeaderMap()
          

Return an immutable Map whose keys are the set of request header names included in the current request, and whose values (of type String) are the first (or only) value for each header name returned by the underlying request.

 java.util.Map getRequestHeaderValuesMap()
          

Return an immutable Map whose keys are the set of request header names included in the current request, and whose values (of type String[]) are all of the value for each header name returned by the underlying request.

 java.util.Locale getRequestLocale()
          

Return the preferred Locale in which the client will accept content.

 java.util.Iterator getRequestLocales()
          

Return an Iterator over the preferred Locales specified in the request, in decreasing order of preference.

 java.util.Map getRequestMap()
          

Return a mutable Map representing the request scope attributes for the current application.

 java.util.Map getRequestParameterMap()
          

Return an immutable Map whose keys are the set of request parameters names included in the current request, and whose values (of type String) are the first (or only) value for each parameter name returned by the underlying request.

 java.util.Iterator getRequestParameterNames()
          

Return an Iterator over the names of all request parameters included in the current request.

 java.util.Map getRequestParameterValuesMap()
          

Return an immutable Map whose keys are the set of request parameters names included in the current request, and whose values (of type String[]) are all of the values for each parameter name returned by the underlying request.

 java.lang.String getRequestPathInfo()
          

Return the extra path information (if any) included in the request URI; otherwise, return null.

 java.lang.String getRequestServletPath()
          

Return the servlet path information (if any) included in the request URI; otherwise, return null.

 java.net.URL getResource(java.lang.String path)
          

Return a URL for the application resource mapped to the specified path, if it exists; otherwise, return null.

 java.io.InputStream getResourceAsStream(java.lang.String path)
          

Return an InputStream for an application resource mapped to the specified path, if it exists; otherwise, return null.

 java.util.Set getResourcePaths(java.lang.String path)
          

Return the Set of resource paths for all application resources whose resource path starts with the specified argument.

 java.lang.Object getResponse()
          

Return the environment-specific object instance for the current response.

protected  javax.servlet.ServletContext getServletContext()
          Returns the ServletContext.
 java.lang.Object getSession(boolean create)
          

If the create parameter is true, create (if necessary) and return a session instance associated with the current request.

 java.util.Map getSessionMap()
          

Return a mutable Map representing the session scope attributes for the current application.

 java.security.Principal getUserPrincipal()
          

Return the Principal object containing the name of the current authenticated user, if any; otherwise, return null.

 boolean isUserInRole(java.lang.String role)
          

Return true if the currently authenticated user is included in the specified role.

 void log(java.lang.String message)
          

Log the specified message to the application object.

 void log(java.lang.String message, java.lang.Throwable exception)
          

Log the specified message and exception to the application object.

 void redirect(java.lang.String url)
          

Redirect a request to the specified URL, and cause the responseComplete() method to be called on the FacesContext instance for the current request.

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
For logging.

Constructor Detail

ServletExternalContextFake

public ServletExternalContextFake(javax.servlet.ServletContext servletContext)
Constructs an ExternalContext with the given ServletContext servletContext.

Parameters:
servletContext - the context of the application environment
Method Detail

dispatch

public void dispatch(java.lang.String path)
              throws java.io.IOException

Dispatch a request to the specified resource to create output for this response.

Servlet: This must be accomplished by calling the javax.servlet.ServletContext method getRequestDispatcher(path), and calling the forward() method on the resulting object.

Portlet: This must be accomplished by calling the javax.portlet.PortletContext method getRequestDispatcher(), and calling the include() method on the resulting object.

Specified by:
dispatch in class ExternalContext
Parameters:
path - Context relative path to the specified resource, which must start with a slash ("/") character
Throws:
java.io.IOException - if an input/output error occurs

encodeActionURL

public java.lang.String encodeActionURL(java.lang.String url)

Return the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable action in the current application.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletResponse method encodeURL(url).

Portlet: This must be the value returned by the javax.portlet.PortletResponse method encodeURL(url).

Specified by:
encodeActionURL in class ExternalContext
Parameters:
url - The input URL to be encoded

encodeNamespace

public java.lang.String encodeNamespace(java.lang.String name)

Return the specified name, after prefixing it with a namespace that ensures that it will be unique within the context of a particular page.

Servlet: The input value must be returned unchanged.

Portlet: The returned value must be the input value prefixed by the value returned by the javax.portlet.RenderResponse method getNamespace().

Specified by:
encodeNamespace in class ExternalContext
Parameters:
name - Name to be encoded

encodeResourceURL

public java.lang.String encodeResourceURL(java.lang.String url)

Return the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable resource in the current application.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletResponse method encodeURL(url).

Portlet: This must be the value returned by the javax.portlet.PortletResponse method encodeURL(url).

Specified by:
encodeResourceURL in class ExternalContext
Parameters:
url - The input URL to be encoded

getApplicationMap

public java.util.Map getApplicationMap()

Return a mutable Map representing the application scope attributes for the current application. The returned Map must implement the entire contract for a modifiable map as described in the JavaDocs for java.util.Map. Modifications made in the Map must cause the corresponding changes in the set of application scope attributes.

Servlet: This must be the set of attributes available via the javax.servlet.ServletContext methods getAttribute(), getAttributeNames(), removeAttribute(), and setAttribute().

Portlet: This must be the set of attributes available via the javax.portlet.PortletContext methods getAttribute(), getAttributeNames(), removeAttribute(), and setAttribute().

Specified by:
getApplicationMap in class ExternalContext

getAuthType

public java.lang.String getAuthType()

Return the name of the authentication scheme used to authenticate the current user, if any; otherwise, return null. For standard authentication schemes, the returned value will match one of the following constants: BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, or FORM_AUTH.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletRequest method getAuthType().

Portlet: This must be the value returned by the javax.portlet.http.PortletRequest method getAuthType().

Specified by:
getAuthType in class ExternalContext

getContext

public java.lang.Object getContext()

Return the application environment object instance for the current appication.

Servlet: This must be the current application's javax.servlet.ServletContext instance.

Portlet: This must be the current application's javax.portlet.PortletContext instance.

Specified by:
getContext in class ExternalContext

getInitParameter

public java.lang.String getInitParameter(java.lang.String name)

Return the value of the specified application initialization parameter (if any).

Servlet: This must be the result of the javax.servlet.ServletContext method getInitParameter(name).

Portlet: This must be the result of the javax.portlet.PortletContext method getInitParameter(name).

Specified by:
getInitParameter in class ExternalContext
Parameters:
name - Name of the requested initialization parameter

getInitParameterMap

public java.util.Map getInitParameterMap()

Return an immutable Map whose keys are the set of application initialization parameter names configured for this application, and whose values are the corresponding parameter values. The returned Map must implement the entire contract for an unmodifiable map as described in the JavaDocs for java.util.Map.

Servlet: This result must be as if it were synthesized by calling the javax.servlet.ServletContext method getInitParameterNames, and putting each configured parameter name/value pair into the result.

Portlet: This result must be as if it were synthesized by calling the javax.portlet.PortletContext method getInitParameterNames, and putting each configured parameter name/value pair into the result.

Specified by:
getInitParameterMap in class ExternalContext

getRemoteUser

public java.lang.String getRemoteUser()

Return the login name of the user making the current request if any; otherwise, return null.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletRequest method getRemoteUser().

Portlet: This must be the value returned by the javax.portlet.http.PortletRequest method getRemoteUser().

Specified by:
getRemoteUser in class ExternalContext

getRequest

public java.lang.Object getRequest()

Return the environment-specific object instance for the current request.

Servlet: This must be the current request's javax.servlet.http.HttpServletRequest instance.

Portlet: This must be the current request's javax.portlet.PortletRequest instance, which will be either an ActionRequest or a RenderRequest depending upon when this method is called.

Specified by:
getRequest in class ExternalContext

getRequestContextPath

public java.lang.String getRequestContextPath()

Return the portion of the request URI that identifies the web application context for this request.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletRequest method getContextPath().

Portlet: This must be the value returned by the javax.portlet.PortletRequest method getContextPath().

Specified by:
getRequestContextPath in class ExternalContext

getRequestCookieMap

public java.util.Map getRequestCookieMap()

Return an immutable Map whose keys are the set of cookie names included in the current request, and whose values (of type javax.servlet.http.Cookie) are the first (or only) cookie for each cookie name returned by the underlying request. The returned Map must implement the entire contract for an unmodifiable map as described in the JavaDocs for java.util.Map.

Servlet: This must be the value returned by the javax.servlet.ServletRequest method getCookies(), unless null was returned, in which case this must be a zero-length array.

Portlet: The must be a zero-length array.

Specified by:
getRequestCookieMap in class ExternalContext

getRequestHeaderMap

public java.util.Map getRequestHeaderMap()

Return an immutable Map whose keys are the set of request header names included in the current request, and whose values (of type String) are the first (or only) value for each header name returned by the underlying request. The returned Map must implement the entire contract for an unmodifiable map as described in the JavaDocs for java.util.Map. In addition, key comparisons must be performed in a case insensitive manner.

Servlet: This must be the set of headers available via the javax.servlet.http.HttpServletRequest methods getHeader() and getHeaderNames().

Portlet: This must be the set of properties available via the javax.portlet.PortletRequest methods getProperty() and getPropertyNames(). As such, HTTP headers will only be included if they were provided by the portlet container, and additional properties provided by the portlet container may also be included.

Specified by:
getRequestHeaderMap in class ExternalContext

getRequestHeaderValuesMap

public java.util.Map getRequestHeaderValuesMap()

Return an immutable Map whose keys are the set of request header names included in the current request, and whose values (of type String[]) are all of the value for each header name returned by the underlying request. The returned Map must implement the entire contract for an unmodifiable map as described in the JavaDocs for java.util.Map. In addition, key comparisons must be performed in a case insensitive manner.

Servlet: This must be the set of headers available via the javax.servlet.http.HttpServletRequest methods getHeaders() and getHeaderNames().

Portlet: This must be the set of properties available via the javax.portlet.PortletRequest methods getProperties() and getPropertyNames(). As such, HTTP headers will only be included if they were provided by the portlet container, and additional properties provided by the portlet container may also be included.

Specified by:
getRequestHeaderValuesMap in class ExternalContext

getRequestLocale

public java.util.Locale getRequestLocale()

Return the preferred Locale in which the client will accept content.

Servlet: This must be the value returned by the javax.servlet.ServletRequest method getLocale().

Portlet: This must be the value returned by the javax.portlet.PortletRequest method getLocale().

Specified by:
getRequestLocale in class ExternalContext

getRequestLocales

public java.util.Iterator getRequestLocales()

Return an Iterator over the preferred Locales specified in the request, in decreasing order of preference.

Servlet: This must be an Iterator over the values returned by the javax.servlet.ServletRequest method getLocales().

Portlet: This must be an Iterator over the values returned by the javax.portlet.PortletRequest method getLocales().

Specified by:
getRequestLocales in class ExternalContext

getRequestMap

public java.util.Map getRequestMap()

Return a mutable Map representing the request scope attributes for the current application. The returned Map must implement the entire contract for a modifiable map as described in the JavaDocs for java.util.Map. Modifications made in the Map must cause the corresponding changes in the set of request scope attributes.

Servlet: This must be the set of attributes available via the javax.servlet.ServletRequest methods getAttribute(), getAttributeNames(), removeAttribute(), and setAttribute().

Portlet: This must be the set of attributes available via the javax.portlet.PortletRequest methods getAttribute(), getAttributeNames(), removeAttribute(), and setAttribute().

Specified by:
getRequestMap in class ExternalContext

getRequestParameterMap

public java.util.Map getRequestParameterMap()

Return an immutable Map whose keys are the set of request parameters names included in the current request, and whose values (of type String) are the first (or only) value for each parameter name returned by the underlying request. The returned Map must implement the entire contract for an unmodifiable map as described in the JavaDocs for java.util.Map.

Servlet: This must be the set of parameters available via the javax.servlet.ServletRequest methods getParameter() and getParameterNames().

Portlet: This must be the set of parameters available via the javax.portlet.PortletRequest methods getParameter() and getParameterNames().

Specified by:
getRequestParameterMap in class ExternalContext

getRequestParameterNames

public java.util.Iterator getRequestParameterNames()

Return an Iterator over the names of all request parameters included in the current request.

Servlet: This must be an Iterator over the values returned by the javax.servlet.ServletRequest method getParameterNames().

Portlet: This must be an Iterator over the values returned by the javax.portlet.PortletRequest method getParameterNames().

Specified by:
getRequestParameterNames in class ExternalContext

getRequestParameterValuesMap

public java.util.Map getRequestParameterValuesMap()

Return an immutable Map whose keys are the set of request parameters names included in the current request, and whose values (of type String[]) are all of the values for each parameter name returned by the underlying request. The returned Map must implement the entire contract for an unmodifiable map as described in the JavaDocs for java.util.Map.

Servlet: This must be the set of parameters available via the javax.servlet.ServletRequest methods getParameterValues() and getParameterNames().

Portlet: This must be the set of parameters available via the javax.portlet.PortletRequest methods getParameterValues() and getParameterNames().

Specified by:
getRequestParameterValuesMap in class ExternalContext

getRequestPathInfo

public java.lang.String getRequestPathInfo()

Return the extra path information (if any) included in the request URI; otherwise, return null.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletRequest method getPathInfo().

Portlet: This must be null.

Specified by:
getRequestPathInfo in class ExternalContext

getRequestServletPath

public java.lang.String getRequestServletPath()

Return the servlet path information (if any) included in the request URI; otherwise, return null.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletRequest method getServletPath().

Portlet: This must be null.

Specified by:
getRequestServletPath in class ExternalContext

getResource

public java.net.URL getResource(java.lang.String path)
                         throws java.net.MalformedURLException

Return a URL for the application resource mapped to the specified path, if it exists; otherwise, return null.

Servlet: This must be the value returned by the javax.servlet.ServletContext method getResource(path).

Portlet: This must be the value returned by the javax.portlet.PortletContext method getResource(path).

Specified by:
getResource in class ExternalContext
Parameters:
path - The path to the requested resource, which must start with a slash ("/" character
Throws:
java.net.MalformedURLException - if the specified path is not in the correct form

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String path)

Return an InputStream for an application resource mapped to the specified path, if it exists; otherwise, return null.

Servlet: This must be the value returned by the javax.servlet.ServletContext method getResourceAsStream(path).

Portlet: This must be the value returned by the javax.portlet.PortletContext method getResourceAsStream(path).

Specified by:
getResourceAsStream in class ExternalContext
Parameters:
path - The path to the requested resource, which must start with a slash ("/" character

getResourcePaths

public java.util.Set getResourcePaths(java.lang.String path)

Return the Set of resource paths for all application resources whose resource path starts with the specified argument.

Servlet: This must be the value returned by the javax.servlet.ServletContext method getResourcePaths(path).

Servlet: This must be the value returned by the javax.servlet.ServletContext method getResourcePaths(path).

Specified by:
getResourcePaths in class ExternalContext
Parameters:
path - Partial path used to match resources, which must start with a slash ("/") character

getResponse

public java.lang.Object getResponse()

Return the environment-specific object instance for the current response.

Servlet: This is the current request's javax.servlet.http.HttpServletResponse instance.

Portlet: This is the current request's javax.portlet.PortletResponse instance, which will be either an ActionResponse or a RenderResponse depending upon when this method is called.

Specified by:
getResponse in class ExternalContext

getSession

public java.lang.Object getSession(boolean create)

If the create parameter is true, create (if necessary) and return a session instance associated with the current request. If the create parameter is false return any existing session instance associated with the current request, or return null if there is no such session.

Servlet: This must return the result of calling getSession(create) on the underlying javax.servlet.http.HttpServletRequest instance.

em>Portlet: This must return the result of calling getPortletSession(create) on the underlying javax.portlet.PortletRequest instance.

Specified by:
getSession in class ExternalContext
Parameters:
create - Flag indicating whether or not a new session should be created if there is no session associated with the current request

getSessionMap

public java.util.Map getSessionMap()

Return a mutable Map representing the session scope attributes for the current application. The returned Map must implement the entire contract for a modifiable map as described in the JavaDocs for java.util.Map. Modifications made in the Map must cause the corresponding changes in the set of session scope attributes. Accessing attributes via this Map must cause the creation of a session associated with the current request, if such a session does not already exist.

Servlet: This must be the set of attributes available via the javax.servlet.http.HttpServletSession methods getAttribute(), getAttributeNames(), removeAttribute(), and setAttribute().

Portlet: This must be the set of attributes available via the javax.portlet.PortletSession methods getAttribute(), getAttributeNames(), removeAttribute(), and setAttribute(). All session attribute access must occur in PORTLET_SCOPE scope within the session.

Specified by:
getSessionMap in class ExternalContext

getUserPrincipal

public java.security.Principal getUserPrincipal()

Return the Principal object containing the name of the current authenticated user, if any; otherwise, return null.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletRequest method getUserPrincipal().

Portlet: This must be the value returned by the javax.portlet.http.PortletRequest method getUserPrincipal().

Specified by:
getUserPrincipal in class ExternalContext

isUserInRole

public boolean isUserInRole(java.lang.String role)

Return true if the currently authenticated user is included in the specified role. Otherwise, return false.

Servlet: This must be the value returned by the javax.servlet.http.HttpServletRequest method isUserInRole(role).

Portlet: This must be the value returned by the javax.portlet.http.PortletRequest method isUserInRole(role).

Specified by:
isUserInRole in class ExternalContext
Parameters:
role - Logical role name to be checked

log

public void log(java.lang.String message)

Log the specified message to the application object.

Servlet: This must be performed by calling the javax.servlet.ServletContext method log(String).

Portlet: This must be performed by calling the javax.portlet.PortletContext method log(String).

Specified by:
log in class ExternalContext
Parameters:
message - Message to be logged

log

public void log(java.lang.String message,
                java.lang.Throwable exception)

Log the specified message and exception to the application object.

Servlet: This must be performed by calling the javax.servlet.ServletContext method log(String,Throwable).

Portlet: This must be performed by calling the javax.portlet.PortletContext method log(String,Throwable).

Specified by:
log in class ExternalContext
Parameters:
message - Message to be logged
exception - Exception to be logged

redirect

public void redirect(java.lang.String url)
              throws java.io.IOException

Redirect a request to the specified URL, and cause the responseComplete() method to be called on the FacesContext instance for the current request.

Servlet: This must be accomplished by calling the javax.servlet.http.HttpServletResponse method sendRedirect().

Portlet: This must be accomplished by calling the javax.portlet.ActionResponse method sendRedirect().

Specified by:
redirect in class ExternalContext
Parameters:
url - Absolute URL to which the client should be redirected
Throws:
java.io.IOException - if an input/output error occurs

destroy

public void destroy()
             throws java.lang.Exception
Invoked by a BeanFactory on destruction of a singleton.

Specified by:
destroy in interface DisposableBean
Throws:
java.lang.Exception - in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to release their resources too.

getServletContext

protected final javax.servlet.ServletContext getServletContext()
Returns the ServletContext.

Returns:
The ServletContext

JSF-Spring

Copyright © 2006 mindmatters GmbH & Co. KG