com.ibm.wps.portlets.struts
Class WpsStrutsPortlet

java.lang.Object
  extended by HttpServlet
      extended by com.ibm.wps.pe.pc.legacy.cache.CacheablePortlet
          extended by org.apache.jetspeed.portlet.Portlet
              extended by org.apache.jetspeed.portlet.PortletAdapter
                  extended by com.ibm.wps.portlets.struts.WpsStrutsPortlet
All Implemented Interfaces:
ActionListener, MessageListener, PortletPageListener, PortletSessionListener

public class WpsStrutsPortlet
extends PortletAdapter
implements ActionListener, PortletPageListener, MessageListener

The WpsStrutsPortlet class is specified in the portlet deployment descriptor for Struts-based portlets. This class can be subclassed to customize the behavior of the portlet. In general, the WpsRequestProcessor should be subclassed to customize the behavior of the Struts applicaton. This class should be subclassed to affect the Portal behavior.

Since:
4.1

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.jetspeed.portlet.Portlet
Portlet.Mode, Portlet.ModeModifier
 
Field Summary
protected static MessageResources messages
          The message resources for the Struts Portlet Framework.
static java.lang.String STRUTS_SERVLET_MAPPING_KEY
          The key used to identify the Struts servlet mapping in the servlet context.
 
Constructor Summary
WpsStrutsPortlet()
          Construtor for the WpsStrutsPortlet.
 
Method Summary
 void actionPerformed(ActionEvent event)
          Called by the portlet container to allow the portlet to process an action request.
 void beginPage(PortletRequest portletRequest, PortletResponse portletResponse)
          Begin Page.
protected  WpsActionServlet createActionServlet(ServletContext servletContext, PortletConfig portletConfig, WpsStrutsInfo strutsInfo)
          Returns the WpsActionServlet for this application.
protected  ViewCommandExecutionContext createCommandExecutionContext(PortletContext portletContext, ModuleContext moduleContext, ServletContext servletContext)
          Creates a ViewCommandExecutionContext to be used when executing a ViewCommand.
protected  PortletRequest createPortletRequestWrapper(PortletRequest portletRequest)
          Creates a portlet request wrapper.
 void destroy(PortletConfig config)
          Destroys the portlet.
protected  void destroyCommandManagerPlugin(PortletConfig portletConfig)
          Calls the destroy method of the plugin.
 void doConfigure(PortletRequest request, PortletResponse response)
          Render method for configure mode.
 void doEdit(PortletRequest request, PortletResponse response)
          Render method for edit mode.
 void doHelp(PortletRequest request, PortletResponse response)
          Render method for help mode.
protected  void doService(PortletRequest portletRequest, PortletResponse response)
          The common processing for doView, doHelp, doConfigure and doEdit.
 void doView(PortletRequest request, PortletResponse response)
          Render method for view mode.
 void endPage(PortletRequest request, PortletResponse response)
          End Page.
 WpsActionServlet getActionServlet()
          Returns the WpsActionServlet object.
 long getLastModified(PortletRequest request)
          Gets the last modified time.
protected  MessageResources getMessages()
          Creates and fetches the default message resources for the Struts Portlet Framework.
 PortletContext getPortletContext()
          Returns the portlet context.
 PortletLog getPortletLog()
          Gets the portlet log.
 ServletContext getServletContext()
          Returns the servlet context.
 ServletContext getServletContextWrapper()
          Returns the servlet context wrapper.
protected  ServletContext getServletContextWrapper(PortletConfig portletConfig, ServletContext servletContext)
          Returns a servlet context that places the portlet attributes in their proper namescopes.
 WpsStrutsInfo getStrutsInfo()
          Returns the StrutsInfo object.
 java.lang.String getStrutsRoot()
          Returns the Struts Context root.
protected  java.util.Vector ServletContext)">getWelcomeFileList(ServletContext servletContext)
          Gets the welcome file list.
protected  java.util.List getWelcomeFileList(ServletContext servletContext, PortletContext portletContext, PortletRequest portletRequest)
          Gets the welcome file list.
 void init(PortletConfig portletConfig)
          Called by the portlet container to indicate to a portlet that the portlet is being placed into service.
