Class DefaultEnvironment
- java.lang.Object
-
- org.appng.api.support.environment.DefaultEnvironment
-
- All Implemented Interfaces:
Environment
public class DefaultEnvironment extends Object implements Environment
This class implementsEnvironment
.- Author:
- Matthias Müller
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultEnvironment()
DefaultEnvironment(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearSiteScope(Site site)
Clears the site-scoped attributes for the givenSite
.void
disable(Scope scope)
Disables the givenScope
for this environmentvoid
enable(Scope scope)
Enables the givenScope
for this environmentstatic DefaultEnvironment
get(javax.servlet.http.HttpSession session)
Returns a newDefaultEnvironment
.static DefaultEnvironment
get(javax.servlet.jsp.PageContext pageContext)
Returns a fully initialized DefaultEnvironment.static DefaultEnvironment
get(javax.servlet.ServletContext context)
Returns a newDefaultEnvironment
.static DefaultEnvironment
get(javax.servlet.ServletContext context, javax.servlet.ServletRequest request)
Returns a fully initialized DefaultEnvironment.static DefaultEnvironment
get(javax.servlet.ServletContext context, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
Returns a fully initialized DefaultEnvironment.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 givenScope
.String
getAttributeAsString(Scope scope, String name)
Returns the string-representation of an attribute, callingtoString()
on the resulting object.Locale
getLocale()
Returns the currentLocale
.javax.servlet.ServletContext
getServletContext()
Returns the currentServletContext
.javax.servlet.http.HttpServletRequest
getServletRequest()
Returns the currentHttpServletRequest
.javax.servlet.http.HttpServletResponse
getServletResponse()
Returns the currentHttpServletResponse
.Map<String,Object>
getSession()
Subject
getSubject()
Returns the currentSubject
.TimeZone
getTimeZone()
Returns the currentTimeZone
.void
init(javax.servlet.ServletContext servletContext, javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
boolean
isInitialized()
Checks whether thisEnvironment
has been initialized.boolean
isSubjectAuthenticated()
Set<String>
keySet(Scope scope)
void
logoutSubject()
Removes the currentSubject
form theHttpSession
and invalidates the latter.<T> T
removeAttribute(Scope scope, String name)
Removes the attribute with the given name from the givenScope
and returns it.void
setAttribute(Scope scope, String name, Object value)
Sets an attribute for the givenScope
to the given value.void
setLocale(Locale locale)
void
setSubject(Subject subject)
Sets theSubject
fur the currentHttpSession
.void
setTimeZone(TimeZone timeZone)
String
toString()
-
-
-
Method Detail
-
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
- aPageContext
-
get
public static DefaultEnvironment get(javax.servlet.http.HttpSession session)
Returns a newDefaultEnvironment
. OnlyScope.PLATFORM
andScope.SESSION
will be available for the returned instance.- Parameters:
session
- aHttpSession
- Returns:
- a new
DefaultEnvironment
-
get
public static DefaultEnvironment get(javax.servlet.ServletContext context, javax.servlet.ServletRequest request)
Returns a fully initialized DefaultEnvironment.- Parameters:
context
- aServletContext
request
- aServletRequest
- Returns:
- a new
DefaultEnvironment
-
get
public static DefaultEnvironment get(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
Returns a fully initialized DefaultEnvironment.- Parameters:
request
- aServletRequest
response
- aServletResponse
- Returns:
- a new
DefaultEnvironment
-
get
public static DefaultEnvironment get(javax.servlet.ServletContext context, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
Returns a fully initialized DefaultEnvironment.- Parameters:
context
- aServletContext
request
- aServletRequest
response
- aServletResponse
- Returns:
- a new
DefaultEnvironment
-
get
public static DefaultEnvironment get(javax.servlet.ServletContext context)
Returns a newDefaultEnvironment
. OnlyScope.PLATFORM
will be available for the returned instance.- Parameters:
context
- aServletContext
- Returns:
- a new
DefaultEnvironment
-
setAttribute
public void setAttribute(Scope scope, String name, Object value)
Description copied from interface:Environment
Sets an attribute for the givenScope
to the given value.- Specified by:
setAttribute
in interfaceEnvironment
- Parameters:
scope
- theScope
of the attribute to setname
- the name of the attribute to setvalue
- 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 givenScope
.- Specified by:
getAttribute
in interfaceEnvironment
- Parameters:
scope
- theScope
of the attribute to getname
- the name of the attribute to get- Returns:
- the attribute of the desired type, or
null
if the attribute does not exist in the givenScope
-
removeAttribute
public <T> T removeAttribute(Scope scope, String name)
Description copied from interface:Environment
Removes the attribute with the given name from the givenScope
and returns it.- Specified by:
removeAttribute
in interfaceEnvironment
- Parameters:
scope
- theScope
of the attribute to removename
- the name of the attribute to remove- Returns:
- the attribute of the desired type, or
null
if the attribute does not exist in the givenScope
-
getAttributeAsString
public String getAttributeAsString(Scope scope, String name)
Description copied from interface:Environment
Returns the string-representation of an attribute, callingtoString()
on the resulting object.- Specified by:
getAttributeAsString
in interfaceEnvironment
- Parameters:
scope
- theScope
of the attribute to getname
- the name of the attribute to get- Returns:
- the string-representation of the attribute, or
null
if the attribute does not exist in the givenScope
-
keySet
public Set<String> keySet(Scope scope)
Description copied from interface:Environment
- Specified by:
keySet
in interfaceEnvironment
- Parameters:
scope
- theScope
the get the attribute names for- Returns:
- a
Set
containing all attribute names, ornull
if theScope
is not available
-
getServletContext
public javax.servlet.ServletContext getServletContext()
Returns the currentServletContext
.- Returns:
- the
ServletContext
-
getServletRequest
public javax.servlet.http.HttpServletRequest getServletRequest()
Returns the currentHttpServletRequest
.- Returns:
- the
HttpServletRequest
-
getServletResponse
public javax.servlet.http.HttpServletResponse getServletResponse()
Returns the currentHttpServletResponse
.- Returns:
- the
HttpServletResponse
-
isSubjectAuthenticated
public boolean isSubjectAuthenticated()
Description copied from interface:Environment
- Specified by:
isSubjectAuthenticated
in interfaceEnvironment
- Returns:
true
if the currentSubject
is authenticated,false
otherwise
-
setSubject
public void setSubject(Subject subject)
Sets theSubject
fur the currentHttpSession
.- Parameters:
subject
- theSubject
to set
-
getLocale
public Locale getLocale()
Description copied from interface:Environment
Returns the currentLocale
. If aSubject
is logged in, aLocale
is returned that represent the language of theSubject
viaAccount.getLanguage()
. If noSubject
is present, the default-Locale
from theSite
is used.- Specified by:
getLocale
in interfaceEnvironment
- Returns:
- the
Locale
-
setLocale
public void setLocale(Locale locale)
-
getTimeZone
public TimeZone getTimeZone()
Description copied from interface:Environment
Returns the currentTimeZone
. If aSubject
is present (no matter whether it is logged in or not),Account.getTimeZone()
is being returned. If noSubject
is present, the default-TimeZone
from theSite
is used.- Specified by:
getTimeZone
in interfaceEnvironment
- Returns:
- the
TimeZone
-
setTimeZone
public void setTimeZone(TimeZone timeZone)
-
getSubject
public Subject getSubject()
Description copied from interface:Environment
Returns the currentSubject
.- Specified by:
getSubject
in interfaceEnvironment
- Returns:
- the
Subject
, if present
-
logoutSubject
public void logoutSubject()
Removes the currentSubject
form theHttpSession
and invalidates the latter.
-
disable
public void disable(Scope scope)
Disables the givenScope
for this environment- Parameters:
scope
- theScope
to disable- See Also:
enable(Scope)
-
enable
public void enable(Scope scope)
Enables the givenScope
for this environment- Parameters:
scope
- theScope
to enable- See Also:
disable(Scope)
-
isInitialized
public boolean isInitialized()
Checks whether thisEnvironment
has been initialized.- Returns:
true
if hisEnvironment
has been initialized,false
otherwise.- See Also:
init(ServletContext, ServletRequest, ServletResponse)
-
-