org.apache.struts2.portlet.dispatcher
Class Jsr168Dispatcher

java.lang.Object
  extended by javax.portlet.GenericPortlet
      extended by org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher
All Implemented Interfaces:
javax.portlet.Portlet, javax.portlet.PortletConfig, PortletActionConstants, StrutsStatics

public class Jsr168Dispatcher
extends javax.portlet.GenericPortlet
implements StrutsStatics, PortletActionConstants

Struts JSR-168 portlet dispatcher. Similar to the WW2 Servlet dispatcher, but adjusted to a portal environment. The portlet is configured through the portlet.xml descriptor. Examples and descriptions follow below:

Author:
Nils-Helge Garli, Rainer Hermanns

Init parameters

Name Description Default value
portletNamespaceThe namespace for the portlet in the xwork configuration. This namespace is prepended to all action lookups, and makes it possible to host multiple portlets in the same portlet application. If this parameter is set, the complete namespace will be /portletNamespace/modeNamespace/actionNameThe default namespace
viewNamespaceBase namespace in the xwork configuration for the view portlet modeThe default namespace
editNamespaceBase namespace in the xwork configuration for the edit portlet modeThe default namespace
helpNamespaceBase namespace in the xwork configuration for the help portlet modeThe default namespace
defaultViewActionDefault action to invoke in the view portlet mode if no action is specifieddefault
defaultEditActionDefault action to invoke in the edit portlet mode if no action is specifieddefault
defaultHelpActionDefault action to invoke in the help portlet mode if no action is specifieddefault

Example:

 

 <init-param>
     <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
     <name>viewNamespace</name>
     <value>/view</value>
 </init-param>
 <init-param>
    <!-- The default action to invoke in view mode -->
    <name>defaultViewAction</name>
    <value>index</value>
 </init-param>
 <init-param>
     <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
     <name>editNamespace</name>
     <value>/edit</value>
 </init-param>
 <init-param>
     <!-- The default action to invoke in view mode -->
     <name>defaultEditAction</name>
     <value>index</value>
 </init-param>
 <init-param>
     <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
     <name>helpNamespace</name>
     <value>/help</value>
 </init-param>
 <init-param>
     <!-- The default action to invoke in view mode -->
     <name>defaultHelpAction</name>
     <value>index</value>
 </init-param>

 
 

Field Summary
 
Fields inherited from interface org.apache.struts2.StrutsStatics
HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT
 
Fields inherited from interface org.apache.struts2.portlet.PortletActionConstants
ACTION_MAPPING, ACTION_PARAM, ACTION_RESET, DEFAULT_ACTION_FOR_MODE, DEFAULT_ACTION_NAME, DEFAULT_DISPATCHER_SERVLET_NAME, DISPATCH_TO, ERROR_ACTION, EVENT_ACTION, EVENT_PHASE, MODE_NAMESPACE_MAP, MODE_PARAM, PHASE, PORTLET_CONFIG, PORTLET_NAMESPACE, RENDER_DIRECT_LOCATION, RENDER_PHASE, REQUEST, RESPONSE, STACK_FROM_EVENT_PHASE
 
Constructor Summary
Jsr168Dispatcher()
           
 
Method Summary
 java.util.HashMap<java.lang.String,java.lang.Object> createContextMap(java.util.Map<java.lang.String,java.lang.Object> requestMap, java.util.Map<java.lang.String,java.lang.String[]> parameterMap, java.util.Map<java.lang.String,java.lang.Object> sessionMap, java.util.Map<java.lang.String,java.lang.Object> applicationMap, javax.portlet.PortletRequest request, javax.portlet.PortletResponse response, javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, javax.servlet.ServletContext servletContext, javax.portlet.PortletConfig portletConfig, java.lang.Integer phase)
          Merges all application and portlet attributes into a single HashMap to represent the entire Action context.
 void destroy()
           
protected  ActionMapping getActionMapping(javax.portlet.PortletRequest portletRequest, javax.servlet.http.HttpServletRequest servletRequest)
          Gets the namespace of the action from the request.
protected  java.util.Map getApplicationMap()
          Returns a Map of all application attributes.
protected  java.util.Map<java.lang.String,java.lang.String[]> getParameterMap(javax.portlet.PortletRequest request)
          Returns a Map of all request parameters.
protected  java.util.Map getRequestMap(javax.portlet.PortletRequest request)
          Returns a Map of all request attributes.
protected  java.util.Map getSessionMap(javax.portlet.PortletRequest request)
          Returns a Map of all session attributes.
 void init(javax.portlet.PortletConfig cfg)
          Initialize the portlet with the init parameters from portlet.xml
 void processAction(javax.portlet.ActionRequest request, javax.portlet.ActionResponse response)
          Service an action from the event phase.
 void render(javax.portlet.RenderRequest request, javax.portlet.RenderResponse response)
          Service an action from the render phase.
 void serviceAction(javax.portlet.PortletRequest request, javax.portlet.PortletResponse response, java.util.Map<java.lang.String,java.lang.Object> requestMap, java.util.Map<java.lang.String,java.lang.String[]> parameterMap, java.util.Map<java.lang.String,java.lang.Object> sessionMap, java.util.Map<java.lang.String,java.lang.Object> applicationMap, java.lang.String portletNamespace, java.lang.Integer phase)
          Loads the action and executes it.
 void setActionMapper(ActionMapper actionMapper)
           
protected  void setActionProxyFactory(ActionProxyFactory factory)
          Convenience method to ease testing.
 
Methods inherited from class javax.portlet.GenericPortlet
doDispatch, doEdit, doHelp, doView, getInitParameter, getInitParameterNames, getPortletConfig, getPortletContext, getPortletName, getResourceBundle, getTitle, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jsr168Dispatcher