protected  void initCommandManagerPlugin(PortletConfig portletConfig)
          Initializes the command manager factory plugin.
 void initConcrete(PortletSettings settings)
          Called by the portlet container to indicate that the concrete portlet is put into service.
 void login(PortletRequest request)
          Called by the portlet container to ask the portlet to initialize a personalized user experience.
 void logout(PortletSession session)
          Called by the portlet container when the user has logged out.
 void messageReceived(MessageEvent event)
          Process the sent message.
protected  void migratePseudoResponse(PortletResponse pseudoResponse, PortletResponse realResponse)
          Migrate the information from the PseudoResponse used during actionPerformed processing to real response.
 void processAction(PortletRequest portletRequest, java.lang.String strutsAction)
          Deprecated.  
protected  void processActionPerformed(PortletRequest portletRequest)
          The processing for actionPerformed.
protected  void processLocale(PortletRequest request)
          Sets the locale to the locale obtained from the portlet request object.
 void processStrutsAction(PortletRequest portletRequest, java.lang.String strutsAction)
          Invokes the Struts request processor for the specified Struts action.
protected  void readInitParameters(ServletContext servletContext, PortletConfig portletConfig, WpsStrutsInfo strutsInfo)
          Reads the init parameters for this portlet from the web deployment descriptor and performs the appropriate configuration.
protected  void saveWelcomeFileCommand(PortletRequest request)
          Saves the Welcome File Command.
 void setCommonsLogFactory()
          Deprecated. The LogFactory implementation class is set in commons-logging.properties.
protected static void setupBase(PortletRequest request, PortletResponse response, PortletConfig config)
          Allows BaseImplUtils to set up the processing.
protected  void setupRenderPhase(PortletRequest request)
          Sets up the render phase.
protected  void setupRequestPhase(PortletRequest request)
          Sets up the request phase.
 
Methods inherited from class org.apache.jetspeed.portlet.PortletAdapter
destroyConcrete, getPortletConfig, getVariable, removeVariable, service, setVariable
 
Methods inherited from class org.apache.jetspeed.portlet.Portlet
destroy, doGet, doPost, doPut, getId, getInitParameter, getInitParameterNames, getPortletSettings, getServletInfo
 
Methods inherited from class com.ibm.wps.pe.pc.legacy.cache.CacheablePortlet
getSharingPolicy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messages

protected static MessageResources messages
The message resources for the Struts Portlet Framework.


STRUTS_SERVLET_MAPPING_KEY

public static final java.lang.String STRUTS_SERVLET_MAPPING_KEY
The key used to identify the Struts servlet mapping in the servlet context.

See Also:
Constant Field Values
Constructor Detail

WpsStrutsPortlet

public WpsStrutsPortlet()
Construtor for the WpsStrutsPortlet.

Method Detail

getActionServlet

public WpsActionServlet getActionServlet()
Returns the WpsActionServlet object.

Returns:
returns the WpsActionServlet object

getStrutsInfo

public WpsStrutsInfo getStrutsInfo()
Returns the StrutsInfo object.

Returns:
returns the WpsStrutsInfo object

getStrutsRoot

public java.lang.String getStrutsRoot()
Returns the Struts Context root.

Returns:
the Struts context root

getServletContextWrapper

public ServletContext getServletContextWrapper()
Returns the servlet context wrapper.

Returns:
returns the servlet context wrapper

getServletContext

public ServletContext getServletContext()
Returns the servlet context. The servlet context wrapper is returned if called after the portlet is initialized, otherwise super.getServletContext is returned.

Overrides:
getServletContext in class Portlet
Returns:
returns the servlet context

getPortletContext

public PortletContext getPortletContext()
Returns the portlet context.

Returns:
returns the portlet context object

init

public void init(PortletConfig portletConfig)
          throws UnavailableException
Called by the portlet container to indicate to a portlet that the portlet is being placed into service.

