org.jasig.portal.channels.portlet
Class CPortletAdapter

java.lang.Object
  extended by org.jasig.portal.channels.portlet.CPortletAdapter
All Implemented Interfaces:
IPortletAdaptor, IMultithreadedCacheable, IMultithreadedChannel, IMultithreadedCharacterChannel, IMultithreadedDirectResponse, IMultithreadedPrivileged

public class CPortletAdapter
extends java.lang.Object
implements IMultithreadedCharacterChannel, IMultithreadedPrivileged, IMultithreadedCacheable, IMultithreadedDirectResponse, IPortletAdaptor

A JSR 168 Portlet adapter that presents a portlet through the uPortal channel interface.

There is a related channel type called "Portlet Adapter" that is included with uPortal, so to use this channel, just select the "Portlet" type when publishing.

Note: A portlet can specify the String "password" in the user attributes section of the portlet.xml. In this is done, this adapter will look for the user's cached password. If the user's password is being stored in memory by a caching security context, the adapter will consult the cache to fill the request for the attribute. If the user's password is not cached, null will be set for the attributes value.

Version:
$Revision: 1.67.2.5 $
Author:
Ken Weiner, kweiner@unicon.net

Field Summary
protected static java.util.Map channelStateMap
           
private static ChannelCacheKey instanceCacheKey
           
protected  org.apache.commons.logging.Log log
           
private static org.apache.pluto.PortletContainer portletContainer
           
private static boolean portletContainerInitialized
           
private static java.lang.String portletDefinitionIdParamName
           
static java.lang.String portletPreferenceNamePrefix
           
private static java.lang.String REQUEST_PARAMS_KEY
           
private static javax.servlet.ServletConfig servletConfig
           
private static ChannelCacheKey systemCacheKey
           
private static java.lang.String uniqueContainerName
           
 
Constructor Summary
CPortletAdapter()
           
 
Method Summary
 ChannelCacheKey generateKey(java.lang.String uid)
          Generates a channel cache key.
protected  java.lang.String getMarkup(java.lang.String uid)
          This is where we do the real work of getting the markup.
private  java.lang.String getPassword(ISecurityContext baseContext)
          Retrieves the users password by iterating over the user's security contexts and returning the first available cached password.
 ChannelRuntimeProperties getRuntimeProperties(java.lang.String uid)
          Sets channel runtime properties.
protected  java.util.Map getUserInfo(java.lang.String uid, ChannelStaticData staticData, UserAttributeListImpl userAttributes)
          Get the Map of portlet user attribute names to portlet user attribute values.
protected  void initPortletContainer(java.lang.String uid)
           
protected  void initPortletWindow(java.lang.String uid)
           
 boolean isCacheValid(java.lang.Object validity, java.lang.String uid)
          Determines whether the cached content for this channel is still valid.
 void receiveEvent(PortalEvent ev, java.lang.String uid)
          React to portal events.
 void renderCharacters(java.io.PrintWriter pw, java.lang.String uid)
          Output channel content to the portal as raw characters
 void renderXML(org.xml.sax.ContentHandler out, java.lang.String uid)
          Output channel content to the portal.
 void setPortalControlStructures(PortalControlStructures pcs, java.lang.String uid)
          Sets the portal control structures.
 void setResponse(java.lang.String uid, javax.servlet.http.HttpServletResponse response)
          Sets the HttpServletResponse for the channel to use.
 void setRuntimeData(ChannelRuntimeData rd, java.lang.String uid)
          Sets the channel runtime data.
static void setServletConfig(javax.servlet.ServletConfig config)
          Receive the servlet config from uPortal's PortalSessionManager servlet.
 void setStaticData(ChannelStaticData sd, java.lang.String uid)
          Sets the channel static data.
protected  void setupRequestAttributes(javax.servlet.http.HttpServletRequest request, java.lang.String uid)
          Adds the appropriate information to the request attributes of the portlet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log

channelStateMap

protected static java.util.Map channelStateMap

portletContainerInitialized

private static boolean portletContainerInitialized

portletContainer

private static org.apache.pluto.PortletContainer portletContainer

servletConfig

private static javax.servlet.ServletConfig servletConfig

systemCacheKey

private static ChannelCacheKey systemCacheKey

instanceCacheKey

private static ChannelCacheKey instanceCacheKey

uniqueContainerName

private static final java.lang.String uniqueContainerName

REQUEST_PARAMS_KEY

private static final java.lang.String REQUEST_PARAMS_KEY

portletDefinitionIdParamName

private static final java.lang.String portletDefinitionIdParamName
See Also:
Constant Field Values

portletPreferenceNamePrefix

public static final java.lang.String portletPreferenceNamePrefix
See Also:
Constant Field Values
Constructor Detail

CPortletAdapter

public CPortletAdapter()
Method Detail

setServletConfig

public static void setServletConfig(javax.servlet.ServletConfig config)
Receive the servlet config from uPortal's PortalSessionManager servlet. Pluto needs access to this object from serveral places.

Parameters:
config - the servlet config

initPortletContainer

protected void initPortletContainer(java.lang.String uid)
                             throws PortalException
Parameters:
uid - A String uniquely identifying the IChannel 'instance' we are virtually representing as an IMultithreadedChannel.
Throws:
PortalException

initPortletWindow

protected void initPortletWindow(java.lang.String uid)
                          throws PortalException
Throws:
PortalException

getRuntimeProperties

public ChannelRuntimeProperties getRuntimeProperties(java.lang.String uid)
Sets channel runtime properties.

Specified by:
getRuntimeProperties in interface IMultithreadedChannel
Parameters:
uid - a unique ID used to identify the state of the channel
Returns:
channel runtime properties