public Jsr168Dispatcher()
Method Detail

init

public void init(javax.portlet.PortletConfig cfg)
          throws javax.portlet.PortletException
Initialize the portlet with the init parameters from portlet.xml

Specified by:
init in interface javax.portlet.Portlet
Overrides:
init in class javax.portlet.GenericPortlet
Throws:
javax.portlet.PortletException

processAction

public void processAction(javax.portlet.ActionRequest request,
                          javax.portlet.ActionResponse response)
                   throws javax.portlet.PortletException,
                          java.io.IOException
Service an action from the event phase.

Specified by:
processAction in interface javax.portlet.Portlet
Overrides:
processAction in class javax.portlet.GenericPortlet
Throws:
javax.portlet.PortletException
java.io.IOException
See Also:
Portlet.processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)

render

public void render(javax.portlet.RenderRequest request,
                   javax.portlet.RenderResponse response)
            throws javax.portlet.PortletException,
                   java.io.IOException
Service an action from the render phase.

Specified by:
render in interface javax.portlet.Portlet
Overrides:
render in class javax.portlet.GenericPortlet
Throws:
javax.portlet.PortletException
java.io.IOException
See Also:
Portlet.render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)

createContextMap

public java.util.HashMap<java.lang.String,java.lang.Object> createContextMap(java.util.Map<java.lang.String,java.lang.Object> requestMap,
                                                                             java.util.Map<java.lang.String,java.lang.String[]> parameterMap,
                                                                             java.util.Map<java.lang.String,java.lang.Object> sessionMap,
                                                                             java.util.Map<java.lang.String,java.lang.Object> applicationMap,
                                                                             javax.portlet.PortletRequest request,
                                                                             javax.portlet.PortletResponse response,
                                                                             javax.servlet.http.HttpServletRequest servletRequest,
                                                                             javax.servlet.http.HttpServletResponse servletResponse,
                                                                             javax.servlet.ServletContext servletContext,
                                                                             javax.portlet.PortletConfig portletConfig,
                                                                             java.lang.Integer phase)
                                                                      throws java.io.IOException
Merges all application and portlet attributes into a single HashMap to represent the entire Action context.

Parameters:
requestMap - a Map of all request attributes.
parameterMap - a Map of all request parameters.
sessionMap - a Map of all session attributes.
applicationMap - a Map of all servlet context attributes.
request - the PortletRequest object.
response - the PortletResponse object.
portletConfig - the PortletConfig object.
phase - The portlet phase (render or action, see PortletActionConstants)
Returns:
a HashMap representing the Action context.
Throws:
java.io.IOException

serviceAction

public void serviceAction(javax.portlet.PortletRequest request,
                          javax.portlet.PortletResponse response,
                          java.util.Map<java.lang.String,java.lang.Object> requestMap,
                          java.util.Map<java.lang.String,java.lang.String[]> parameterMap,
                          java.util.Map<java.lang.String,java.lang.Object> sessionMap,
                          java.util.Map<java.lang.String,java.lang.Object> applicationMap,
                          java.lang.String portletNamespace,
                          java.lang.Integer phase)
                   throws javax.portlet.PortletException
Loads the action and executes it. This method first creates the action context from the given parameters then loads an ActionProxy from the given action name and namespace. After that, the action is executed and output channels throught the response object.

Parameters:
request - the HttpServletRequest object.
response - the HttpServletResponse object.
requestMap - a Map of request attributes.
parameterMap - a Map of request parameters.
sessionMap - a Map of all session attributes.
applicationMap - a Map of all application attributes.
portletNamespace - the namespace or context of the action.
phase - The portlet phase (render or action, see PortletActionConstants)
Throws:
javax.portlet.PortletException

getApplicationMap

protected java.util.Map getApplicationMap()
Returns a Map of all application attributes. Copies all attributes from the PortletActionContextinto an ApplicationMap.

Returns:
a Map of all application attributes.

getActionMapping

protected ActionMapping getActionMapping(javax.portlet.PortletRequest portletRequest,
                                         javax.servlet.http.HttpServletRequest servletRequest)
Gets the namespace of the action from the request. The namespace is the same as the portlet mode. E.g, view mode is mapped to namespace view, and edit mode is mapped to the namespace edit

Parameters:
request - the PortletRequest object.
Returns:
the namespace of the action.

getParameterMap

protected java.util.Map<java.lang.String,java.lang.String[]> getParameterMap(javax.portlet.PortletRequest request)
                                                                      throws java.io.IOException
Returns a Map of all request parameters. This implementation just calls PortletRequest.getParameterMap().

Parameters:
request - the PortletRequest object.
Returns:
a Map of all request parameters.
Throws:
java.io.IOException - if an exception occurs while retrieving the parameter map.

getRequestMap

protected java.util.Map getRequestMap(javax.portlet.PortletRequest request)
Returns a Map of all request attributes. The default implementation is to wrap the request in a RequestMap. Override this method to customize how request attributes are mapped.

Parameters:
request - the PortletRequest object.
Returns:
a Map of all request attributes.

getSessionMap

protected java.util.Map getSessionMap(javax.portlet.PortletRequest request)
Returns a Map of all session attributes. The default implementation is to wrap the reqeust in a SessionMap. Override this method to customize how session attributes are mapped.

Parameters:
request - the PortletRequest object.
Returns:
a Map of all session attributes.

setActionProxyFactory

protected void setActionProxyFactory(ActionProxyFactory factory)
Convenience method to ease testing.

Parameters:
factory -

destroy

public void destroy()
Specified by:
destroy in interface javax.portlet.Portlet
Overrides:
destroy in class javax.portlet.GenericPortlet

setActionMapper

public void setActionMapper(ActionMapper actionMapper)
Parameters:
actionMapper - the actionMapper to set


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.