Overrides:
init in class PortletAdapter
Parameters:
portletConfig - the portlet configuration
Throws:
UnavailableException - if an exception has occurrred that interferes with the portlet's normal initialization

getMessages

protected MessageResources getMessages()
Creates and fetches the default message resources for the Struts Portlet Framework.

Returns:
The created/fetched resources.

initConcrete

public void initConcrete(PortletSettings settings)
                  throws UnavailableException
Called by the portlet container to indicate that the concrete portlet is put into service.

Overrides:
initConcrete in class PortletAdapter
Parameters:
settings - the PortletSettings
Throws:
UnavailableException - if an exception has occurrred that interferes with the portlet's normal initialization

createActionServlet

protected WpsActionServlet createActionServlet(ServletContext servletContext,
                                               PortletConfig portletConfig,
                                               WpsStrutsInfo strutsInfo)
Returns the WpsActionServlet for this application. A protected method is used so the WpsActionServlet used can be customized.

Parameters:
servletContext - the ServletContext object
portletConfig - the PortletConfig object
strutsInfo - the StrutsInfo object
Returns:
returns the action servlet object

readInitParameters

protected void readInitParameters(ServletContext servletContext,
                                  PortletConfig portletConfig,
                                  WpsStrutsInfo strutsInfo)
Reads the init parameters for this portlet from the web deployment descriptor and performs the appropriate configuration.
Supported init parameters

Parameters:
servletContext - the servlet context
portletConfig - the portlet config
strutsInfo - the Struts info object

login

public void login(PortletRequest request)
           throws PortletException
Called by the portlet container to ask the portlet to initialize a personalized user experience.

Specified by:
login in interface PortletSessionListener
Overrides:
login in class PortletAdapter
Parameters:
request - the PortletRequest
Throws:
PortletException - if the portlet cannot fulfill the request

logout

public void logout(PortletSession session)
            throws PortletException
Called by the portlet container when the user has logged out.

Specified by:
logout in interface PortletSessionListener
Overrides:
logout in class PortletAdapter
Parameters:
session - the portlet session
Throws:
PortletException - if the portlet cannot fulfill the request

doService

protected void doService(PortletRequest portletRequest,
                         PortletResponse response)
                  throws PortletException,
                         java.io.IOException
The common processing for doView, doHelp, doConfigure and doEdit. The StrutsViewCommand is obtained from the CommandManagerFactory. If the command is found, then it is executed to render the view. If a StrutsViewCommand is not found then the welcome file processing is used to find the initial view.

Parameters:
request - the portlet request
response - the portlet response
Throws:
PortletException - if the portlet cannot fulfill the request
java.io.IOException - if the streaming causes an I/O problem

doView

public void doView(PortletRequest request,
                   PortletResponse response)
            throws PortletException,
                   java.io.IOException
Render method for view mode. The default implementation of this method calls the doService method.

Overrides:
doView in class PortletAdapter
Parameters:
request - the portlet request
response - the portlet response
Throws:
PortletException - if the portlet cannot fulfill the request
java.io.IOException - if the streaming causes an I/O problem

doHelp

public void doHelp(PortletRequest request,
                   PortletResponse response)
            throws PortletException,
                   java.io.IOException
Render method for help mode. The default implementation of this method calls the doService method.

Overrides:
doHelp in class PortletAdapter
Parameters:
request - the portlet request
response - the portlet response
Throws:
PortletException - if the portlet cannot fulfill the request
java.io.IOException - if the streaming causes an I/O problem

doEdit

public void doEdit(PortletRequest request,
                   PortletResponse response)
            throws PortletException,
                   java.io.IOException
Render method for edit mode. The default implementation of this method calls the doService method.

Overrides:
doEdit in class PortletAdapter
Parameters:
request - the portlet request
response - the portlet response
Throws:
PortletException - if the portlet cannot fulfill the request
java.io.IOException - if the streaming causes an I/O problem

doConfigure

public void doConfigure(PortletRequest request,
                        PortletResponse response)
                 throws PortletException,
                        java.io.IOException
Render method for configure mode. The default implementation of this method calls the doService method.

