org.roscopeco.janno.views
Class ScriptedActionDispatcher

java.lang.Object
  extended by org.roscopeco.janno.views.AbstractViewDispatcher
      extended by org.roscopeco.janno.views.ScriptedActionDispatcher
All Implemented Interfaces:
ActionViewDispatcher

public class ScriptedActionDispatcher
extends AbstractViewDispatcher

Attempts to dispatch to a specific set of context-relative URLs based on predefined arrangements of the action path, name and result. As the name implies, this is primarily intended to be used alongside scripted actions, but it can in fact be used with both scripted and configured actions as a more implicit alternative to the full URLMappingDispatcher.

When instantiating ScriptedActionDispatcher you may supply a List with the view file extensions to be tried, in order. When searching for a view the dispatcher will try each of the path/name/result combinations detailed below for each extension in the order they're supplied (i.e. [each combination].jsp, then [each combination].vm, and so on). A convienience constructor is provided that will construct a single-element list for a String argument when only a single extension is to be used.

Assume we have a ScriptedActionDispatcher dispatcher, to which we supplied an extension list containing a single entry, jsp. Given an action mapped (either by script location or configuration) to the path /path/to/my and having the name action, which returns the value result, this class would attempt to dispatch to the following URLs in order:

Please note that this list and it's order is subject to change at this stage in development. It will be set later in the 1.0 cycle.

Version:
$Revision: 1.1 $ $Date: 2005/08/24 16:34:19 $
Author:
Ross Bamford (rosco<at>roscopeco.co.uk)

Constructor Summary
ScriptedActionDispatcher()
          Convienience constructor that uses a default set of extensions, namely .vm and .jsp, in that order.
ScriptedActionDispatcher(List<String> extensions)
          Create a new ScriptedActionDispatcher that will attempt to dispatch to each of the path/name/result combinations for each file extension in the supplied List.
ScriptedActionDispatcher(String extension)
          Convienience constructor for use with a single extension.
ScriptedActionDispatcher(String[] extensions)
          Convienience constructor for use with a String array of view extensions.
 
Method Summary
 boolean dispatchView(ServletContext ctx, HttpServletRequest req, HttpServletResponse resp, String actionPath, String actionName, String actionResult)
          Attempt to dispatch an action-view through this dispatcher.

This method checks each view path combination in turn, checking first if it exists, and then attempting to dispatch to it (forwarding or including as appropriate).

protected  List<String> viewsFor(String path, String name, String result)
          Returns a List of context-relative URL specs that should be tried by the dispatcher in order.
 
Methods inherited from class org.roscopeco.janno.views.AbstractViewDispatcher
dispatchTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptedActionDispatcher

public ScriptedActionDispatcher(List<String> extensions)
Create a new ScriptedActionDispatcher that will attempt to dispatch to each of the path/name/result combinations for each file extension in the supplied List. The list is shallow-copied, with each entry prefixed with a period if not already. Thus, jsp and .jsp are equal for the purposes of this method.

Although of little value, it is possible to create a dispatcher that won't actually dispatch anything by passing in either an empty list or null.

Parameters:
extensions - The List of String URL extensions.

ScriptedActionDispatcher

public ScriptedActionDispatcher(String extension)
Convienience constructor for use with a single extension.

Parameters:
extension - The String extension for dispatched views.

ScriptedActionDispatcher

public ScriptedActionDispatcher(String[] extensions)
Convienience constructor for use with a String array of view extensions.

Parameters:
extensions - An array of String containing the view extensions. The same parameter rules apply as for the ScriptedActionDispatcher(List) constructor.

ScriptedActionDispatcher

public ScriptedActionDispatcher()
Convienience constructor that uses a default set of extensions, namely .vm and .jsp, in that order. If you are using JSP routinely it is highly recommended that you call another constructor, since the ordering used by this one will result in a lot of work on every request.

Method Detail

dispatchView

public boolean dispatchView(ServletContext ctx,
                            HttpServletRequest req,
                            HttpServletResponse resp,
                            String actionPath,
                            String actionName,
                            String actionResult)
                     throws IOException,
                            ServletException
Attempt to dispatch an action-view through this dispatcher. See ActionViewDispatcher for general information on the dispatch process.

This method checks each view path combination in turn, checking first if it exists, and then attempting to dispatch to it (forwarding or including as appropriate).

Specified by:
dispatchView in interface ActionViewDispatcher
Specified by:
dispatchView in class AbstractViewDispatcher
Parameters:
ctx - The ServletContext within which the view request is to be processed.
req - The HttpServletRequest representing the user request.
resp - The HttpServletResponse in use.
actionPath - The path that was requested and resolved to the action.
actionName - The name of the action method that was called.
actionResult - The String result from the action.
Returns:
true if the view was dispatched (even if an error occured), or false if the view could not be mapped to a view builder.
Throws:
ServletException - if an error occurs during view processing.
IOException

viewsFor

protected List<String> viewsFor(String path,
                                String name,
                                String result)
Returns a List of context-relative URL specs that should be tried by the dispatcher in order. This method is protected to allow subclasses to easily affect the list of possible views.

For performance reasons this method is required to return a single List with all possible view combinations for all of the supplied extensions.

Parameters:
path - The path to the action. This is the path from which the action was loaded (scripts) or the key with which it was instantiated (configured actions).
name - The action name (the name of the method that was executed)
result - The String result from the action.
Returns:
A new List of String with all the URL combinations that should be tried by this dispatcher for a given action / result combination.


Copyright © 2005 Roscopeco Open Technologies. All Rights Reserved.