org.apache.struts2.convention
Class DefaultResultMapBuilder

java.lang.Object
  extended by org.apache.struts2.convention.DefaultResultMapBuilder
All Implemented Interfaces:
ResultMapBuilder

public class DefaultResultMapBuilder
extends java.lang.Object
implements ResultMapBuilder

This class implements the ResultMapBuilder and traverses the web application content directory looking for reasonably named JSPs and other result types as well as annotations. This naming is in this form:

 /resultPath/namespace/action-<result>.jsp
 

If there are any files in these locations than a result is created for each one and the result names is the last portion of the file name up to the . (dot).

When results are found, new ResultConfig instances are created. The result config that is created has a number of thing to be aware of:

After loading the files in the web application, this class will then use any annotations on the action class to override what was found in the web application files. These annotations are the Result and Results annotations. These two annotations allow an action to supply different or non-forward based results for specific return values of an action method.

The result path used by this class for locating JSPs and other such result files can be set using the Struts2 constant named struts.convention.result.path or using the ResultPath annotation.

This class will also locate and configure Results in the classpath, including velocity and FreeMarker templates inside the classpath.

All results that are conigured from resources are given a type corresponding to the resources extension. The extensions and types are given in the table below:

ExtensionType
.jspdispatcher
.jspxdispatcher
.htmldispatcher
.htmdispatcher
.vmvelocity
.ftlfreemarker


Nested Class Summary
protected  class DefaultResultMapBuilder.ResultInfo
           
 
Constructor Summary
DefaultResultMapBuilder(javax.servlet.ServletContext servletContext, Container container, java.lang.String relativeResultTypes)
          Constructs the SimpleResultMapBuilder using the given result location.
 
Method Summary
 java.util.Map<java.lang.String,ResultConfig> build(java.lang.Class<?> actionClass, Action annotation, java.lang.String actionName, PackageConfig packageConfig)
          Builds the result configurations given the action information.
protected  void createFromAnnotations(java.util.Map<java.lang.String,ResultConfig> resultConfigs, java.lang.String resultPath, PackageConfig packageConfig, Result[] results, java.lang.Class<?> actionClass, java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)
           
protected  void createFromResources(java.lang.Class<?> actionClass, java.util.Map<java.lang.String,ResultConfig> results, java.lang.String resultPath, java.lang.String resultPrefix, java.lang.String actionName, PackageConfig packageConfig, java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)
          Creates any result types from the resources available in the web application.
protected  ResultConfig createResultConfig(java.lang.Class<?> actionClass, DefaultResultMapBuilder.ResultInfo info, PackageConfig packageConfig, Result result)
          Creates the result configuration for the single result annotation.
protected  void createResultsFromAnnotations(java.lang.Class<?> actionClass, PackageConfig packageConfig, java.lang.String defaultResultPath, java.util.Map<java.lang.String,ResultConfig> results, java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)
          Creates results from @Results and @Result annotations
protected  ClassLoaderInterface getClassLoaderInterface()
           
protected  void makeResults(java.lang.Class<?> actionClass, java.lang.String path, java.lang.String resultPrefix, java.util.Map<java.lang.String,ResultConfig> results, PackageConfig packageConfig, java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)
          Makes all the results for the given path.
 void setFlatResultLayout(java.lang.String flatResultLayout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultResultMapBuilder

public DefaultResultMapBuilder(javax.servlet.ServletContext servletContext,
                               Container container,
                               java.lang.String relativeResultTypes)
Constructs the SimpleResultMapBuilder using the given result location.

Parameters:
servletContext - The ServletContext for finding the resources of the web application.
container - The Xwork container
relativeResultTypes - The list of result types that can have locations that are relative and the result location (which is the resultPath plus the namespace) prepended to them.
Method Detail

setFlatResultLayout

public void setFlatResultLayout(java.lang.String flatResultLayout)
Parameters:
flatResultLayout - If 'true' result resources will be expected to be in the form ${namespace}/${actionName}-${result}.${extension}, otherwise in the form ${namespace}/${actionName}/${result}.${extension}

build

public java.util.Map<java.lang.String,ResultConfig> build(java.lang.Class<?> actionClass,
                                                          Action annotation,
                                                          java.lang.String actionName,
                                                          PackageConfig packageConfig)
Builds the result configurations given the action information.

Specified by:
build in interface ResultMapBuilder
Parameters:
actionClass - The class of the action.
annotation - The action annotation.
actionName - The action name.
packageConfig - The package configuration that the action will be added to.
Returns:
The mapping of the result names to the result configurations. If there were none found than this should return an empty Map.

createResultsFromAnnotations

protected void createResultsFromAnnotations(java.lang.Class<?> actionClass,
                                            PackageConfig packageConfig,
                                            java.lang.String defaultResultPath,
                                            java.util.Map<java.lang.String,ResultConfig> results,
                                            java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)
Creates results from @Results and @Result annotations

Parameters:
actionClass - class to check for annotations
packageConfig - packageConfig where the action will be located
defaultResultPath - default result path
results - map of results
resultsByExtension - map of result types keyed by extension

createFromResources

protected void createFromResources(java.lang.Class<?> actionClass,
                                   java.util.Map<java.lang.String,ResultConfig> results,
                                   java.lang.String resultPath,
                                   java.lang.String resultPrefix,
                                   java.lang.String actionName,
                                   PackageConfig packageConfig,
                                   java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)
Creates any result types from the resources available in the web application. This scans the web application resources using the servlet context.

Parameters:
actionClass - The action class the results are being built for.
results - The results map to put the result configs created into.
resultPath - The calculated path to the resources.
resultPrefix - The prefix for the result. This is usually /resultPath/actionName.
actionName - The action name which is used only for logging in this implementation.
packageConfig - The package configuration which is passed along in order to determine
resultsByExtension - The map of extensions to result type configuration instances.

getClassLoaderInterface

protected ClassLoaderInterface getClassLoaderInterface()

makeResults

protected void makeResults(java.lang.Class<?> actionClass,
                           java.lang.String path,
                           java.lang.String resultPrefix,
                           java.util.Map<java.lang.String,ResultConfig> results,
                           PackageConfig packageConfig,
                           java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)
Makes all the results for the given path.

Parameters:
actionClass - The action class the results are being built for.
path - The path to build the result for.
resultPrefix - The is the result prefix which is the result location plus the action name. This is used to determine if the path contains a result code or not.
results - The Map to place the result(s)
packageConfig - The package config the results belong to.
resultsByExtension - The map of extensions to result type configuration instances.

createFromAnnotations

protected void createFromAnnotations(java.util.Map<java.lang.String,ResultConfig> resultConfigs,
                                     java.lang.String resultPath,
                                     PackageConfig packageConfig,
                                     Result[] results,
                                     java.lang.Class<?> actionClass,
                                     java.util.Map<java.lang.String,ResultTypeConfig> resultsByExtension)

createResultConfig

protected ResultConfig createResultConfig(java.lang.Class<?> actionClass,
                                          DefaultResultMapBuilder.ResultInfo info,
                                          PackageConfig packageConfig,
                                          Result result)
Creates the result configuration for the single result annotation. This will use all the information from the annotation and anything that isn't specified will be fetched from the PackageConfig defaults (if they exist).

Parameters:
actionClass - The action class the results are being built for.
info - The result info that is used to create the ResultConfig instance.
packageConfig - The PackageConfig to use to fetch defaults for result and parameters.
result - (Optional) The result annotation to pull additional information from.
Returns:
The ResultConfig or null if the Result annotation is given and the annotation is targeted to some other action than this one.


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