Overrides:
doConfigure in class PortletAdapter
Parameters:
request - the portlet request
response - the portlet response
Throws:
PortletException - if the portlet cannot fulfill the request
java.io.IOException - if the streaming causes an I/O problem

saveWelcomeFileCommand

protected void saveWelcomeFileCommand(PortletRequest request)
                               throws PortletException
Saves the Welcome File Command. The method will use portlet preferences or the the welcome file list to determine the welcome command.

Parameters:
request - the request object
Throws:
PortletException - if the portlet cannot fulfill the request

destroy

public void destroy(PortletConfig config)
Destroys the portlet.

Overrides:
destroy in class PortletAdapter
Parameters:
config - the portlet config

actionPerformed

public void actionPerformed(ActionEvent event)
                     throws PortletException
Called by the portlet container to allow the portlet to process an action request. This method is called if the client request was originated by a portlet URL with an action. This method will process the Struts action request parameter and determine if the Struts request processor should be called.

Specified by:
actionPerformed in interface ActionListener
Parameters:
event - the action event
Throws:
PortletException - if the portlet cannot fulfill the request

getPortletLog

public PortletLog getPortletLog()
Gets the portlet log.

Overrides:
getPortletLog in class PortletAdapter
Returns:
the PortletLog object

migratePseudoResponse

protected void migratePseudoResponse(PortletResponse pseudoResponse,
                                     PortletResponse realResponse)
Migrate the information from the PseudoResponse used during actionPerformed processing to real response. The only information migrated is the locale.

Parameters:
pseudoResponse - the pseudo response object
realResponse - the real response object

beginPage

public void beginPage(PortletRequest portletRequest,
                      PortletResponse portletResponse)
               throws PortletException,
                      java.io.IOException
Begin Page. If the user is an anonymous user and does not have a session object then one is created.

Specified by:
beginPage in interface PortletPageListener
Parameters:
request - the request object
response - the response object
Throws:
PortletException - if the portlet cannot fulfill the request
java.io.IOException - if the streaming causes an I/O problem

processActionPerformed

protected void processActionPerformed(PortletRequest portletRequest)
                               throws java.io.IOException,
                                      ServletException
The processing for actionPerformed. This method actually processes the action and determines if the request is for a Struts action or not. If the request is for the execution of a Struts action then the Struts Request Processor is invoked, otherwise the URI is passed to the ViewCommandFactory. This method is called from actionPerformed or for an action welcome file.

Parameters:
request - the request object
Throws:
ServletException - if the request processor cannot fulfill the request
java.io.IOException - if the streaming causes an I/O problem

endPage

public void endPage(PortletRequest request,
                    PortletResponse response)
             throws PortletException,
                    java.io.IOException
End Page. The current mode is saved is session so mode changes can be determined on future requests.

Specified by:
endPage in interface PortletPageListener
Parameters:
request - the request object
response - the response object
Throws:
PortletException - if the portlet cannot fulfill the request
java.io.IOException - if the streaming causes an I/O problem

createCommandExecutionContext

protected ViewCommandExecutionContext createCommandExecutionContext(PortletContext portletContext,
                                                                    ModuleContext moduleContext,
                                                                    ServletContext servletContext)
Creates a ViewCommandExecutionContext to be used when executing a ViewCommand. This can be overridden to supply execution context that is particular to the portal environment

Parameters:
portletContext - the PortletContext object
moduleContext - the module context object
servletContext - the servlet context object
Returns:
returns the ViewCommandExecutionContext object

messageReceived

public void messageReceived(MessageEvent event)
                     throws PortletException
Process the sent message. This version looks for both DefaultPortletMessage and IStrutsPortletMessage messages. If the DefaultPortletMessage starts with the WpsStrutsConstants.ACTION_KEY, then the message is processed as a Struts Action. If the DefaultPortletMessage message starts with WpsStrutsConstants.FORWARD_KEY, then the message is processed as a Struts global forward.

Specified by:
messageReceived in interface MessageListener
Parameters:
event - the message event
Throws:
PortletException - if the portlet cannot fulfill the request

getWelcomeFileList

