com.ibm.websphere.personalization.context
Class PersonalizationContext

java.lang.Object
  extended by com.ibm.websphere.personalization.context.PersonalizationContext
All Implemented Interfaces:
RequestContext, java.io.Serializable, java.lang.Cloneable

public class PersonalizationContext
extends java.lang.Object
implements RequestContext

This class provides several static methods that are useful in creating a RequestContext. It is also an implementor of RequestContext.

See Also:
RequestContext, Serialized Form

Field Summary
static java.lang.String CONTEXT_KEY
           
static java.lang.String COPYRIGHT
           
protected static boolean isPreviewServer
           
protected  PznPortletRequestObjectInterface portletRequestObject
           
protected  java.util.Date requestDate
           
protected  PznRequestObjectInterface requestObject
           
protected  java.lang.String requestUserName
           
protected  java.lang.Object triggerBean
           
 
Constructor Summary
protected PersonalizationContext()
           
protected PersonalizationContext(PznPortletRequestObjectInterface proi, java.lang.Object trigger)
           
protected PersonalizationContext(PznRequestObjectInterface roi, java.lang.Object trigger)
           
 
Method Summary
 boolean addCookie(javax.servlet.http.Cookie cookie)
          Sets a cookie.
 java.lang.Object clone()
           
 java.lang.Object get(java.lang.String key)
          Get a value from the context.
 java.lang.Object getApplicationObject(java.lang.String key, java.lang.String applicationObjectClass)
          Retrieves an application object from the context.
 java.lang.Object getApplicationObjectByPath(java.lang.String path)
           
 java.lang.String getAuthenticatedUsername()
          Returns the username of the Authenticated User.
 java.lang.String getContextPath()
          Used to get contextPath name from the HttpContext or surrogate.
 javax.servlet.http.Cookie getCookie(java.lang.String cookieName)
          Returns the value of a particular cookie, or null if none exist.
 javax.servlet.http.Cookie[] getCookies()
          Returns the array of cookies known to the request, or null if none exist.
static RequestContext getCurrentContext()
           
 java.util.Locale getLocale()
          Used to get locale from the HttpContext or surrogate.
 java.lang.Object getPortletAttribute(java.lang.String itemName)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists
 java.lang.Object getPortletSetting(java.lang.String itemName)
          Returns the value of the named setting as an Object, or null if no attribute of the given name exists.
 com.ibm.websphere.personalization.preview.IPreviewState getPreviewState()
           
 Resource getPreviewUserResource(java.lang.String resourceCollectionName)
          Returns the user Resource instance when in preview mode
 PznRequestObjectInterface getPznRequestObjectInterface()
          Returns the PznRequestObjectInterface
 java.lang.String getRemoteHost()
          Returns the hostName (IP address if hostName cannot be determined) of the server requesting the jsp or servlet containing the rule request
 java.lang.String getRemoteUser()
          Used to get remoteUser name from the HttpContext or surrogate.
 java.lang.Object getRequestAttribute(java.lang.String itemName)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists
static RequestContext getRequestContext()
          Get an instance of a default RequestContext
static RequestContext getRequestContext(javax.servlet.http.HttpServletRequest sr)
          Get an instance of RequestContext based on an HttpServletRequest
static RequestContext getRequestContext(javax.servlet.http.HttpServletRequest sr, java.lang.Object trigger)
          Get an instance of RequestContext based on an HttpServletRequest
static RequestContext getRequestContext(java.lang.Object request, java.lang.Object trigger)
          Get an instance of RequestContext based on an HttpServletRequest
static RequestContext getRequestContext(PznPortletRequestObjectInterface proi)
          Get an instance of RequestContext based on a PznPortletRequestObjectInterface
static RequestContext getRequestContext(PznPortletRequestObjectInterface proi, java.lang.Object trigger)
          Get an instance of RequestContext.
static RequestContext getRequestContext(PznRequestObjectInterface roi)
          Get an instance of RequestContext based on a PznRequestObjectInterface
