org.appng.api.support.environment

## Class DefaultEnvironment

- java.lang.Object
- - org.appng.api.support.environment.DefaultEnvironment

- All Implemented Interfaces:
    Environment

      public class DefaultEnvironment
      extends Object
      implements Environment

  This class implements `Environment`.
  Author:
    Matthias Müller

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `DefaultEnvironment()`
    `protected` | `DefaultEnvironment(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpSession httpSession, javax.servlet.ServletRequest servletRequest)` Deprecated.
    `protected` | `DefaultEnvironment(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpSession httpSession, javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)` Deprecated. use `DefaultEnvironment(ServletRequest, ServletResponse)` instead.
    `` | `DefaultEnvironment(javax.servlet.ServletContext context, String host)` Deprecated. use `get(ServletContext)` instead
    `` | `DefaultEnvironment(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearSiteScope(Site site)` Clears the site-scoped attributes for the given `Site`.
    `void` | `disable(Scope scope)` Disables the given `Scope` for this environment
    `void` | `enable(Scope scope)` Enables the given `Scope` for this environment
    `static DefaultEnvironment` | `get(javax.servlet.http.HttpSession session)` Returns a new `DefaultEnvironment`.
    `static DefaultEnvironment` | `get(javax.servlet.jsp.PageContext pageContext)` Returns a fully initialized DefaultEnvironment.
    `static DefaultEnvironment` | `get(javax.servlet.ServletContext context)` Returns a new `DefaultEnvironment`.
    `static DefaultEnvironment` | `get(javax.servlet.ServletContext context, javax.servlet.ServletRequest request)` Deprecated. use `get(ServletRequest, ServletResponse)` instead!
    `static DefaultEnvironment` | `get(javax.servlet.ServletContext context, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)` Deprecated. use `get(ServletRequest, ServletResponse)` instead!
    `static DefaultEnvironment` | `get(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)` Returns a fully initialized DefaultEnvironment.
    `<T> T` | `getAttribute(Scope scope, String name)` Returns the attribute with the given name for the given `Scope`.
    `String` | `getAttributeAsString(Scope scope, String name)` Returns the string-representation of an attribute, calling `toString()` on the resulting object.
    `ScopedEnvironment` | `getEnvironment(Scope scope)` Returns a `ScopedEnvironment` for the given `Scope`
    `static DefaultEnvironment` | `getGlobal()`
    `Locale` | `getLocale()` Returns the current `Locale`.
    `javax.servlet.ServletContext` | `getServletContext()` Returns the current `ServletContext`.
    `javax.servlet.http.HttpServletRequest` | `getServletRequest()` Returns the current `HttpServletRequest`.
    `javax.servlet.http.HttpServletResponse` | `getServletResponse()` Returns the current `HttpServletResponse`.
    `Map<String,Object>` | `getSession()`
    `Site` | `getSite()` Returns the current `Site`, if this environment has been created from a `HttpServletRequest`
    `Subject` | `getSubject()` Returns the current `Subject`.
    `TimeZone` | `getTimeZone()` Returns the current `TimeZone`.
    `void` | `init(javax.servlet.ServletContext context, javax.servlet.http.HttpSession session, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, String host)` Deprecated. use `init(ServletContext, ServletRequest, ServletResponse)` instead.
    `void` | `init(javax.servlet.ServletContext servletContext, javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)`
    `static DefaultEnvironment` | `initGlobal(javax.servlet.ServletContext ctx)`
    `void` | `initSiteScope(Site site)`
    `boolean` | `isInitialized()` Checks whether this `Environment` has been initialized.
    `boolean` | `isSubjectAuthenticated()` Returns `true` if the current `Subject` is authenticated, `false` otherwise
    `Set<String>` | `keySet(Scope scope)` Returns a `Set` of all attribute names for the given `Scope`
    `void` | `logoutSubject()` Removes the current `Subject` form the `HttpSession` and invalidates the latter.
    `<T> T` | `removeAttribute(Scope scope, String name)` Removes the attribute with the given name from the given `Scope` and returns it.
    `void` | `setAttribute(Scope scope, String name, Object value)` Sets an attribute for the given `Scope` to the given value.
    `void` | `setLocale(Locale locale)`
    `void` | `setSubject(Subject subject)` Sets the `Subject` fur the current `HttpSession`.
    `void` | `setTimeZone(TimeZone timeZone)`
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### DefaultEnvironment

          protected DefaultEnvironment()

    - #### DefaultEnvironment

          @Deprecated
          protected DefaultEnvironment(javax.servlet.ServletContext servletContext,
                                                   javax.servlet.http.HttpSession httpSession,
                                                   javax.servlet.ServletRequest servletRequest)

      Deprecated.

    - #### DefaultEnvironment

          @Deprecated
          protected DefaultEnvironment(javax.servlet.ServletContext servletContext,
                                                   javax.servlet.http.HttpSession httpSession,
                                                   javax.servlet.ServletRequest servletRequest,
                                                   javax.servlet.ServletResponse servletResponse)

      Deprecated. use `DefaultEnvironment(ServletRequest, ServletResponse)` instead.

    - #### DefaultEnvironment

          @Deprecated
          public DefaultEnvironment(javax.servlet.ServletContext context,
                                                String host)

      Deprecated. use `get(ServletContext)` instead
      Returns a fully initialized DefaultEnvironment.
      Parameters:
        `context` - a `ServletContext`
        `host` - the host for the site-`Scope`

    - #### DefaultEnvironment

          public DefaultEnvironment(javax.servlet.ServletRequest servletRequest,
                                    javax.servlet.ServletResponse servletResponse)

  - ### Method Detail

    - #### initGlobal

          public static DefaultEnvironment initGlobal(javax.servlet.ServletContext ctx)

    - #### getGlobal

          public static DefaultEnvironment getGlobal()

    - #### init

          @Deprecated
          public void init(javax.servlet.ServletContext context,
                                       javax.servlet.http.HttpSession session,
                                       javax.servlet.ServletRequest request,
                                       javax.servlet.ServletResponse response,
                                       String host)

      Deprecated. use `init(ServletContext, ServletRequest, ServletResponse)` instead.
      Initializes the environment
      Specified by:
        `init` in interface `Environment`
      Parameters:
        `context` - a `ServletContext`
        `session` - a `HttpSession`
        `request` - a `ServletRequest`
        `response` - a `ServletResponse`
        `host` - the host for the site-`Scope`

    - #### init

          public void init(javax.servlet.ServletContext servletContext,
                           javax.servlet.ServletRequest servletRequest,
                           javax.servlet.ServletResponse servletResponse)

    - #### get

          public static DefaultEnvironment get(javax.servlet.jsp.PageContext pageContext)

      Returns a fully initialized DefaultEnvironment.
      Parameters:
        `pageContext` - a `PageContext`

    - #### get

          public static DefaultEnvironment get(javax.servlet.http.HttpSession session)

      Returns a new `DefaultEnvironment`. Only `Scope.PLATFORM` and `Scope.SESSION` will be available for the returned instance.
      Parameters:
        `session` - a `HttpSession`
      Returns:
        a new `DefaultEnvironment`

    - #### get

          @Deprecated
          public static DefaultEnvironment get(javax.servlet.ServletContext context,
                                                           javax.servlet.ServletRequest request)

      Deprecated. use `get(ServletRequest, ServletResponse)` instead!
      Returns a fully initialized DefaultEnvironment.
      Parameters:
        `context` - a `ServletContext`
        `request` - a `ServletRequest`
      Returns:
        a new `DefaultEnvironment`

    - #### get

          public static DefaultEnvironment get(javax.servlet.ServletRequest request,
                                               javax.servlet.ServletResponse response)

      Returns a fully initialized DefaultEnvironment.
      Parameters:
        `request` - a `ServletRequest`
        `response` - a `ServletResponse`
      Returns:
        a new `DefaultEnvironment`

    - #### get

          @Deprecated
          public static DefaultEnvironment get(javax.servlet.ServletContext context,
                                                           javax.servlet.ServletRequest request,
                                                           javax.servlet.ServletResponse response)

      Deprecated. use `get(ServletRequest, ServletResponse)` instead!
      Returns a fully initialized DefaultEnvironment.
      Parameters:
        `context` - a `ServletContext`
        `request` - a `ServletRequest`
        `response` - a `ServletResponse`
      Returns:
        a new `DefaultEnvironment`

    - #### get

          public static DefaultEnvironment get(javax.servlet.ServletContext context)

      Returns a new `DefaultEnvironment`. Only `Scope.PLATFORM` will be available for the returned instance.
      Parameters:
        `context` - a `ServletContext`
      Returns:
        a new `DefaultEnvironment`

    - #### setAttribute

          public void setAttribute(Scope scope,
                                   String name,
                                   Object value)

      Description copied from interface: `Environment`
      Sets an attribute for the given `Scope` to the given value.
      Specified by:
        `setAttribute` in interface `Environment`
      Parameters:
        `scope` - the `Scope` of the attribute to set
        `name` - the name of the attribute to set
        `value` - the attribute to set

    - #### getAttribute

          public <T> T getAttribute(Scope scope,
                                    String name)

      Description copied from interface: `Environment`
      Returns the attribute with the given name for the given `Scope`.
      Specified by:
        `getAttribute` in interface `Environment`
      Parameters:
        `scope` - the `Scope` of the attribute to get
        `name` - the name of the attribute to get
      Returns:
        the attribute of the desired type, or `null` if the attribute does not exist in the given `Scope`

    - #### removeAttribute

          public <T> T removeAttribute(Scope scope,
                                       String name)

      Description copied from interface: `Environment`
      Removes the attribute with the given name from the given `Scope` and returns it.
      Specified by:
        `removeAttribute` in interface `Environment`
      Parameters:
        `scope` - the `Scope` of the attribute to remove
        `name` - the name of the attribute to remove
      Returns:
        the attribute of the desired type, or `null` if the attribute does not exist in the given `Scope`

    - #### getAttributeAsString

          public String getAttributeAsString(Scope scope,
                                             String name)

      Description copied from interface: `Environment`
      Returns the string-representation of an attribute, calling `toString()` on the resulting object.
      Specified by:
        `getAttributeAsString` in interface `Environment`
      Parameters:
        `scope` - the `Scope` of the attribute to get
        `name` - the name of the attribute to get
      Returns:
        the string-representation of the attribute, or `null` if the attribute does not exist in the given `Scope`

    - #### getEnvironment

          public ScopedEnvironment getEnvironment(Scope scope)

      Description copied from interface: `Environment`
      Returns a `ScopedEnvironment` for the given `Scope`
      Specified by:
        `getEnvironment` in interface `Environment`
      Parameters:
        `scope` - the `Scope` to use
      Returns:
        the `ScopedEnvironment`, if scope is available, `null` otherwise.

    - #### keySet

          public Set<String> keySet(Scope scope)

      Description copied from interface: `Environment`
      Returns a `Set` of all attribute names for the given `Scope`
      Specified by:
        `keySet` in interface `Environment`
      Parameters:
        `scope` - the `Scope` the get the attribute names for
      Returns:
        a `Set` containing all attribute names, or `null` if the `Scope` is not available

    - #### getServletContext

          public javax.servlet.ServletContext getServletContext()

      Returns the current `ServletContext`.
      Returns:
        the `ServletContext`

    - #### getServletRequest

          public javax.servlet.http.HttpServletRequest getServletRequest()

      Returns the current `HttpServletRequest`.
      Returns:
        the `HttpServletRequest`

    - #### getServletResponse

          public javax.servlet.http.HttpServletResponse getServletResponse()

      Returns the current `HttpServletResponse`.
      Returns:
        the `HttpServletResponse`

    - #### getSession

          public Map<String,Object> getSession()

    - #### isSubjectAuthenticated

          public boolean isSubjectAuthenticated()

      Description copied from interface: `Environment`
      Returns `true` if the current `Subject` is authenticated, `false` otherwise
      Specified by:
        `isSubjectAuthenticated` in interface `Environment`
      Returns:
        `true` if the current `Subject` is authenticated, `false` otherwise

    - #### setSubject

          public void setSubject(Subject subject)

      Sets the `Subject` fur the current `HttpSession`.
      Parameters:
        `subject` - the `Subject` to set

    - #### getLocale

          public Locale getLocale()

      Description copied from interface: `Environment`
      Returns the current `Locale`. If a `Subject` is logged in, a `Locale` is returned that represent the language of the `Subject` via `Account.getLanguage()`. If no `Subject` is present, the default-`Locale` from the `Site` is used.
      Specified by:
        `getLocale` in interface `Environment`
      Returns:
        the `Locale`

    - #### setLocale

          public void setLocale(Locale locale)

    - #### getTimeZone

          public TimeZone getTimeZone()

      Description copied from interface: `Environment`
      Returns the current `TimeZone`. If a `Subject` is present (no matter whether it is logged in or not), `Account.getTimeZone()` is being returned. If no `Subject` is present, the default-`TimeZone` from the `Site` is used.
      Specified by:
        `getTimeZone` in interface `Environment`
      Returns:
        the `TimeZone`

    - #### setTimeZone

          public void setTimeZone(TimeZone timeZone)

    - #### getSite

          public Site getSite()

      Description copied from interface: `Environment`
      Returns the current `Site`, if this environment has been created from a `HttpServletRequest`
      Specified by:
        `getSite` in interface `Environment`
      Returns:
        the site

    - #### getSubject

          public Subject getSubject()

      Description copied from interface: `Environment`
      Returns the current `Subject`.
      Specified by:
        `getSubject` in interface `Environment`
      Returns:
        the `Subject`, if present

    - #### logoutSubject

          public void logoutSubject()

      Removes the current `Subject` form the `HttpSession` and invalidates the latter.

    - #### disable

          public void disable(Scope scope)

      Disables the given `Scope` for this environment
      Parameters:
        `scope` - the `Scope` to disable
      See Also:
        `enable(Scope)`

    - #### enable

          public void enable(Scope scope)

      Enables the given `Scope` for this environment
      Parameters:
        `scope` - the `Scope` to enable
      See Also:
        `disable(Scope)`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### isInitialized

          public boolean isInitialized()

      Checks whether this `Environment` has been initialized.
      Returns:
        `true` if his `Environment` has been initialized, `false` otherwise.
      See Also:
        `init(ServletContext, HttpSession, ServletRequest, ServletResponse, String)`

    - #### initSiteScope

          public void initSiteScope(Site site)

    - #### clearSiteScope

          public void clearSiteScope(Site site)

      Clears the site-scoped attributes for the given `Site`.
      Parameters:
        `site` - The `Site` to clear the site-scope for.

Copyright © 2011–2023 aiticon GmbH. All rights reserved.