protected java.util.List getWelcomeFileList(ServletContext servletContext,
                                            PortletContext portletContext,
                                            PortletRequest portletRequest)
Gets the welcome file list. This list will contain entries for the portlet definition and the web deployment descriptor.

Parameters:
servletContext - the servlet context object
portletContext - the portlet context object
portletRequest - the portlet request object
Returns:
a list of the welcome files

ServletContext)">

getWelcomeFileList

protected java.util.Vector getWelcomeFileList(ServletContext servletContext)
Gets the welcome file list. This implementation will only return the welcome files from "web.xml".

Parameters:
servletContext - the servlet context objects
Returns:
a list of the welcome files

createPortletRequestWrapper

protected PortletRequest createPortletRequestWrapper(PortletRequest portletRequest)
Creates a portlet request wrapper. The request wrapper will be used to implement request features unique to the Struts Portlet Framework.

Parameters:
portletRequest - the portlet request
Returns:
returns the portlet request wrapper

processStrutsAction

public void processStrutsAction(PortletRequest portletRequest,
                                java.lang.String strutsAction)
                         throws PortletException
Invokes the Struts request processor for the specified Struts action.

Parameters:
request - the request object
strutsAction - the Struts action
Throws:
PortletException - if the portlet cannot fulfill the request

processAction

public void processAction(PortletRequest portletRequest,
                          java.lang.String strutsAction)
Deprecated. 

Invokes the Struts request processor for the specified Struts action. This version does not throw a PortletException, see processStrutsAction.

Parameters:
request - the request object
strutsAction - the Struts action
See Also:
processStrutsAction(PortletRequest,String)

setupBase

protected static void setupBase(PortletRequest request,
                                PortletResponse response,
                                PortletConfig config)
Allows BaseImplUtils to set up the processing.

Parameters:
request - the request object
response - the response object
config - the config parameter

processLocale

protected void processLocale(PortletRequest request)
Sets the locale to the locale obtained from the portlet request object. The locale object is stored in session and used by Struts components.

NOTE - The Struts request processor implementation will only set a locale if a locale object is not already set. This method effectively defeats the Struts implementation.

We have also seen Struts actions that set the locale object in session, so the usePortalsLocale must be set to false for those applications to work.

Parameters:
request - the portlet request object

getLastModified

public long getLastModified(PortletRequest request)
Gets the last modified time. If the command is a WpsStrutsViewCommand, the last modified time can be obtained from the command object if the command sets the modified time.

Overrides:
getLastModified in class PortletAdapter
Parameters:
request - the portlet request object
Returns:
returns the last modified time

setupRenderPhase

protected void setupRenderPhase(PortletRequest request)
Sets up the render phase. Sets request attributes that can be used by the processing to determine the portal phase.

Parameters:
request - the portlet request object

setupRequestPhase

protected void setupRequestPhase(PortletRequest request)
Sets up the request phase. Sets request attributes that can be used by the processing to determine the portal phase.

Parameters:
request - the portlet request object

setCommonsLogFactory

public void setCommonsLogFactory()
Deprecated. The LogFactory implementation class is set in commons-logging.properties.

Sets the commons-logger for the Struts components.

NOTE - The log messages from the Portal environment for Struts will continue to be logged to the portal logger.


getServletContextWrapper

protected ServletContext getServletContextWrapper(PortletConfig portletConfig,
                                                  ServletContext servletContext)
Returns a servlet context that places the portlet attributes in their proper namescopes.

Parameters:
portletConfig - the portlet config
servletContext - the real servlet context
Returns:
returns the wrappered servlet context

initCommandManagerPlugin

protected void initCommandManagerPlugin(PortletConfig portletConfig)
Initializes the command manager factory plugin. The command manager plugin can be specified in the web deployment descriptor. This will allow a plugin to execute once per Struts application instead of once per Struts module.

Parameters:
portletConfig - the portlet config

destroyCommandManagerPlugin

protected void destroyCommandManagerPlugin(PortletConfig portletConfig)
Calls the destroy method of the plugin.

Parameters:
portletConfig - the portlet config