org.apache.myfaces.trinidad.util

## Class ExternalContextUtils

- java.lang.Object
- - org.apache.myfaces.trinidad.util.ExternalContextUtils

-     public final class ExternalContextUtils
      extends Object

  This provides some functionality for determining some things about the native request object that is not provided by the base utils.
  Version:
    2.0

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `getCharacterEncoding(javax.faces.context.ExternalContext ec)` Deprecated. replaced by an API in JSF. Use ExternalContext.getRequestCharacterEncoding()
    `static int` | `getContentLength(javax.faces.context.ExternalContext ec)` Returns the content length or -1 if the unknown.
    `static String` | `getContentType(javax.faces.context.ExternalContext ec)` Deprecated. use ExternalContext.getRequestContentType()
    `static String` | `getContextName(javax.faces.context.ExternalContext ec)` Returns the name of the underlying context or `null` if something went wrong in trying to retrieve the context.
    `static String` | `getRequestContextPath(javax.faces.context.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(javax.faces.context.ExternalContext ec)` Returns the session ID for the client, or `null` if there is none.
    `static InputStream` | `getRequestInputStream(javax.faces.context.ExternalContext ec)` Returns the request input stream if one is available
    `static String` | `getRequestScheme(javax.faces.context.ExternalContext ec)` Returns the scheme of the current request, or "unknown" if the request scheme cannot be determined.
    `static RequestType` | `getRequestType(javax.faces.context.ExternalContext ec)` Returns the requestType of this ExternalContext.
    `static String` | `getRequestURI(javax.faces.context.ExternalContext ec)` Returns the requestURI of the HttpServletRequest or `null` for portlet requests
    `static Writer` | `getResponseWriter(javax.faces.context.ExternalContext ec)` Returns the writer appropriate for the current response or `null` if one is not available.
    `static String` | `getServerInfo(javax.faces.context.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(javax.faces.context.ExternalContext ec)` Returns the contextPath of the ServletContext or `null` for portlets
    `static String` | `getSessionId(javax.faces.context.ExternalContext ec)` Returns the current active session id or `null` if there is none.
    `static String` | `getSessionId(javax.faces.context.ExternalContext ec, boolean create)` Returns the current active session id or `null` if there is none.
    `static boolean` | `isAction(javax.faces.context.ExternalContext ec)` Deprecated. replaced with `isRequestFromClient(ExternalContext)`
    `static boolean` | `isHttpServletRequest(javax.faces.context.ExternalContext ec)` Returns wherther of not this external context represents a true HttpServletRequest or not.
    `static boolean` | `isPortlet(javax.faces.context.ExternalContext ec)` Returns the value of `RequestType.isPortlet()` for the current RequestType.
    `static boolean` | `isRequestedSessionIdValid(javax.faces.context.ExternalContext ec)` Checks if the requested session ID is still valid.
    `static boolean` | `isRequestFromClient(javax.faces.context.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(javax.faces.context.ExternalContext ec)` Returns the value of `RequestType.isResponseWritable()` for the current RequestType.
    `static boolean` | `isSecure(javax.faces.context.ExternalContext ec)` Provides access to `ServletRequest.isSecure()` or `PortletRequest.isSecure()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### isRequestTypeAvailable

          public static final 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. 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.
      Parameters:
        `type` - the RequestType to test
      Returns:
        a boolean value of `true` if the container contains the request type in the classpath
      Since:
        2.0

    - #### isRequestTypeSupported

          public static final boolean isRequestTypeSupported(RequestType type)

      Returns `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.
      Parameters:
        `type` - the RequestType to test
      Returns:
        a boolean value of `true` if the container supports the current request type
      Since:
        2.0

    - #### getRequestType

          public static final RequestType getRequestType(javax.faces.context.ExternalContext ec)

      Returns the requestType of this ExternalContext.
      Parameters:
        `ec` - the current external context
      Returns:
        the appropriate RequestType for this external context
      Since:
        2.0
      See Also:
        `RequestType`

    - #### getSessionId

          public static String getSessionId(javax.faces.context.ExternalContext ec)

      Returns the current active session id or `null` if there is none. If a session is not already created, this method will create one for you.
      Parameters:
        `ec` - the current external context
      Returns:
        a string containing the requestedSessionId

    - #### getSessionId

          public static String getSessionId(javax.faces.context.ExternalContext ec,
                            boolean create)

      Returns the current active session id or `null` if there is none.
      Parameters:
        `ec` - the current external context
        `create` - create a new session if one is not created
      Returns:
        a string containing the requestedSessionId

    - #### getRequestedSessionId

          public static String getRequestedSessionId(javax.faces.context.ExternalContext ec)

      Returns the session ID for the client, or `null` if there is none.
      Parameters:
        `ec` - the current external context
      Returns:
        a string containing the requestedSessionId

    - #### isRequestedSessionIdValid

          public static boolean isRequestedSessionIdValid(javax.faces.context.ExternalContext ec)

      Checks if the requested session ID is still valid.
      Parameters:
        `ec` - the current external context
      Returns:
        a boolean containing `true` if the request session is valid or `false` if it is not

    - #### getServletContextPath

          public static String getServletContextPath(javax.faces.context.ExternalContext ec)

      Returns the contextPath of the ServletContext or `null` for portlets
      Parameters:
        `ec` - the current external context
      Returns:
        a String containing the servletContextPath

    - #### getRequestContextPath

          @Deprecated
          public static String getRequestContextPath(javax.faces.context.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.
      Returns the contextPath of the ServletRequest or `null` for portlet requests
      Parameters:
        `ec` - the current external context
      Returns:
        a String containing the request context path
      See Also:
        `ExternalContext.getRequestContextPath()`

    - #### getRequestURI

          public static String getRequestURI(javax.faces.context.ExternalContext ec)

      Returns the requestURI of the HttpServletRequest or `null` for portlet requests
      Parameters:
        `ec` - the current external context
      Returns:
        A string containing the current request uri

    - #### getResponseWriter

          public static Writer getResponseWriter(javax.faces.context.ExternalContext ec)
                                          throws IOException

      Returns the writer appropriate for the current response or `null` if one is not available. This will always be available in a servlet request, but will only be available for resource or render responses in a portal environments
      Parameters:
        `ec` - the current externalContext
      Returns:
        a writer appropriate for the current response
      Throws:
        `IOException`

    - #### getRequestScheme

          public static String getRequestScheme(javax.faces.context.ExternalContext ec)

      Returns the scheme of the current request, or "unknown" if the request scheme cannot be determined.
      Parameters:
        `ec` - the current external context
      Returns:
        A string containing the current request scheme, or "unknown".

    - #### getCharacterEncoding

          @Deprecated
          public static String getCharacterEncoding(javax.faces.context.ExternalContext ec)

      Deprecated. replaced by an API in JSF. Use ExternalContext.getRequestCharacterEncoding()
      Returns the character encoding or `null` if there isn't any
      Parameters:
        `ec` - the current external context
      Returns:
        a string containing the request's character encoding
      See Also:
        `ExternalContext.getRequestCharacterEncoding()`

    - #### getContextName

          public static String getContextName(javax.faces.context.ExternalContext ec)

      Returns the name of the underlying context or `null` if something went wrong in trying to retrieve the context.
      Parameters:
        `ec` - the current external context
      Returns:
        a String containing the context name

    - #### getServerInfo

          public static String getServerInfo(javax.faces.context.ExternalContext ec)

      Returns the name and version of the underlying servlet container or `null` if something went wrong in trying to retrieve the context.
      Parameters:
        `ec` - the current external context
      Returns:
        a String containing the name and version of the underlying servlet container

    - #### getContentLength

          public static int getContentLength(javax.faces.context.ExternalContext ec)

      Returns the content length or -1 if the unknown.
      Parameters:
        `ec` - the current external context
      Returns:
        the length or -1 if the length is unknown

    - #### getContentType

          @Deprecated
          public static String getContentType(javax.faces.context.ExternalContext ec)

      Deprecated. use ExternalContext.getRequestContentType()
      Returns the content type from the current externalContext or `null` if unknown.
      Parameters:
        `ec` - the current external context
      Returns:
        a String contining the the content type or `null`
      See Also:
        `ExternalContext.getRequestContentType()`

    - #### getRequestInputStream

          public static InputStream getRequestInputStream(javax.faces.context.ExternalContext ec)
                                                   throws IOException

      Returns the request input stream if one is available
      Parameters:
        `ec` - the current external context
      Returns:
        the request's input stream
      Throws:
        `IOException` - if there was a problem getting the input stream

    - #### isAction

          @Deprecated
          public static boolean isAction(javax.faces.context.ExternalContext ec)

      Deprecated. replaced with `isRequestFromClient(ExternalContext)`
      Returns `true` if this externalContext represents an "action". An action request is any ServletRequest or a portlet ActionRequest or ResourceRequest.
      Parameters:
        `ec` - the current external context
      Returns:
        a boolean of `true` if this request is an action-type request.
      See Also:
        `isRequestFromClient(ExternalContext)`

    - #### isPortlet

          public static boolean isPortlet(javax.faces.context.ExternalContext ec)

      Returns the value of `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.
      Parameters:
        `ec` - the current external context
      Returns:
        a boolean value of `true` if the current RequestType is a portlet request.
      See Also:
        `RequestType.isPortlet()`, `getRequestType(ExternalContext)`

    - #### isResponseWritable

          public static final boolean isResponseWritable(javax.faces.context.ExternalContext ec)

      Returns the value of `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.
      Parameters:
        `ec` - the current external context
      Returns:
        a boolean value of `true` if the current RequestType is a "render" type response.
      Since:
        2.0
      See Also:
        `RequestType.isResponseWritable()`, `getRequestType(ExternalContext)`

    - #### isRequestFromClient

          public static final boolean isRequestFromClient(javax.faces.context.ExternalContext ec)

      Returns the value of `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.
      Parameters:
        `ec` - the current external context
      Returns:
        a boolean value of `true` if the current RequestType represents a request from the client.
      Since:
        2.0
      See Also:
        `RequestType.isResponseWritable()`, `getRequestType(ExternalContext)`

    - #### isHttpServletRequest

          public static boolean isHttpServletRequest(javax.faces.context.ExternalContext ec)

      Returns wherther of not this external context represents a true HttpServletRequest or not. Some portal containers implement the PortletRequest/Response objects as HttpServletRequestWrappers, and those objects should not be treated as an HttpServlerRequest. As such, this method first tests to see if the request is a portlet request and, if not, then tests to see if the request is an instanceof HttpServletRequest.
      Parameters:
        `ec` - the current external context
      Returns:
        a boolean value of `true` if the current request is an HttpServletRequest
      Since:
        1.1

    - #### isSecure

          public static boolean isSecure(javax.faces.context.ExternalContext ec)

      Provides access to `ServletRequest.isSecure()` or `PortletRequest.isSecure()`
      Parameters:
        `ec` -
      Returns:

Copyright © 2001-2016 The Apache Software Foundation. All Rights Reserved.