org.activemath.webapp.base
Class AppSession

java.lang.Object
  extended by org.activemath.webapp.base.AppSession
All Implemented Interfaces:
EventListener, HttpSessionBindingListener, ActivemathEventListener

public class AppSession
extends Object
implements HttpSessionBindingListener, ActivemathEventListener

Represents a User in an HttpSession. A user is considered logged in when the user object in this session is not set to the AnonUser.


Method Summary
 Object attachedObject(String key)
          Retrieve an associated object, added with a call to attachObject.
 void attachListener(String key, ActivemathEventListener listener)
          Convenience method to attach an event listener to this AppSession.
 void attachObject(String key, Object o)
          Associate an object with this AppSession.
 void attachShutdownHook(String key, AppSessionShutdownHook hook)
          Convenience method to attach a shutdown hook to this AppSession.
 void clearAuthToken()
          Remove a token from this session and from AuthenticationManager.
 void detachHook(String key)
           
 void detachListener(String key)
           
 void detachObject(String key)
          Detach an object that has been attached by attachObject().
 ActivemathEvent[] fetchBrowserEvents()
          Fetch the queued browser events and clear the queue.
 List<String> getAcceptedLanguages()
          Languages accepted by the client of this session (derived from browser setting).
 AuthToken getAuthToken()
          Get the AuthToken for this session, or create one on first access.
 String getId()
          Synonym to getSessionId()
 String getLanguage()
          Language to use in this session.
 Book getLastUsedBook()
          Returns the book for which we received last a PagePresentedEvent.
 String getOutputFormat()
          Output format to use in this session (see Formatter).
 String getSessionId()
          Id of HttpSession bound to this session, or null.
 Skin getSkin()
          Skin to use in this session (can be the default skin).
 User getUser()
          User object bound to this session.
 long getUserStartedTime()
          Timestamp when the current user was set.
 boolean isLoggedIn()
          Say if we have a non-anon user
 void onActivemathEvent(ActivemathEvent event)
          Handle an ActivemathEvent for this session.
 void resetUser()
          Reset initial user of this session (AnonUser or null).
 String toString()
           
 void valueBound(HttpSessionBindingEvent event)
          Called when the object is bound to a HttpSession
 void valueUnbound(HttpSessionBindingEvent event)
          Called when the object is unbound from a HttpSession
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

toString

public String toString()
Overrides:
toString in class Object

isLoggedIn

public boolean isLoggedIn()
Say if we have a non-anon user


valueBound

public void valueBound(HttpSessionBindingEvent event)
Called when the object is bound to a HttpSession

Specified by:
valueBound in interface HttpSessionBindingListener

valueUnbound

public void valueUnbound(HttpSessionBindingEvent event)
Called when the object is unbound from a HttpSession

Specified by:
valueUnbound in interface HttpSessionBindingListener

attachObject

public void attachObject(String key,
                         Object o)
Associate an object with this AppSession. If the object implements ActivemathEventListener, all events will be forwarded to it. If the object implements AppSessionShutdownHook, this will get called when this session is shut down for whatever reason (and also on detachObject()).

Parameters:
key - object key
o - object to attach

attachedObject

public Object attachedObject(String key)
Retrieve an associated object, added with a call to attachObject.

Returns:
the object, or null.

attachListener

public void attachListener(String key,
                           ActivemathEventListener listener)
Convenience method to attach an event listener to this AppSession. Just calls attachObject(key, listener).


detachListener

public void detachListener(String key)

attachShutdownHook

public void attachShutdownHook(String key,
                               AppSessionShutdownHook hook)
Convenience method to attach a shutdown hook to this AppSession. Just calls #attachObject(key, hook).


detachHook

public void detachHook(String key)

detachObject

public void detachObject(String key)
Detach an object that has been attached by attachObject(). If the object implements AppSessionShutdownHook, this is called to inform the object of session shutdown.

Parameters:
key - - object key used by attachObject()

onActivemathEvent

public void onActivemathEvent(ActivemathEvent event)
Handle an ActivemathEvent for this session. The following actions are taken:

Specified by:
onActivemathEvent in interface ActivemathEventListener
Parameters:
event - the event to respond to
See Also:
ActivemathEventListener.onActivemathEvent(org.activemath.events.ActivemathEvent)

fetchBrowserEvents

public ActivemathEvent[] fetchBrowserEvents()
Fetch the queued browser events and clear the queue.

Returns:
array of ActivemathEvent, possibly empty.

getSessionId

public String getSessionId()
Id of HttpSession bound to this session, or null.


getId

public String getId()
Synonym to getSessionId()


getUser

public User getUser()
User object bound to this session. If no user is logged in, either return the AnonUser (if anon usage is enabled by config), or null.

Returns:
user object bound to this session, or null, indicating that anon usage is disallowed and user is not logged in.

resetUser

public void resetUser()
Reset initial user of this session (AnonUser or null).


getAcceptedLanguages

public List<String> getAcceptedLanguages()
Languages accepted by the client of this session (derived from browser setting).


getSkin

public Skin getSkin()
Skin to use in this session (can be the default skin).

Returns:
Skin to use in this session, never null.

getLanguage

public String getLanguage()
Language to use in this session.


getOutputFormat

public String getOutputFormat()
Output format to use in this session (see Formatter).


getLastUsedBook

public Book getLastUsedBook()
Returns the book for which we received last a PagePresentedEvent.

Returns:
the book or null

getUserStartedTime

public long getUserStartedTime()
Timestamp when the current user was set. For AnonUser, it's the time when the session started. For a regular User, it's the time of login.

Returns:
Timestamp when the current user was set, or -1.

getAuthToken

public AuthToken getAuthToken()
Get the AuthToken for this session, or create one on first access.


clearAuthToken

public void clearAuthToken()
Remove a token from this session and from AuthenticationManager.