static RequestContext getRequestContext(PznRequestObjectInterface roi, java.lang.Object trigger)
          Get an instance of RequestContext.
 java.util.Date getRequestDate()
          Returns the date of the request.
 java.lang.String getRequestInfo()
           
 PznRequestObjectInterface getRequestObject()
           
 java.lang.String getRequestParameter(java.lang.String itemName)
          Returns the value of a request parameter as a String, or null if the parameter does not exist.
 java.lang.String[] getRequestParameterValues(java.lang.String itemName)
          Returns the value of a request parameter as a String, or null if the parameter does not exist.
 java.lang.String getRequestUsername()
          Returns the username that personalization will use.
 com.ibm.websphere.personalization.resources.ResourceContext getResourceContext()
          Deprecated.  
 java.lang.String getServerName()
          Returns the hostName (IP address if hostName cannot be determined) of the server processing the rule request
 java.lang.Object getSessionAttribute(java.lang.String itemName)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists
 java.lang.String getSessionInfo()
           
 java.lang.String getTranslatedUsername(java.lang.String collectionName)
          Returns the username that personalization will use for the specified collection.
protected  Resource getUserResource(java.lang.String collName)
           
protected  void initialize(PznRequestObjectInterface roi, java.lang.Object trigger)
           
protected  void initializePreview()
           
 boolean isPreviewMode()
          Returns true if this is a preview execution context
protected  void mergePreviewRequest(PznPortletRequestObjectInterface previewRequest)
           
 void removePortletAttribute(java.lang.String itemName)
          Remove the value of the named attribute as an Object
 void removeRequestAttribute(java.lang.String itemName)
          Remove the value of the named attribute as an Object
 void removeSessionAttribute(java.lang.String itemName)
          Remove the value of the named attribute
 boolean setContextPath(java.lang.String contextPath)
          Used to set the application contextPath in the HttpContext surrogate.
 boolean setLocale(java.util.Locale locale)
          Used to set locale in the HttpContext surrogate.
 boolean setPortletAttribute(java.lang.String itemName, java.lang.Object itemValue)
          Set the value of the named attribute as an Object
 void setPreviewMode(boolean previewMode)
           
 boolean setRemoteUser(java.lang.String userName)
          Used to set remoteUser name in the HttpContext surrogate.
 void setRequestAttribute(java.lang.String itemName, java.lang.Object itemValue)
          Set the value of the named attribute as an Object
 boolean setRequestParameter(java.lang.String itemName, java.lang.String itemValue)
          Sets the value of a request parameter.
 boolean setRequestParameterValues(java.lang.String itemName, java.lang.String[] itemValues)
          Sets the value of a request parameter.
 void setRequestUsername(java.lang.String aName)
          Set the username that personalization will use for the duration of this request.
 void setResourceContext(com.ibm.websphere.personalization.resources.ResourceContext resContext)
          Deprecated.  
 boolean setSessionAttribute(java.lang.String itemName, java.lang.Object itemValue)
          Set the value of the named attribute.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

CONTEXT_KEY

public static final java.lang.String CONTEXT_KEY

isPreviewServer

protected static boolean isPreviewServer

requestUserName

protected java.lang.String requestUserName

requestObject

protected PznRequestObjectInterface requestObject

portletRequestObject

protected PznPortletRequestObjectInterface portletRequestObject

triggerBean

protected java.lang.Object triggerBean

requestDate

protected java.util.Date requestDate
Constructor Detail

PersonalizationContext

protected PersonalizationContext()

PersonalizationContext

protected PersonalizationContext(PznRequestObjectInterface roi,
                                 java.lang.Object trigger)

PersonalizationContext

protected PersonalizationContext(PznPortletRequestObjectInterface proi,
                                 java.lang.Object trigger)
Method Detail

initialize

protected void initialize(PznRequestObjectInterface roi,
                          java.lang.Object trigger)

getRequestInfo

public java.lang.String getRequestInfo()
Specified by:
getRequestInfo in interface RequestContext

getSessionInfo

public java.lang.String getSessionInfo()
Specified by:
getSessionInfo in interface RequestContext

isPreviewMode

public boolean isPreviewMode()
Description copied from interface: RequestContext
Returns true if this is a preview execution context

Specified by:
isPreviewMode in interface RequestContext

getCurrentContext

public static RequestContext getCurrentContext()

setPreviewMode

public void setPreviewMode(boolean previewMode)

getPreviewUserResource