receiveEvent

public void receiveEvent(PortalEvent ev,
                         java.lang.String uid)
React to portal events. Removes channel state from the channel state map when the session expires.

Specified by:
receiveEvent in interface IMultithreadedChannel
Parameters:
ev - a portal event
uid - a unique ID used to identify the state of the channel

setStaticData

public void setStaticData(ChannelStaticData sd,
                          java.lang.String uid)
                   throws PortalException
Sets the channel static data.

Specified by:
setStaticData in interface IMultithreadedChannel
Parameters:
sd - the channel static data
uid - a unique ID used to identify the state of the channel
Throws:
PortalException

setRuntimeData

public void setRuntimeData(ChannelRuntimeData rd,
                           java.lang.String uid)
                    throws PortalException
Sets the channel runtime data.

Specified by:
setRuntimeData in interface IMultithreadedChannel
Parameters:
rd - the channel runtime data
uid - a unique ID used to identify the state of the channel
Throws:
PortalException

setPortalControlStructures

public void setPortalControlStructures(PortalControlStructures pcs,
                                       java.lang.String uid)
                                throws PortalException
Sets the portal control structures.

Specified by:
setPortalControlStructures in interface IMultithreadedPrivileged
Parameters:
pcs - the portal control structures
uid - a unique ID used to identify the state of the channel
Throws:
PortalException
See Also:
PortalControlStructures

renderCharacters

public void renderCharacters(java.io.PrintWriter pw,
                             java.lang.String uid)
                      throws PortalException
Output channel content to the portal as raw characters

Specified by:
renderCharacters in interface IMultithreadedCharacterChannel
Parameters:
pw - a print writer
uid - a unique ID used to identify the state of the channel
Throws:
PortalException - if an error occurs

renderXML

public void renderXML(org.xml.sax.ContentHandler out,
                      java.lang.String uid)
               throws PortalException
Output channel content to the portal. This version of the render method is normally not used since this is a "character channel".

Specified by:
renderXML in interface IMultithreadedChannel
Parameters:
out - a sax document handler
uid - a unique ID used to identify the state of the channel
Throws:
PortalException

getMarkup

protected java.lang.String getMarkup(java.lang.String uid)
                              throws PortalException
This is where we do the real work of getting the markup. This is called from both renderXML() and renderCharacters().

Parameters:
uid - a unique ID used to identify the state of the channel
Returns:
markup representing channel content
Throws:
PortalException

generateKey

public ChannelCacheKey generateKey(java.lang.String uid)
Generates a channel cache key. The key scope is set to be system-wide when the channel is anonymously accessed, otherwise it is set to be instance-wide. The caching implementation here is simple and may not handle all cases. It may also violate the Portlet Specification so this obviously needs further discussion.

Specified by:
generateKey in interface IMultithreadedCacheable
Parameters:
uid - the unique identifier
Returns:
the channel cache key

isCacheValid

public boolean isCacheValid(java.lang.Object validity,
                            java.lang.String uid)
Determines whether the cached content for this channel is still valid.

Return true when:

  1. We have not just received an event
  2. No runtime parameters are sent to the channel
  3. The focus hasn't switched.
Otherwise, return false.

In other words, cache the content in all cases except for when a user clicks a channel button, a link or form button within the channel, or the focus or unfocus button.

Specified by:
isCacheValid in interface IMultithreadedCacheable
Parameters:
validity - the validity object
uid - the unique identifier
Returns:
true if the cache is still valid, otherwise false

setResponse

public void setResponse(java.lang.String uid,
                        javax.servlet.http.HttpServletResponse response)
Description copied from interface: IMultithreadedDirectResponse
Sets the HttpServletResponse for the channel to use.

Specified by:
setResponse in interface IMultithreadedDirectResponse
Parameters:
uid - The unique ID of the channel
response - The HttpServletResponse for the channel to use.

getPassword

private java.lang.String getPassword(ISecurityContext baseContext)
Retrieves the users password by iterating over the user's security contexts and returning the first available cached password.

Parameters:
baseContext - The security context to start looking for a password from.
Returns:
the users password

setupRequestAttributes

protected void setupRequestAttributes(javax.servlet.http.HttpServletRequest request,
                                      java.lang.String uid)
Adds the appropriate information to the request attributes of the portlet. This is an extension point. You can override this method to set other request attributes.

Parameters:
request - The request to add the attributes to
uid - The uid of the request so the appropriate ChannelState can be accessed

getUserInfo

protected java.util.Map getUserInfo(java.lang.String uid,
                                    ChannelStaticData staticData,
                                    UserAttributeListImpl userAttributes)
Get the Map of portlet user attribute names to portlet user attribute values. This is an extension point. You can extend CPortletAdapter and override this method to implement the particular user attribute Map creation strategy that you need to implement. Such strategies might rename uPortal user attributes to names that your particular portlet knows how to consume, transform the user attribute values to forms expected by your portlet, add additional attributes, convey a CAS proxy ticket or other security token. This extension point is the way to accomodate the particular user attributes particular portlets require. The default implementation of this method includes in the userInfo Map those uPortal IPerson attributes matching entries in the list of attributes the Portlet declared it wanted. Additionally, the default implementation copies the cached user password if the Portlet declares it wants the user attribute 'password'. We take the uid as an argument even though the default implementation does not use it because overriding implementations might use the uid to key into state maps.

Parameters:
uid - a String uniquely identifying the IChannel 'instance' we are emulating as an IMultithreaded channel.
staticData - data associated with the particular instance of the portlet window for the particular user session
userAttributes - the user attributes requested by the Portlet
Returns:
a Map from portlet user attribute names to portlet user attribute values.