message
Class MessageHelper

java.lang.Object
  extended bymessage.MessageHelper
All Implemented Interfaces:
MessageConstants

public class MessageHelper
extends java.lang.Object
implements MessageConstants

This is intended as the main interface between portlet code and the messaging system. It can be used to send and receive messages, and to load/save message mappings between the portlet preferences and the session. Each portlet should ensure that loadPrefs is called at least once per session (for example at the beginning of doView).


Field Summary
protected  MessageCentre msgCentre
           
protected  java.lang.String portletID
           
protected  java.lang.String sessionID
           
 
Fields inherited from interface message.MessageConstants
INPUT, MSG_CENTRE_KEY, MSG_LOADED, MSG_PORTLET_ID, MSG_SESSION_ID_RETRIEVER, NS_LOCAL, OUTPUT, PREF_IN_PREFIX, PREF_NAME, PREF_OUT_PREFIX, PREF_PUBLISHNAME, PREF_PUBLISHNS, PREF_SOURCENAME, PREF_SOURCENS
 
Constructor Summary
MessageHelper(PortletRequest request)
          Retrieve MessageHelper.
MessageHelper(PortletSession session, java.lang.String portletID, java.lang.String sessionID)
          Retrieve MessageHelper for messaging between portlets in one or more webapps.
 
Method Summary
protected static void clearPrefs(PortletPreferences prefs)
           
 java.lang.Object get(java.lang.String name)
          Get message.
 java.lang.String getAsString(java.lang.String name)
          Get message as String.
protected static java.util.Set getLoadedPrefs(PortletSession session)
           
static MessageCentre getMessageCentre(PortletSession session, java.lang.String sessionID)
          Retrieve MessageCentre for messaging between portlets in one or more webapps.
static java.lang.String getPortletID(PortletRequest request)
          Utility: get (and set, if not yet present) a unique ID for this portlet instance, cached in the session.
static java.lang.String getPortletID(PortletRequest request, boolean useWindowID)
          Utility: get (and set, if not yet present) a unique ID for this portlet instance, cached in the session.
static java.lang.String getPortletWindowID(PortletRequest request)
          Utility: Try to find the real portlet window ID, by setting a temporary attribute in the local portlet session.
static java.lang.String getSessionID(PortletRequest request)
          Utility: get a browser session ID.
protected static boolean loadedPrefs(PortletSession session, java.lang.String portletID)
           
static void loadPrefs(PortletRequest request)
          Loads portlet preferences for message mappings into the session, if this has not already been done (checked using loadedPrefs).
static void loadPrefs(PortletRequest request, java.lang.String portletID, java.lang.String sessionID)
          Loads portlet preferences for message mappings into the session, if this has not already been done (checked using loadedPrefs).
static void savePrefs(PortletRequest request, java.lang.String portletID, java.lang.String sessionID)
           
 void send(java.lang.String name, java.lang.Object message)
          Send message.
static void setLoadedPrefs(PortletSession session, java.lang.String portletID, boolean isLoaded)
          Sets a marker for whether or not the message mappings in the specified portlet's preferences have been loaded into the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

msgCentre

protected MessageCentre msgCentre

portletID

protected java.lang.String portletID

sessionID

protected java.lang.String sessionID
Constructor Detail

MessageHelper

public MessageHelper(PortletSession session,
                     java.lang.String portletID,
                     java.lang.String sessionID)
Retrieve MessageHelper for messaging between portlets in one or more webapps. The portletID should be an identifier for the portlet instance that is unique across all portlet apps, if you want to communicate between webapps. The sessionID should be an identifier to represent a particular user's browser session, that is shared across all portlet apps.


MessageHelper

public MessageHelper(PortletRequest request)
Retrieve MessageHelper. This will automatically use MessageHelper.getPortletID and MessageHelper.getSessionID.

Method Detail

getMessageCentre

public static MessageCentre getMessageCentre(PortletSession session,
                                             java.lang.String sessionID)
Retrieve MessageCentre for messaging between portlets in one or more webapps. The MessageStore implementation used can be configured. This checks MessageCentre.isValid() before returning it; if it is not valid, it creates a new one.


getPortletID

public static java.lang.String getPortletID(PortletRequest request)
Utility: get (and set, if not yet present) a unique ID for this portlet instance, cached in the session. It will try to retrieve the true window ID assigned by the portal, and then prefix it with the portlet context name. So IDs should be unique across portlet applications and probably persistent across sessions.


getPortletID

public static java.lang.String getPortletID(PortletRequest request,
                                            boolean useWindowID)
Utility: get (and set, if not yet present) a unique ID for this portlet instance, cached in the session. This uses the portlet context name, so IDs should be unique across portlet applications. If useWindowID is set, it tries to retrieve the actual portlet window ID assigned by the portal. If not set, it generates a random number for the ID.


getPortletWindowID

public static java.lang.String getPortletWindowID(PortletRequest request)
Utility: Try to find the real portlet window ID, by setting a temporary attribute in the local portlet session. Returns null if unable to do so.


getSessionID

public static java.lang.String getSessionID(PortletRequest request)
Utility: get a browser session ID. This should be available across portlet applications if you want cross context communication. The SessionIDRetriever used can be configured.


loadedPrefs

protected static boolean loadedPrefs(PortletSession session,
                                     java.lang.String portletID)

getLoadedPrefs

protected static java.util.Set getLoadedPrefs(PortletSession session)

setLoadedPrefs

public static void setLoadedPrefs(PortletSession session,
                                  java.lang.String portletID,
                                  boolean isLoaded)
Sets a marker for whether or not the message mappings in the specified portlet's preferences have been loaded into the session. You can force loadPrefs to reload the preferences by first calling this with isLoaded=false.


loadPrefs

public static void loadPrefs(PortletRequest request)
Loads portlet preferences for message mappings into the session, if this has not already been done (checked using loadedPrefs). This automatically calls getPortletID and getSessionID on the provided request.


loadPrefs

public static void loadPrefs(PortletRequest request,
                             java.lang.String portletID,
                             java.lang.String sessionID)
Loads portlet preferences for message mappings into the session, if this has not already been done (checked using loadedPrefs).


savePrefs

public static void savePrefs(PortletRequest request,
                             java.lang.String portletID,
                             java.lang.String sessionID)

clearPrefs

protected static void clearPrefs(PortletPreferences prefs)

get

public java.lang.Object get(java.lang.String name)
Get message. If there is no message, returns null.


getAsString

public java.lang.String getAsString(java.lang.String name)
Get message as String. If there is no message, returns "".


send

public void send(java.lang.String name,
                 java.lang.Object message)
Send message. This will replace any message already in the box.