public Resource getPreviewUserResource(java.lang.String resourceCollectionName)
Description copied from interface: RequestContext
Returns the user Resource instance when in preview mode

Specified by:
getPreviewUserResource in interface RequestContext

get

public java.lang.Object get(java.lang.String key)
Description copied from interface: RequestContext
Get a value from the context. The valid values to get are:

Specified by:
get in interface RequestContext
Parameters:
key - java.lang.String
Returns:
java.lang.Object

getApplicationObjectByPath

public java.lang.Object getApplicationObjectByPath(java.lang.String path)

getApplicationObject

public java.lang.Object getApplicationObject(java.lang.String key,
                                             java.lang.String applicationObjectClass)
Retrieves an application object from the context. If the application object is not found on the context, and it is a SelfInitializingApplicationObject, this method will attempt to create and initialize the object. getApplicationObject description

Specified by:
getApplicationObject in interface RequestContext
Parameters:
key -
applicationObjectClass -
Returns:
the ApplicationObject at the specified key.

getRequestObject

public PznRequestObjectInterface getRequestObject()

getRequestContext

public static RequestContext getRequestContext()
Get an instance of a default RequestContext

Returns:
com.ibm.websphere.personalization.RequestContext

getRequestContext

public static RequestContext getRequestContext(java.lang.Object request,
                                               java.lang.Object trigger)
Get an instance of RequestContext based on an HttpServletRequest

Parameters:
request - An implementation of either javax.servlet.http.HttpServletRequest, javax.portlet.PortletRequest, org.apache.jetspeed.portlet.PortletRequest, javax.servlet.http.HttpServletRequest, or com.ibm.websphere.personalization.PznRequestObjectInterface.
trigger - an object to use for dynamic classloading
Returns:
com.ibm.websphere.personalization.RequestContext

getRequestContext

public static RequestContext getRequestContext(javax.servlet.http.HttpServletRequest sr,
                                               java.lang.Object trigger)
Get an instance of RequestContext based on an HttpServletRequest

Parameters:
sr - javax.servlet.http.HttpServletRequest
trigger - An object which may be used for dynamic classloading
Returns:
com.ibm.websphere.personalization.RequestContext

getRequestContext

public static RequestContext getRequestContext(javax.servlet.http.HttpServletRequest sr)
Get an instance of RequestContext based on an HttpServletRequest

Parameters:
sr - javax.servlet.http.HttpServletRequest
Returns:
com.ibm.websphere.personalization.RequestContext

getRequestContext

public static RequestContext getRequestContext(PznRequestObjectInterface roi)
Get an instance of RequestContext based on a PznRequestObjectInterface

Parameters:
roi - PznRequestObjectInterface
Returns:
com.ibm.websphere.personalization.RequestContext

getRequestContext

public static RequestContext getRequestContext(PznRequestObjectInterface roi,
                                               java.lang.Object trigger)
Get an instance of RequestContext. The RuleTrigger ensures the correct classloader is used when instantiating resources from resource collections.

Parameters:
roi - The PznRequestObjectInterface which should back the returned RequestContext
trigger - An object which may be used for dynamic classloading
Returns:
com.ibm.websphere.personalization.RequestContext

getRequestContext

public static RequestContext getRequestContext(PznPortletRequestObjectInterface proi)
Get an instance of RequestContext based on a PznPortletRequestObjectInterface

Parameters:
proi - The PznPortletRequestObjectInterface which should back the returned RequestContext
Returns:
com.ibm.websphere.personalization.RequestContext

getRequestContext

public static RequestContext getRequestContext(PznPortletRequestObjectInterface proi,
                                               java.lang.Object trigger)
Get an instance of RequestContext. The RuleTrigger ensures the correct classloader is used when instantiating resources from resource collections.

Parameters:
proi - The PznPortletRequestObjectInterface which should back the returned RequestContext
trigger - An object which may be used for dynamic classloading
Returns:
com.ibm.websphere.personalization.RequestContext

getPreviewState

public com.ibm.websphere.personalization.preview.IPreviewState getPreviewState()

initializePreview

protected void initializePreview()

mergePreviewRequest

protected void mergePreviewRequest(PznPortletRequestObjectInterface previewRequest)

getAuthenticatedUsername

