com.flexive.shared
Class FxContext

java.lang.Object
  extended by com.flexive.shared.FxContext
All Implemented Interfaces:
java.io.Serializable

public class FxContext
extends java.lang.Object
implements java.io.Serializable

The [fleXive] context - user session specific data like UserTickets, etc.

Author:
Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at), Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at), Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
See Also:
Serialized Form

Field Summary
static java.lang.String ADMIN_AUTHENTICATED
          Session key set if the user successfully logged into the admin area
static int DIV_GLOBAL_CONFIGURATION
          Global division id
static int DIV_UNDEFINED
          Undefined division id
static java.lang.String SESSION_DIVISIONID
          Session key for the session division ID.
 
Method Summary
static FxContext _getEJBContext(FxContext template)
          Get a FxContext instance to use at the EJB layer.
 void _reloadUserTicket()
          Reload the UserTicket, needed i.e.
static void cleanup()
          Performs a cleanup of the stored informations.
 void clearCachedAttributes()
          Remove attributes that are known to be cached (before storing the context for later use).
 FxContext copy()
          Returns an independent copy of this context.
static FxContext get()
          Gets the session information for the running thread
 java.lang.String getAbsolutePath(java.lang.String path)
          Returns the absolute path for the given resource (i.e.
 java.lang.String getApplicationId()
          Returns the id of the appication the request was made in.
 java.lang.Object getAttribute(java.lang.Object key)
          Return the value stored under the given key.
 java.util.Map<java.lang.Object,java.lang.Object> getAttributeMap()
          Return a (unmodifiable) map of all attributes stored in the context.
 java.lang.String getContextPath()
          Return the context path of this request.
 java.lang.String getDateFormat()
          Get the used date format - either an override set in the context or the one defined by the current users ticket
 java.lang.String getDateFormatOverride()
           
 java.text.DateFormat getDateFormatter()
          Get the date formatter for the current users locale
 java.text.DateFormat getDateFormatter(java.util.Locale locale)
          Get the date formatter for the requested locale
 java.lang.String getDateTimeFormat()
          Get the used date/time format - either an override set in the context or the one defined by the current users ticket
 java.lang.String getDateTimeFormatOverride()
           
 java.text.DateFormat getDateTimeFormatter()
          Get the date/time formatter for the current users locale
 java.text.DateFormat getDateTimeFormatter(java.util.Locale locale)
          Get the date/time formatter for the requested locale
 char getDecimalSeparator()
          Get the used decimal separator - either an override set in the context or the one defined by the current users ticket
 char getDecimalSeparatorOverride()
           
 DivisionData getDivisionData()
           
 int getDivisionId()
          Returns the id of the division.
 char getGroupingSeparator()
          Get the used grouping separator - either an override set in the context or the one defined by the current users ticket
 char getGroupingSeparatorOverride()
           
 FxLanguage getLanguage()
          Get the current users preferred language
 java.util.Locale getLocale()
          Get the current users preferred locale (based on his preferred language)
 java.text.NumberFormat getNumberFormatInstance()
          Get a number format instance depending on the current users formatting options
 java.text.NumberFormat getNumberFormatInstance(java.util.Locale locale)
          Get a number format instance depending on the current users formatting options
 java.text.NumberFormat getPortableNumberFormatInstance()
          Get a portable number formatter instance
 java.lang.String getRelativeRequestURI()
          Returns the decoded relative request URI.
 java.lang.String getRelativeRequestURI(boolean decode)
          Returns the relative request URI.
 java.lang.String getRemoteHost()
          Returns the calling remote host.
 java.lang.String getRequestURI()
          Returns the request URI.
 java.lang.String getRequestUriNoContext()
          Returns the request URI without its context.
 boolean getRunAsSystem()
          Returns true if all calls are done without permission checks for the time beeing.
 java.lang.String getServer()
          Returns the full server URL including the port for this request, e.g.
 java.lang.String getServerName()
          Returns the name of the server handling this request, e.g.
 int getServerPort()
          Returns the port of the server handling this request, e.g.
 java.lang.String getSessionId()
          Returns the session id, which is unique at call time
 UserTicket getTicket()
           
static UserTicket getTicketFromEJB(javax.servlet.http.HttpSession session)
          Gets the user ticket from the ejb layer, and stores it in the session as 'last used user ticket'
 java.lang.String getTimeFormat()
          Get the used time format - either an override set in the context or the one defined by the current users ticket
 java.lang.String getTimeFormatOverride()
           
 java.text.DateFormat getTimeFormatter()
          Get the time formatter for the current users locale
 java.text.DateFormat getTimeFormatter(java.util.Locale locale)
          Get the time formatter for the requested locale
 boolean getTreeWasModified()
          Returns true if the tree was modified within this thread by the user belonging to this thread.
 java.lang.Boolean getUseGroupingSeparatorOverride()
           
static UserTicket getUserTicket()
          Returns the user ticket associated to the current thread.
static void initializeSystem(int divisionId, java.lang.String applicationName)
          Helper method to bootstrap a [fleXive] system outside an application server (e.g.
 boolean isExecutingRunOnceScripts()
          Is this context currently executing run-once scripts? This effectively returns the user id of the default global supervisor, but does not change any other behaviour.
 boolean isGlobalAuthenticated()
          Return true if the user successfully authenticated for the global configuration area
 boolean isGlobalConfigDivision()
          Returns true if the division is the global configuration division.
 boolean isTestDivision()
          Return true if the current context runs in the test division.
 boolean isWebDAV()
          Returns true if this request is triggered by a webdav operation.
 void login(java.lang.String loginname, java.lang.String password, boolean takeOver)
          Tries to login a user.
 void logout()
          Logout of the current user.
 void overrideTicket(UserTicket ticket)
          Override the used ticket.
static boolean preventAutoVersioning()
          Should auto versioning be prevented for this context?
static void remove()
          Remove the thread-local FxContext instance.
 void replace()
          Stores the FxContext instance in the current thread.
 void runAsSystem()
          Runs all further calls as SYSTEM user with full permissions until stopRunAsSystem gets called.
 void setAttribute(java.lang.Object key, java.lang.Object value)
          Store a value under the given key in the current request's FxContext.
 void setContextPath(java.lang.String contextPath)
          Changes the context path (Currently needed for embedded container testing.)
 void setDateFormatOverride(java.lang.String dateFormatOverride)
           
 void setDateTimeFormatOverride(java.lang.String dateTimeFormatOverride)
           
 void setDecimalSeparatorOverride(char decimalSeparatorOverride)
           
 void setDivisionId(int division)
          Changes the division ID.
 void setExecutingRunOnceScripts(boolean executingRunOnceScripts)
          Mark this context for executing run-once scripts.
 void setGlobalAuthenticated(boolean globalAuthenticated)
          Authorize the user for the global configuration area
 void setGroupingSeparatorOverride(char groupingSeparatorOverride)
           
static void setPreventAutoVersioning(boolean flag)
          Set auto versioning prevention flag
 void setSessionID(java.lang.String sessionID)
          Sets the session ID.
 void setTicket(UserTicket ticket)
           
 void setTimeFormatOverride(java.lang.String timeFormatOverride)
           
 void setTreeWasModified()
          Flag the tree as modified
 void setUseGroupingSeparatorOverride(java.lang.Boolean useGroupingSeparatorOverride)
           
static void startRunningAsSystem()
          Shortcut for FxContext.get().runAsSystem().
 void stopRunAsSystem()
          Removes one runeAsSystem flag from the stack.
static void stopRunningAsSystem()
          Shortcut for FxContext.get().stopRunAsSystem().
static FxContext storeEmptyContext(javax.servlet.http.HttpServletRequest request, int divisionId, boolean isWebdav, boolean forceSession)
          Set an empty FxContext instance for the current request.
static FxContext storeInfos(javax.servlet.http.HttpServletRequest request, boolean dynamicContent, int divisionId, boolean isWebdav)
          Stores the needed informations about the sessions.
 java.lang.String toString()
          Returns a string representation of the object.
 boolean useGroupingSeparator()
          Use the grouping separator? - either an override set in the context or the one defined by the current users ticket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIV_GLOBAL_CONFIGURATION

public static final int DIV_GLOBAL_CONFIGURATION
Global division id

See Also:
Constant Field Values

DIV_UNDEFINED

public static final int DIV_UNDEFINED
Undefined division id

See Also:
Constant Field Values

ADMIN_AUTHENTICATED

public static final java.lang.String ADMIN_AUTHENTICATED
Session key set if the user successfully logged into the admin area

See Also:
Constant Field Values

SESSION_DIVISIONID

public static final java.lang.String SESSION_DIVISIONID
Session key for the session division ID.

See Also:
Constant Field Values
Method Detail

getTicket

public UserTicket getTicket()

setTicket

public void setTicket(UserTicket ticket)

getTreeWasModified

public boolean getTreeWasModified()
Returns true if the tree was modified within this thread by the user belonging to this thread.

Returns:
true if the tree was modified

setTreeWasModified

public void setTreeWasModified()
Flag the tree as modified


isExecutingRunOnceScripts

public boolean isExecutingRunOnceScripts()
Is this context currently executing run-once scripts? This effectively returns the user id of the default global supervisor, but does not change any other behaviour. It is needed to avoid creating entries owned by the guest user when setting up a flexive division.

Returns:
context is currently executing run-once scripts
Since:
3.1

setExecutingRunOnceScripts

public void setExecutingRunOnceScripts(boolean executingRunOnceScripts)
Mark this context for executing run-once scripts. This method is used internally and should not be accessed otherwise as it will not provide the calling user with additional permissions, etc.

Parameters:
executingRunOnceScripts - flag
Since:
3.1

getLocale

public java.util.Locale getLocale()
Get the current users preferred locale (based on his preferred language)

Returns:
the current users preferred locale (based on his preferred language)

getLanguage

public FxLanguage getLanguage()
Get the current users preferred language

Returns:
the current users preferred language

login

public void login(java.lang.String loginname,
                  java.lang.String password,
                  boolean takeOver)
           throws FxLoginFailedException,
                  FxAccountInUseException
Tries to login a user.

The next getUserTicket() call will return the new ticket.

Parameters:
loginname - the unique user name
password - the password
takeOver - the take over flag
Throws:
FxLoginFailedException - if the login failed
FxAccountInUseException - if take over was false and the account is in use

logout

public void logout()
            throws FxLogoutFailedException
Logout of the current user.

Throws:
FxLogoutFailedException - if the function fails

overrideTicket

public void overrideTicket(UserTicket ticket)
Override the used ticket. Please do not use this method! Its only purpose is to feed FxContext with a UserTicket when no user is logged in - ie during system startup

Parameters:
ticket - ticket to override with

getTicketFromEJB

public static UserTicket getTicketFromEJB(javax.servlet.http.HttpSession session)
Gets the user ticket from the ejb layer, and stores it in the session as 'last used user ticket'

Parameters:
session - the session
Returns:
the user ticket

isGlobalConfigDivision

public boolean isGlobalConfigDivision()
Returns true if the division is the global configuration division.

Returns:
true if the division is the global configuration division

isTestDivision

public boolean isTestDivision()
Return true if the current context runs in the test division.

Returns:
true if the current context runs in the test division.

getDivisionId

public int getDivisionId()
Returns the id of the division.

Returns:
the id of the division.

setDivisionId

public void setDivisionId(int division)
Changes the division ID. Use with care! (Currently needed for embedded container testing.)

Parameters:
division - the division id

setContextPath

public void setContextPath(java.lang.String contextPath)
Changes the context path (Currently needed for embedded container testing.)

Parameters:
contextPath - the context path

runAsSystem

public void runAsSystem()
Runs all further calls as SYSTEM user with full permissions until stopRunAsSystem gets called. Multiple calls to this function get stacked and the runAsSystem flag is only removed when the stack is empty.


stopRunAsSystem

public void stopRunAsSystem()
Removes one runeAsSystem flag from the stack.


getRunAsSystem

public boolean getRunAsSystem()
Returns true if all calls are done without permission checks for the time beeing.

Returns:
true if all calls are done without permission checks for the time beeing

getSessionId

public java.lang.String getSessionId()
Returns the session id, which is unique at call time

Returns:
the session's id

setSessionID

public void setSessionID(java.lang.String sessionID)
Sets the session ID.

Parameters:
sessionID - the new session ID

getRequestURI

public java.lang.String getRequestURI()
Returns the request URI.

This URI contains the context path, use getRelativeRequestURI() to retrieve the path without it.

Returns:
the request URI

getRelativeRequestURI

public java.lang.String getRelativeRequestURI()
Returns the decoded relative request URI.

This function is the same as calling getRelativeRequestURI(true).

Returns:
the URI without its context path

getRelativeRequestURI

public java.lang.String getRelativeRequestURI(boolean decode)
Returns the relative request URI.

Parameters:
decode - if set to true the URI will be decoded (eg "%20" to a space), using UTF-8
Returns:
the URI without its context path

getServerName

public java.lang.String getServerName()
Returns the name of the server handling this request, e.g. www.flexive.com

Returns:
the name of the server handling this request, e.g. www.flexive.com

getServerPort

public int getServerPort()
Returns the port of the server handling this request, e.g. 80

Returns:
the port of the server handling this request, e.g. 80

getServer

public java.lang.String getServer()
Returns the full server URL including the port for this request, e.g. http://www.flexive.com:8080

Returns:
the full server URL including the port for this request, e.g. http://www.flexive.com:8080

getRemoteHost

public java.lang.String getRemoteHost()
Returns the calling remote host.

Returns:
the remote host.

getApplicationId

public java.lang.String getApplicationId()
Returns the id of the appication the request was made in.

In webapps the application id equals the context path

Returns:
the id of the appication the request was made in.

getAbsolutePath

public java.lang.String getAbsolutePath(java.lang.String path)
Returns the absolute path for the given resource (i.e. the application name + the path).

Parameters:
path - the path of the resource (e.g. /pub/css/demo.css)
Returns:
the absolute path for the given resource

_reloadUserTicket

public void _reloadUserTicket()
Reload the UserTicket, needed i.e. when language settings change


isWebDAV

public boolean isWebDAV()
Returns true if this request is triggered by a webdav operation.

Returns:
true if this request is triggered by a webdav operation

isGlobalAuthenticated

public boolean isGlobalAuthenticated()
Return true if the user successfully authenticated for the global configuration area

Returns:
true if the user successfully authenticated for the global configuration

setGlobalAuthenticated

public void setGlobalAuthenticated(boolean globalAuthenticated)
Authorize the user for the global configuration area

Parameters:
globalAuthenticated - true if the user should be authorized for the global configuration

getRequestUriNoContext

public java.lang.String getRequestUriNoContext()
Returns the request URI without its context.

Returns:
the request URI without its context.

getContextPath

public java.lang.String getContextPath()
Return the context path of this request.

Returns:
the context path of this request.

getDivisionData

public DivisionData getDivisionData()

copy

public FxContext copy()
Returns an independent copy of this context. Also clones the user ticket.

Returns:
an independent copy of this context
Since:
3.1

replace

public void replace()
Stores the FxContext instance in the current thread. Will overwrite an existing context.

Since:
3.1

remove

public static void remove()
Remove the thread-local FxContext instance.

Since:
3.1.5

clearCachedAttributes

public void clearCachedAttributes()
Remove attributes that are known to be cached (before storing the context for later use). This is basically a workaround since the context does not know which attributes must be preserved, and there's one very large blob that may be looming around (the cached FxEnvironment).

Since:
3.1.3

setAttribute

public void setAttribute(java.lang.Object key,
                         java.lang.Object value)
Store a value under the given key in the current request's FxContext.

A value stored in the context exists for the entire time of the fleXive request, for a web request this is slightly shorter than request scope. The main advantage is that the fleXive context is available for any request, not just requests from a web application, and that no overhead for setting or retrieving values exists.

Parameters:
key - the attribute key
value - the attribute value. If null, the attribute will be removed.
Since:
3.1

getAttribute

public java.lang.Object getAttribute(java.lang.Object key)
Return the value stored under the given key.

A value stored in the context exists for the entire time of the fleXive request, for a web request this is slightly shorter than request scope. The main advantage is that the fleXive context is available for any request, not just requests from a web application, and that no overhead for setting or retrieving values exists.

Parameters:
key - the attribute key
Returns:
the value stored under the given key.
Since:
3.1

getAttributeMap

public java.util.Map<java.lang.Object,java.lang.Object> getAttributeMap()
Return a (unmodifiable) map of all attributes stored in the context.

Returns:
a (unmodifiable) map of all attributes stored in the context.
Since:
3.1

storeInfos

public static FxContext storeInfos(javax.servlet.http.HttpServletRequest request,
                                   boolean dynamicContent,
                                   int divisionId,
                                   boolean isWebdav)
Stores the needed informations about the sessions.

Parameters:
request - the users request
dynamicContent - is the content dynamic?
divisionId - the division id
isWebdav - true if this is an webdav request
Returns:
FxContext

storeEmptyContext

public static FxContext storeEmptyContext(javax.servlet.http.HttpServletRequest request,
                                          int divisionId,
                                          boolean isWebdav,
                                          boolean forceSession)
Set an empty FxContext instance for the current request.

Parameters:
request - the servlet request
divisionId - the division ID
isWebdav - true for WebDAV requests (currently not used)
forceSession - whether a HTTP session should be created when none exists
Returns:
the context
Since:
3.2.0

cleanup

public static void cleanup()
Performs a cleanup of the stored informations.


initializeSystem

public static void initializeSystem(int divisionId,
                                    java.lang.String applicationName)
Helper method to bootstrap a [fleXive] system outside an application server (e.g. in unit tests or an standalone application). Should only be called on application startup. Will initialize a FxContext in the current thread with guest user privileges.

Parameters:
divisionId - the desired division ID (will determin the application datasource)
applicationName - the application name (mostly used as "imaginary context path")
Since:
3.1

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.

get

public static FxContext get()
Gets the session information for the running thread

Returns:
the session information for the running thread

getUserTicket

public static UserTicket getUserTicket()
Returns the user ticket associated to the current thread.

Returns:
the user ticket associated to the current thread.

startRunningAsSystem

public static void startRunningAsSystem()
Shortcut for FxContext.get().runAsSystem().

Since:
3.1

stopRunningAsSystem

public static void stopRunningAsSystem()
Shortcut for FxContext.get().stopRunAsSystem().

Since:
3.1

_getEJBContext

public static FxContext _getEJBContext(FxContext template)
Get a FxContext instance to use at the EJB layer. The returned context is a guest user only! This method should only be used internally (for use in different threads, etc.)

Parameters:
template - the template to use for the division
Returns:
FxContext

getDateFormatOverride

public java.lang.String getDateFormatOverride()

setDateFormatOverride

public void setDateFormatOverride(java.lang.String dateFormatOverride)

getTimeFormatOverride

public java.lang.String getTimeFormatOverride()

setTimeFormatOverride

public void setTimeFormatOverride(java.lang.String timeFormatOverride)

getDateTimeFormatOverride

public java.lang.String getDateTimeFormatOverride()

setDateTimeFormatOverride

public void setDateTimeFormatOverride(java.lang.String dateTimeFormatOverride)

getDecimalSeparatorOverride

public char getDecimalSeparatorOverride()

setDecimalSeparatorOverride

public void setDecimalSeparatorOverride(char decimalSeparatorOverride)

getGroupingSeparatorOverride

public char getGroupingSeparatorOverride()

setGroupingSeparatorOverride

public void setGroupingSeparatorOverride(char groupingSeparatorOverride)

getUseGroupingSeparatorOverride

public java.lang.Boolean getUseGroupingSeparatorOverride()

setUseGroupingSeparatorOverride

public void setUseGroupingSeparatorOverride(java.lang.Boolean useGroupingSeparatorOverride)

getDateFormat

public java.lang.String getDateFormat()
Get the used date format - either an override set in the context or the one defined by the current users ticket

Returns:
date format

getTimeFormat

public java.lang.String getTimeFormat()
Get the used time format - either an override set in the context or the one defined by the current users ticket

Returns:
time format

getDateTimeFormat

public java.lang.String getDateTimeFormat()
Get the used date/time format - either an override set in the context or the one defined by the current users ticket

Returns:
date/time format

getDecimalSeparator

public char getDecimalSeparator()
Get the used decimal separator - either an override set in the context or the one defined by the current users ticket

Returns:
decimal separator

getGroupingSeparator

public char getGroupingSeparator()
Get the used grouping separator - either an override set in the context or the one defined by the current users ticket

Returns:
grouping separator

useGroupingSeparator

public boolean useGroupingSeparator()
Use the grouping separator? - either an override set in the context or the one defined by the current users ticket

Returns:
use the grouping separator

getPortableNumberFormatInstance

public java.text.NumberFormat getPortableNumberFormatInstance()
Get a portable number formatter instance

Returns:
portable number formatter instance

getNumberFormatInstance

public java.text.NumberFormat getNumberFormatInstance()
Get a number format instance depending on the current users formatting options

Returns:
NumberFormat

getNumberFormatInstance

public java.text.NumberFormat getNumberFormatInstance(java.util.Locale locale)
Get a number format instance depending on the current users formatting options

Parameters:
locale - locale to use
Returns:
NumberFormat

getDateFormatter

public java.text.DateFormat getDateFormatter()
Get the date formatter for the current users locale

Returns:
DateFormat

getDateFormatter

public java.text.DateFormat getDateFormatter(java.util.Locale locale)
Get the date formatter for the requested locale

Parameters:
locale - requested locale
Returns:
DateFormat

getTimeFormatter

public java.text.DateFormat getTimeFormatter()
Get the time formatter for the current users locale

Returns:
DateFormat

getTimeFormatter

public java.text.DateFormat getTimeFormatter(java.util.Locale locale)
Get the time formatter for the requested locale

Parameters:
locale - requested locale
Returns:
DateFormat

getDateTimeFormatter

public java.text.DateFormat getDateTimeFormatter()
Get the date/time formatter for the current users locale

Returns:
DateFormat

getDateTimeFormatter

public java.text.DateFormat getDateTimeFormatter(java.util.Locale locale)
Get the date/time formatter for the requested locale

Parameters:
locale - requested locale
Returns:
DateFormat

preventAutoVersioning

public static boolean preventAutoVersioning()
Should auto versioning be prevented for this context?

Returns:
prevent auto versioning

setPreventAutoVersioning

public static void setPreventAutoVersioning(boolean flag)
Set auto versioning prevention flag

Parameters:
flag - auto versioning prevention flag