public class DefaultResultMapBuilder extends 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 configured from resources are given a type corresponding to the resources extension. The extensions and types are given in the table below:
Extension | Type |
---|---|
.jsp | dispatcher |
.jspx | dispatcher |
.html | dispatcher |
.htm | dispatcher |
.vm | velocity |
.ftl | freemarker |
Modifier and Type | Class and Description |
---|---|
protected class |
DefaultResultMapBuilder.ResultInfo |
Constructor and Description |
---|
DefaultResultMapBuilder(javax.servlet.ServletContext servletContext,
Container container,
String relativeResultTypes)
Constructs the SimpleResultMapBuilder using the given result location.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addResult(Class<?> actionClass,
String path,
Map<String,ResultConfig> results,
PackageConfig packageConfig,
Map<String,ResultTypeConfig> resultsByExtension,
String resultKey)
Checks if result was already assigned, if not checks global results first and if exists, adds reference to it.
|
Map<String,ResultConfig> |
build(Class<?> actionClass,
Action annotation,
String actionName,
PackageConfig packageConfig)
Builds the result configurations given the action information.
|
protected void |
createFromAnnotations(Map<String,ResultConfig> resultConfigs,
String resultPath,
PackageConfig packageConfig,
Result[] results,
Class<?> actionClass,
Map<String,ResultTypeConfig> resultsByExtension) |
protected void |
createFromResources(Class<?> actionClass,
Map<String,ResultConfig> results,
String resultPath,
String resultPrefix,
String actionName,
PackageConfig packageConfig,
Map<String,ResultTypeConfig> resultsByExtension)
Creates any result types from the resources available in the web application.
|
protected ResultConfig |
createResultConfig(Class<?> actionClass,
DefaultResultMapBuilder.ResultInfo info,
PackageConfig packageConfig,
Result result)
Creates the result configuration for the single result annotation.
|
protected void |
createResultsFromAnnotations(Class<?> actionClass,
PackageConfig packageConfig,
String defaultResultPath,
Map<String,ResultConfig> results,
Map<String,ResultTypeConfig> resultsByExtension)
Creates results from @Results and @Result annotations
|
protected ClassLoaderInterface |
getClassLoaderInterface() |
protected void |
makeResults(Class<?> actionClass,
String path,
String resultPrefix,
Map<String,ResultConfig> results,
PackageConfig packageConfig,
Map<String,ResultTypeConfig> resultsByExtension)
Makes all the results for the given path.
|
void |
setFlatResultLayout(String flatResultLayout) |
public DefaultResultMapBuilder(javax.servlet.ServletContext servletContext, Container container, String relativeResultTypes)
servletContext
- The ServletContext for finding the resources of the web application.container
- The Xwork containerrelativeResultTypes
- 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.public void setFlatResultLayout(String flatResultLayout)
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}public Map<String,ResultConfig> build(Class<?> actionClass, Action annotation, String actionName, PackageConfig packageConfig)
build
in interface ResultMapBuilder
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.protected void createResultsFromAnnotations(Class<?> actionClass, PackageConfig packageConfig, String defaultResultPath, Map<String,ResultConfig> results, Map<String,ResultTypeConfig> resultsByExtension)
actionClass
- class to check for annotationspackageConfig
- packageConfig where the action will be locateddefaultResultPath
- default result pathresults
- map of resultsresultsByExtension
- map of result types keyed by extensionprotected void createFromResources(Class<?> actionClass, Map<String,ResultConfig> results, String resultPath, String resultPrefix, String actionName, PackageConfig packageConfig, Map<String,ResultTypeConfig> resultsByExtension)
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 determineresultsByExtension
- The map of extensions to result type configuration instances.protected ClassLoaderInterface getClassLoaderInterface()
protected void makeResults(Class<?> actionClass, String path, String resultPrefix, Map<String,ResultConfig> results, PackageConfig packageConfig, Map<String,ResultTypeConfig> resultsByExtension)
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.protected void addResult(Class<?> actionClass, String path, Map<String,ResultConfig> results, PackageConfig packageConfig, Map<String,ResultTypeConfig> resultsByExtension, String resultKey)
actionClass
- The action class the results are being built for.path
- The path to build the result for.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.resultKey
- The result name to useprotected void createFromAnnotations(Map<String,ResultConfig> resultConfigs, String resultPath, PackageConfig packageConfig, Result[] results, Class<?> actionClass, Map<String,ResultTypeConfig> resultsByExtension)
protected ResultConfig createResultConfig(Class<?> actionClass, DefaultResultMapBuilder.ResultInfo info, PackageConfig packageConfig, Result result)
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.Copyright © 2000–2020 Apache Software Foundation. All rights reserved.