public java.lang.String getAuthenticatedUsername()
Description copied from interface: RequestContext
Returns the username of the Authenticated User. Will return null if no user is logged in.

Specified by:
getAuthenticatedUsername in interface RequestContext
Returns:
String

getRequestUsername

public java.lang.String getRequestUsername()
Description copied from interface: RequestContext
Returns the username that personalization will use. Can return null if no user has been established.

Specified by:
getRequestUsername in interface RequestContext
Returns:
String

getUserResource

protected Resource getUserResource(java.lang.String collName)

getRequestAttribute

public java.lang.Object getRequestAttribute(java.lang.String itemName)
Description copied from interface: RequestContext
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists

Specified by:
getRequestAttribute in interface RequestContext

setRequestAttribute

public void setRequestAttribute(java.lang.String itemName,
                                java.lang.Object itemValue)
Description copied from interface: RequestContext
Set the value of the named attribute as an Object

Specified by:
setRequestAttribute in interface RequestContext

removeRequestAttribute

public void removeRequestAttribute(java.lang.String itemName)
Description copied from interface: RequestContext
Remove the value of the named attribute as an Object

Specified by:
removeRequestAttribute in interface RequestContext

getPortletAttribute

public java.lang.Object getPortletAttribute(java.lang.String itemName)
Description copied from interface: RequestContext
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists

Specified by:
getPortletAttribute in interface RequestContext

setPortletAttribute

public boolean setPortletAttribute(java.lang.String itemName,
                                   java.lang.Object itemValue)
Description copied from interface: RequestContext
Set the value of the named attribute as an Object

Specified by:
setPortletAttribute in interface RequestContext

removePortletAttribute

public void removePortletAttribute(java.lang.String itemName)
Description copied from interface: RequestContext
Remove the value of the named attribute as an Object

Specified by:
removePortletAttribute in interface RequestContext

getPortletSetting

public java.lang.Object getPortletSetting(java.lang.String itemName)
Description copied from interface: RequestContext
Returns the value of the named setting as an Object, or null if no attribute of the given name exists. First checks the portlet entity preferences (edit mode), then checks the init parameters (admin portlets).

Specified by:
getPortletSetting in interface RequestContext

getRequestParameter

public java.lang.String getRequestParameter(java.lang.String itemName)
Description copied from interface: RequestContext
Returns the value of a request parameter as a String, or null if the parameter does not exist.

Specified by:
getRequestParameter in interface RequestContext

getRemoteHost

public java.lang.String getRemoteHost()
Description copied from interface: RequestContext
Returns the hostName (IP address if hostName cannot be determined) of the server requesting the jsp or servlet containing the rule request

Specified by:
getRemoteHost in interface RequestContext

getServerName

public java.lang.String getServerName()
Description copied from interface: RequestContext
Returns the hostName (IP address if hostName cannot be determined) of the server processing the rule request

Specified by:
getServerName in interface RequestContext

setRequestParameter

public boolean setRequestParameter(java.lang.String itemName,
                                   java.lang.String itemValue)
Description copied from interface: RequestContext
Sets the value of a request parameter. This is a nop for HttpRequests return true if operation supported, false if not supported

Specified by:
setRequestParameter in interface RequestContext

getRequestParameterValues

public java.lang.String[] getRequestParameterValues(java.lang.String itemName)
Description copied from interface: RequestContext
Returns the value of a request parameter as a String, or null if the parameter does not exist.

Specified by:
getRequestParameterValues in interface RequestContext

setRequestParameterValues

public boolean setRequestParameterValues(java.lang.String itemName,
                                         java.lang.String[] itemValues)
Description copied from interface: RequestContext
Sets the value of a request parameter. This is a nop for HttpRequests return true if operation supported, false if not supported

Specified by:
setRequestParameterValues in interface RequestContext

getSessionAttribute

public java.lang.Object getSessionAttribute(java.lang.String itemName)
Description copied from interface: RequestContext
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists

Specified by:
getSessionAttribute in interface RequestContext

setSessionAttribute

public boolean setSessionAttribute(java.lang.String itemName,
                                   java.lang.Object itemValue)
Description copied from interface: RequestContext
Set the value of the named attribute. Return true if operation supported, false if not supported

