org.apache.struts2.convention
Class ConventionUnknownHandler

java.lang.Object
  extended by org.apache.struts2.convention.ConventionUnknownHandler
All Implemented Interfaces:
UnknownHandler

public class ConventionUnknownHandler
extends java.lang.Object
implements UnknownHandler

This class is the default unknown handler for all of the Convention plugin integration with XWork. This handles instances when a URL doesn't have an action associated with it but does a viable result and also the instance where an action returns a result code that isn't already configured but there is a viable result for the code.

This class also handles all of the index actions using redirects and actions in nested packages. For example, if there is an action /foo/index and the URL /foo is used, this will render the index action in the /foo namespace.


Nested Class Summary
static class ConventionUnknownHandler.Resource
           
 
Field Summary
protected  Configuration configuration
           
protected  java.lang.String defaultParentPackageName
           
protected  ObjectFactory objectFactory
           
protected  PackageConfig parentPackage
           
protected  ResultMapBuilder resultMapBuilder
           
protected  javax.servlet.ServletContext servletContext
           
 
Constructor Summary
ConventionUnknownHandler(Configuration configuration, ObjectFactory objectFactory, javax.servlet.ServletContext servletContext, Container container, java.lang.String defaultParentPackageName, java.lang.String redirectToSlash, java.lang.String nameSeparator)
          Constructs the unknown handler.
 
Method Summary
protected  ActionConfig buildActionConfig(java.lang.String path, ResultTypeConfig resultTypeConfig)
           
protected  Result buildResult(java.lang.String path, java.lang.String resultCode, ResultTypeConfig config, ActionContext invocationContext)
           
protected  java.lang.String canonicalize(java.lang.String path)
           
protected  java.lang.String determinePath(ActionConfig actionConfig, java.lang.String namespace)
          Determines the result path prefix that the request URL is for, minus the action name.
protected  ConventionUnknownHandler.Resource findResource(java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension, java.lang.String... parts)
          Finds a resource using the given path parts and all of the extensions in the map.
protected  Result findResult(java.lang.String path, java.lang.String resultCode, java.lang.String ext, ActionContext actionContext, java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)
           
 ActionConfig handleUnknownAction(java.lang.String namespace, java.lang.String actionName)
           
 java.lang.Object handleUnknownActionMethod(java.lang.Object action, java.lang.String methodName)
          Not used
 Result handleUnknownResult(ActionContext actionContext, java.lang.String actionName, ActionConfig actionConfig, java.lang.String resultCode)
           
protected  java.lang.String string(java.lang.String... parts)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected Configuration configuration

objectFactory

protected ObjectFactory objectFactory

servletContext

protected javax.servlet.ServletContext servletContext

resultMapBuilder

protected ResultMapBuilder resultMapBuilder

defaultParentPackageName

protected java.lang.String defaultParentPackageName

parentPackage

protected PackageConfig parentPackage
Constructor Detail

ConventionUnknownHandler

public ConventionUnknownHandler(Configuration configuration,
                                ObjectFactory objectFactory,
                                javax.servlet.ServletContext servletContext,
                                Container container,
                                java.lang.String defaultParentPackageName,
                                java.lang.String redirectToSlash,
                                java.lang.String nameSeparator)
Constructs the unknown handler.

Parameters:
configuration - The XWork configuration.
objectFactory - The XWork object factory used to create result instances.
servletContext - The servlet context used to help build the action configurations.
container - The Xwork container
defaultParentPackageName - The default XWork package that the unknown handler will use as the parent package for new actions and results.
redirectToSlash - A boolean parameter that controls whether or not this will handle unknown actions in the same manner as Apache, Tomcat and other web servers. This handling will send back a redirect for URLs such as /foo to /foo/ if there doesn't exist an action that responds to /foo.
nameSeparator - The character used as word separator in the action names. "-" by default
Method Detail

handleUnknownAction

public ActionConfig handleUnknownAction(java.lang.String namespace,
                                        java.lang.String actionName)
                                 throws XWorkException
Specified by:
handleUnknownAction in interface UnknownHandler
Throws:
XWorkException

findResource

protected ConventionUnknownHandler.Resource findResource(java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension,
                                                         java.lang.String... parts)
Finds a resource using the given path parts and all of the extensions in the map.

Parameters:
resultsByExtension - Map of extension to result type config objects.
parts - The parts of the resource.
Returns:
The resource path or null.

canonicalize

protected java.lang.String canonicalize(java.lang.String path)

buildActionConfig

protected ActionConfig buildActionConfig(java.lang.String path,
                                         ResultTypeConfig resultTypeConfig)

handleUnknownResult

public Result handleUnknownResult(ActionContext actionContext,
                                  java.lang.String actionName,
                                  ActionConfig actionConfig,
                                  java.lang.String resultCode)
                           throws XWorkException
Specified by:
handleUnknownResult in interface UnknownHandler
Throws:
XWorkException

findResult

protected Result findResult(java.lang.String path,
                            java.lang.String resultCode,
                            java.lang.String ext,
                            ActionContext actionContext,
                            java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)

buildResult

protected Result buildResult(java.lang.String path,
                             java.lang.String resultCode,
                             ResultTypeConfig config,
                             ActionContext invocationContext)

string

protected java.lang.String string(java.lang.String... parts)

determinePath

protected java.lang.String determinePath(ActionConfig actionConfig,
                                         java.lang.String namespace)
Determines the result path prefix that the request URL is for, minus the action name. This includes the base result location and the namespace, with all the slashes handled.

Parameters:
actionConfig - (Optional) The might be a ConventionActionConfig, from which we can get the default base result location of that specific action.
namespace - The current URL namespace.
Returns:
The path prefix and never null.

handleUnknownActionMethod

public java.lang.Object handleUnknownActionMethod(java.lang.Object action,
                                                  java.lang.String methodName)
                                           throws java.lang.NoSuchMethodException
Not used

Specified by:
handleUnknownActionMethod in interface UnknownHandler
Throws:
java.lang.NoSuchMethodException


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