org.apache.struts2.convention

## Class DefaultResultMapBuilder

- java.lang.Object
- - org.apache.struts2.convention.DefaultResultMapBuilder

- All Implemented Interfaces:
    ResultMapBuilder

      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:

  - The result config contains the location parameter, which is required by most result classes to figure out where to find the result. In addition, the config has all the parameters from the default result-type configuration.

  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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `DefaultResultMapBuilder.ResultInfo`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultResultMapBuilder(javax.servlet.ServletContext servletContext, Container container, String relativeResultTypes)` Constructs the SimpleResultMapBuilder using the given result location.

  - ### Method Summary

    Methods
    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)`

    - ### 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,
                                 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(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 Map<String,ResultConfig> build(Class<?> actionClass,
                                       Action annotation,
                                       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(Class<?> actionClass,
                                          PackageConfig packageConfig,
                                          String defaultResultPath,
                                          Map<String,ResultConfig> results,
                                          Map<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(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. 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(Class<?> actionClass,
                         String path,
                         String resultPrefix,
                         Map<String,ResultConfig> results,
                         PackageConfig packageConfig,
                         Map<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.

    - #### addResult

          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. If not, creates package specific result.
      Parameters:
        `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 use

    - #### createFromAnnotations

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

    - #### createResultConfig

          protected ResultConfig createResultConfig(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–2019 Apache Software Foundation. All rights reserved.