Specified by:
setSessionAttribute in interface RequestContext

removeSessionAttribute

public void removeSessionAttribute(java.lang.String itemName)
Description copied from interface: RequestContext
Remove the value of the named attribute

Specified by:
removeSessionAttribute in interface RequestContext

getRemoteUser

public java.lang.String getRemoteUser()
Description copied from interface: RequestContext
Used to get remoteUser name from the HttpContext or surrogate. The value will be either a null if the user has not been authenticated.

Specified by:
getRemoteUser in interface RequestContext

setRemoteUser

public boolean setRemoteUser(java.lang.String userName)
Description copied from interface: RequestContext
Used to set remoteUser name in the HttpContext surrogate. This is a nop on HttpRequests. return true if operation supported, false if not supported

Specified by:
setRemoteUser in interface RequestContext

getLocale

public java.util.Locale getLocale()
Description copied from interface: RequestContext
Used to get locale from the HttpContext or surrogate.

Specified by:
getLocale in interface RequestContext

setLocale

public boolean setLocale(java.util.Locale locale)
Description copied from interface: RequestContext
Used to set locale in the HttpContext surrogate. This is a nop on HttpRequests. return true if operation supported, false if not supported

Specified by:
setLocale in interface RequestContext

getContextPath

public java.lang.String getContextPath()
Description copied from interface: RequestContext
Used to get contextPath name from the HttpContext or surrogate. Must be supplied for the surrogate case and is used at a minimum to key the scope identity of rules and campaigns

Specified by:
getContextPath in interface RequestContext

setContextPath

public boolean setContextPath(java.lang.String contextPath)
Description copied from interface: RequestContext
Used to set the application contextPath in the HttpContext surrogate. This is a nop on HttpRequests. return true if operation supported, false if not supported

Specified by:
setContextPath in interface RequestContext

getCookies

public javax.servlet.http.Cookie[] getCookies()
Description copied from interface: RequestContext
Returns the array of cookies known to the request, or null if none exist.

Specified by:
getCookies in interface RequestContext

getCookie

public javax.servlet.http.Cookie getCookie(java.lang.String cookieName)
Description copied from interface: RequestContext
Returns the value of a particular cookie, or null if none exist.

Specified by:
getCookie in interface RequestContext

addCookie

public boolean addCookie(javax.servlet.http.Cookie cookie)
Description copied from interface: RequestContext
Sets a cookie. This is a nop for HttpRequests return true if operation supported, false if not supported

Specified by:
addCookie in interface RequestContext

getRequestDate

public java.util.Date getRequestDate()
Description copied from interface: RequestContext
Returns the date of the request. The time returned is determined by the PznRequestContext implementer, and is not guaranteed to be an accurate reflection of the time the request was submitted.

Specified by:
getRequestDate in interface RequestContext
Returns:
java.util.Date

getResourceContext

public com.ibm.websphere.personalization.resources.ResourceContext getResourceContext()
Deprecated. 

Description copied from interface: RequestContext
Returns the implementor of the ResourceContext interface. Can return null.

Specified by:
getResourceContext in interface RequestContext
Returns:
ResourceContext

setResourceContext

public void setResourceContext(com.ibm.websphere.personalization.resources.ResourceContext resContext)
Deprecated. 

Description copied from interface: RequestContext
Set the implementor of the ResourceContext interface.

Specified by:
setResourceContext in interface RequestContext

setRequestUsername

public void setRequestUsername(java.lang.String aName)
Description copied from interface: RequestContext
Set the username that personalization will use for the duration of this request.

Specified by:
setRequestUsername in interface RequestContext

getTranslatedUsername

public java.lang.String getTranslatedUsername(java.lang.String collectionName)
Description copied from interface: RequestContext
Returns the username that personalization will use for the specified collection. Can return null if no user has been established.

Specified by:
getTranslatedUsername in interface RequestContext
Returns:
String

getPznRequestObjectInterface

public PznRequestObjectInterface getPznRequestObjectInterface()
Description copied from interface: RequestContext
Returns the PznRequestObjectInterface

Specified by:
getPznRequestObjectInterface in interface RequestContext

clone

public java.lang.Object clone()
Specified by:
clone in interface RequestContext
Overrides:
clone in class java.lang.Object