public final class ExternalContextUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
getCharacterEncoding(ExternalContext ec)
Deprecated.
replaced by an API in JSF. Use ExternalContext.getRequestCharacterEncoding()
|
static int |
getContentLength(ExternalContext ec)
Returns the content length or -1 if the unknown.
|
static String |
getContentType(ExternalContext ec)
Deprecated.
use ExternalContext.getRequestContentType()
|
static String |
getContextName(ExternalContext ec)
Returns the name of the underlying context or
null if something
went wrong in trying to retrieve the context. |
static javax.servlet.http.HttpServletResponse |
getHttpServletResponse(ExternalContext ec)
Returns an HttpServletResponse if one exists on the externalContext or null
if it does not.
|
static javax.servlet.http.HttpServletResponse |
getHttpServletResponse(Object response)
Trys to obtain a HttpServletResponse from the Response.
|
static String |
getRequestContextPath(ExternalContext ec)
Deprecated.
use ExternalContext.getRequestContextPath() as of JSF 1.2. This method
does not appropriately handle portlet environments, but the functionality
is maintained to prevent needing to change the contract.
|
static String |
getRequestedSessionId(ExternalContext ec)
Returns the session ID for the client, or
null if there is none. |
static InputStream |
getRequestInputStream(ExternalContext ec)
Returns the request input stream if one is available
|
static RequestType |
getRequestType(ExternalContext externalContext)
Returns the requestType of this ExternalContext.
|
static RequestType |
getRequestType(Object context,
Object request)
This method is used when a ExternalContext object is not available,
like in TomahawkFacesContextFactory.
|
static String |
getRequestURI(ExternalContext ec)
Returns the requestURI of the HttpServletRequest or
null for
portlet requests |
static String |
getServerInfo(ExternalContext ec)
Returns the name and version of the underlying servlet container or
null if something
went wrong in trying to retrieve the context. |
static String |
getServletContextPath(ExternalContext ec)
Returns the contextPath of the ServletContext or
null for portlets |
static String |
getSessionId(ExternalContext ec)
Returns the current active session id or
null if there is
none. |
static String |
getSessionId(ExternalContext ec,
boolean create)
Returns the current active session id or
null if there is
none. |
static boolean |
isAction(ExternalContext ec)
Deprecated.
replaced with
isRequestFromClient(ExternalContext) |
static boolean |
isHttpServletRequest(ExternalContext ec)
Returns wherther of not this external context represents a true HttpServletRequest or
not.
|
static boolean |
isPortlet(ExternalContext ec)
Returns the value of
RequestType.isPortlet() for the current
RequestType. |
static boolean |
isRequestedSessionIdValid(ExternalContext ec)
Checks if the requested session ID is still valid.
|
static boolean |
isRequestFromClient(ExternalContext ec)
Returns the value of
RequestType.isRequestFromClient() for the
current RequestType. |
static boolean |
isRequestTypeAvailable(RequestType type)
Returns
true if a particular class relating to the supplied
request type is available on the current classpath or false
if it is not. |
static boolean |
isRequestTypeSupported(RequestType type)
Returns
true if a particular request type is supported by the
container. |
static boolean |
isResponseWritable(ExternalContext ec)
Returns the value of
RequestType.isResponseWritable() for the
current RequestType. |
public static final boolean isRequestTypeAvailable(RequestType type)
true
if a particular class relating to the supplied
request type is available on the current classpath or false
if it is not. This class assumes that all containers have a servlet type
request available, but the portlet request types are all dependant on the
portlet container being used.type
- the RequestType to testtrue
if the container contains the
request type in the classpathpublic static final boolean isRequestTypeSupported(RequestType type)
true
if a particular request type is supported by the
container. For a request type to be supported, the required objects must
be on the classpath AND and, in the case of Portlet RequestTypes, an
appropriate bridge must be avaialble which supports those objects. This
means that if the supplied RequestType is RESOURCE, the
javax.portlet.ResourceRequest object must be available on the classpath AND
a bridge which supports the Portlet 2.0 specification would also need to be
available.type
- the RequestType to testtrue
if the container supports the
current request typepublic static final RequestType getRequestType(ExternalContext externalContext)
externalContext
- the current external contextRequestType
public static final RequestType getRequestType(Object context, Object request)
context
- request
- public static String getSessionId(ExternalContext ec)
null
if there is
none. If a session is not already created, this method will create one
for you.ec
- the current external contextpublic static String getSessionId(ExternalContext ec, boolean create)
null
if there is
none.ec
- the current external contextcreate
- create a new session if one is not createdpublic static String getRequestedSessionId(ExternalContext ec)
null
if there is none.ec
- the current external contextpublic static boolean isRequestedSessionIdValid(ExternalContext ec)
ec
- the current external contexttrue
if the request session is
valid or false
if it is notpublic static String getServletContextPath(ExternalContext ec)
null
for portletsec
- the current external context@Deprecated public static String getRequestContextPath(ExternalContext ec)
null
for portlet requestsec
- the current external contextExternalContext.getRequestContextPath()
public static String getRequestURI(ExternalContext ec)
null
for
portlet requestsec
- the current external context@Deprecated public static String getCharacterEncoding(ExternalContext ec)
null
if there isn't anyec
- the current external contextExternalContext.getRequestCharacterEncoding()
public static String getContextName(ExternalContext ec)
null
if something
went wrong in trying to retrieve the context.ec
- the current external contextpublic static String getServerInfo(ExternalContext ec)
null
if something
went wrong in trying to retrieve the context.ec
- the current external contextpublic static int getContentLength(ExternalContext ec)
ec
- the current external context@Deprecated public static String getContentType(ExternalContext ec)
null
if unknown.ec
- the current external contextnull
ExternalContext.getRequestContentType()
public static InputStream getRequestInputStream(ExternalContext ec) throws IOException
ec
- the current external contextIOException
- if there was a problem getting the input stream@Deprecated public static boolean isAction(ExternalContext ec)
isRequestFromClient(ExternalContext)
true
if this externalContext represents an "action".
An action request is any ServletRequest or a portlet ActionRequest or
ResourceRequest.ec
- the current external contexttrue
if this request is an action-type
request.isRequestFromClient(ExternalContext)
public static boolean isPortlet(ExternalContext ec)
RequestType.isPortlet()
for the current
RequestType. This is a convenience function designed to perform a quick
check of the current request. If more capabilities need to be tested for
the given request, then it is more efficient to pull this information from
the RequestType itself.ec
- the current external contexttrue
if the current RequestType
is a portlet request.RequestType.isPortlet()
,
getRequestType(ExternalContext)
public static final boolean isResponseWritable(ExternalContext ec)
RequestType.isResponseWritable()
for the
current RequestType. This is a convenience function designed to perform a
quick check of the current request. If more capabilities need to be tested
for the given request, then it is more efficient to pull this information
from the RequestType itself.ec
- the current external contexttrue
if the current RequestType
is a "render" type response.RequestType.isResponseWritable()
,
getRequestType(ExternalContext)
public static final boolean isRequestFromClient(ExternalContext ec)
RequestType.isRequestFromClient()
for the
current RequestType. This is a convenience function designed to perform a
quick check of the current request. If more capabilities need to be tested
for the given request, then it is more efficient to pull this information
from the RequestType itself.ec
- the current external contexttrue
if the current RequestType
represents a request from the client.RequestType.isResponseWritable()
,
getRequestType(ExternalContext)
public static boolean isHttpServletRequest(ExternalContext ec)
ec
- the current external contexttrue
if the current request is an
HttpServletRequestpublic static javax.servlet.http.HttpServletResponse getHttpServletResponse(ExternalContext ec)
ec
- public static javax.servlet.http.HttpServletResponse getHttpServletResponse(Object response)
response
- Copyright © 2020 The Apache Software Foundation. All rights reserved.