org.apache.struts2.dispatcher.mapper

## Class DefaultActionMapper

- java.lang.Object
- - org.apache.struts2.dispatcher.mapper.DefaultActionMapper

- All Implemented Interfaces:
    ActionMapper
  Direct Known Subclasses:
    PrefixBasedActionMapper, Restful2ActionMapper

      public class DefaultActionMapper
      extends Object
      implements ActionMapper

  Default action mapper implementation, using the standard *.[ext] (where ext usually "action") pattern. The extension is looked up from the Struts configuration key struts.action.extension.

  To help with dealing with buttons and other related requirements, this mapper (and other `ActionMapper`s, we hope) has the ability to name a button with some predefined prefix and have that button name alter the execution behaviour. The four prefixes are:

  - Method prefix - method:default
  - Action prefix - action:dashboard

  In addition to these four prefixes, this mapper also understands the action naming pattern of foo!bar in either the extension form (eg: foo!bar.action) or in the prefix form (eg: action:foo!bar). This syntax tells this mapper to map to the action named foo and the method bar.

  Method Prefix

  With method-prefix, instead of calling baz action's execute() method (by default if it isn't overriden in struts.xml to be something else), the baz action's anotherMethod() will be called. A very elegant way determine which button is clicked. Alternatively, one would have submit button set a particular value on the action when clicked, and the execute() method decides on what to do with the setted value depending on which button is clicked.

        <!-- START SNIPPET: method-example -->
        <s:form action="baz">
            <s:textfield label="Enter your name" name="person.name"/>
            <s:submit value="Create person"/>
            <s:submit method="anotherMethod" value="Cancel"/>
        </s:form>
        <!-- END SNIPPET: method-example -->

  Action prefix

  With action-prefix, instead of executing baz action's execute() method (by default if it isn't overridden in struts.xml to be something else), the anotherAction action's execute() method (assuming again if it isn't overridden with something else in struts.xml) will be executed.

        <!-- START SNIPPET: action-example -->
        <s:form action="baz">
            <s:textfield label="Enter your name" name="person.name"/>
            <s:submit value="Create person"/>
            <s:submit action="anotherAction" value="Cancel"/>
        </s:form>
        <!-- END SNIPPET: action-example -->

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String` | `ACTION_PREFIX`
    `protected boolean` | `allowDynamicMethodCalls`
    `protected Pattern` | `allowedActionNames`
    `protected Pattern` | `allowedMethodNames`
    `protected Pattern` | `allowedNamespaceNames`
    `protected boolean` | `allowSlashesInActionNames`
    `protected boolean` | `alwaysSelectFullNamespace`
    `protected Container` | `container`
    `protected String` | `defaultActionName`
    `protected String` | `defaultMethodName`
    `protected String` | `defaultNamespaceName`
    `protected List<String>` | `extensions`
    `protected static String` | `METHOD_PREFIX`
    `protected PrefixTrie` | `prefixTrie`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultActionMapper()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addParameterAction(String prefix, ParameterAction parameterAction)` Adds a parameter action.
    `protected String` | `cleanupActionName(String rawActionName)` Checks action name against allowed pattern if not matched returns default action name
    `protected String` | `cleanupMethodName(String rawMethodName)` Checks method name (when DMI is enabled) against allowed pattern if not matched returns default action name
    `protected String` | `cleanupNamespaceName(String rawNamespace)` Checks namespace name against allowed pattern if not matched returns default namespace
    `protected String` | `dropExtension(String name, ActionMapping mapping)` Drops the extension from the action name, storing it in the mapping for later use
    `protected String` | `getDefaultExtension()`
    `ActionMapping` | `getMapping(javax.servlet.http.HttpServletRequest request, ConfigurationManager configManager)` Expose the ActionMapping for the current request
    `ActionMapping` | `getMappingFromActionName(String actionName)` Expose the ActionMapping for the specified action name
    `String` | `getUriFromActionMapping(ActionMapping mapping)` Convert an ActionMapping into a URI string
    `protected void` | `handleDynamicMethod(ActionMapping mapping, StringBuilder uri)`
    `protected void` | `handleExtension(ActionMapping mapping, StringBuilder uri)`
    `protected void` | `handleName(ActionMapping mapping, StringBuilder uri)`
    `protected void` | `handleNamespace(ActionMapping mapping, StringBuilder uri)`
    `protected void` | `handleParams(ActionMapping mapping, StringBuilder uri)`
    `void` | `handleSpecialParameters(javax.servlet.http.HttpServletRequest request, ActionMapping mapping)` Special parameters, as described in the class-level comment, are searched for and handled.
    `boolean` | `isSlashesInActionNames()`
    `protected String` | `lookupExtension(String extension)`
    `protected ActionMapping` | `parseActionName(ActionMapping mapping)`
    `protected void` | `parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager)` Parses the name and namespace from the uri
    `void` | `setAllowActionCrossNamespaceAccess(String allowActionCrossNamespaceAccess)`
    `void` | `setAllowActionPrefix(String allowActionPrefix)`
    `void` | `setAllowDynamicMethodCalls(String enableDynamicMethodCalls)`
    `void` | `setAllowedActionNames(String allowedActionNames)`
    `void` | `setAllowedMethodNames(String allowedMethodNames)`
    `void` | `setAllowedNamespaceNames(String allowedNamespaceNames)`
    `void` | `setAlwaysSelectFullNamespace(String alwaysSelectFullNamespace)`
    `void` | `setContainer(Container container)`
    `void` | `setDefaultActionName(String defaultActionName)`
    `void` | `setDefaultMethodName(String defaultMethodName)`
    `void` | `setDefaultNamespaceName(String defaultNamespaceName)`
    `void` | `setExtensions(String extensions)`
    `void` | `setSlashesInActionNames(String enableSlashesInActionNames)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### METHOD_PREFIX

          protected static final String METHOD_PREFIX

      See Also:
        Constant Field Values

    - #### ACTION_PREFIX

          protected static final String ACTION_PREFIX

      See Also:
        Constant Field Values

    - #### allowDynamicMethodCalls

          protected boolean allowDynamicMethodCalls

    - #### allowSlashesInActionNames

          protected boolean allowSlashesInActionNames

    - #### alwaysSelectFullNamespace

          protected boolean alwaysSelectFullNamespace

    - #### prefixTrie

          protected PrefixTrie prefixTrie

    - #### allowedNamespaceNames

          protected Pattern allowedNamespaceNames

    - #### defaultNamespaceName

          protected String defaultNamespaceName

    - #### allowedActionNames

          protected Pattern allowedActionNames

    - #### defaultActionName

          protected String defaultActionName

    - #### allowedMethodNames

          protected Pattern allowedMethodNames

    - #### defaultMethodName

          protected String defaultMethodName

    - #### extensions

          protected List<String> extensions

    - #### container

          protected Container container

  - ### Constructor Detail

    - #### DefaultActionMapper

          public DefaultActionMapper()

  - ### Method Detail

    - #### addParameterAction

          protected void addParameterAction(String prefix,
                                ParameterAction parameterAction)

      Adds a parameter action. Should only be called during initialization
      Parameters:
        `prefix` - The string prefix to trigger the action
        `parameterAction` - The parameter action to execute
      Since:
        2.1.0

    - #### setAllowDynamicMethodCalls

          public void setAllowDynamicMethodCalls(String enableDynamicMethodCalls)

    - #### setSlashesInActionNames

          public void setSlashesInActionNames(String enableSlashesInActionNames)

    - #### setAlwaysSelectFullNamespace

          public void setAlwaysSelectFullNamespace(String alwaysSelectFullNamespace)

    - #### setAllowedNamespaceNames

          public void setAllowedNamespaceNames(String allowedNamespaceNames)

    - #### setDefaultNamespaceName

          public void setDefaultNamespaceName(String defaultNamespaceName)

    - #### setAllowedActionNames

          public void setAllowedActionNames(String allowedActionNames)

    - #### setDefaultActionName

          public void setDefaultActionName(String defaultActionName)

    - #### setAllowedMethodNames

          public void setAllowedMethodNames(String allowedMethodNames)

    - #### setDefaultMethodName

          public void setDefaultMethodName(String defaultMethodName)

    - #### setAllowActionPrefix

          public void setAllowActionPrefix(String allowActionPrefix)

    - #### setAllowActionCrossNamespaceAccess

          public void setAllowActionCrossNamespaceAccess(String allowActionCrossNamespaceAccess)

    - #### setContainer

          public void setContainer(Container container)

    - #### setExtensions

          public void setExtensions(String extensions)

    - #### getMappingFromActionName

          public ActionMapping getMappingFromActionName(String actionName)

      Description copied from interface: `ActionMapper`
      Expose the ActionMapping for the specified action name
      Specified by:
        `getMappingFromActionName` in interface `ActionMapper`
      Parameters:
        `actionName` - The name of the action that may have other information embedded in it
      Returns:
        The appropriate action mapping

    - #### isSlashesInActionNames

          public boolean isSlashesInActionNames()

    - #### getMapping

          public ActionMapping getMapping(javax.servlet.http.HttpServletRequest request,
                                 ConfigurationManager configManager)

      Description copied from interface: `ActionMapper`
      Expose the ActionMapping for the current request
      Specified by:
        `getMapping` in interface `ActionMapper`
      Parameters:
        `request` - The servlet request
        `configManager` - The current configuration manager
      Returns:
        The appropriate action mapping or null if mapping cannot be determined

    - #### parseActionName

          protected ActionMapping parseActionName(ActionMapping mapping)

    - #### handleSpecialParameters

          public void handleSpecialParameters(javax.servlet.http.HttpServletRequest request,
                                     ActionMapping mapping)

      Special parameters, as described in the class-level comment, are searched for and handled.
      Parameters:
        `request` - The request
        `mapping` - The action mapping

    - #### parseNameAndNamespace

          protected void parseNameAndNamespace(String uri,
                                   ActionMapping mapping,
                                   ConfigurationManager configManager)

      Parses the name and namespace from the uri
      Parameters:
        `uri` - The uri
        `mapping` - The action mapping to populate
        `configManager` - configuration manager

    - #### cleanupNamespaceName

          protected String cleanupNamespaceName(String rawNamespace)

      Checks namespace name against allowed pattern if not matched returns default namespace
      Parameters:
        `rawNamespace` - name extracted from URI
      Returns:
        safe namespace name

    - #### cleanupActionName

          protected String cleanupActionName(String rawActionName)

      Checks action name against allowed pattern if not matched returns default action name
      Parameters:
        `rawActionName` - action name extracted from URI
      Returns:
        safe action name

    - #### cleanupMethodName

          protected String cleanupMethodName(String rawMethodName)

      Checks method name (when DMI is enabled) against allowed pattern if not matched returns default action name
      Parameters:
        `rawMethodName` - method name extracted from URI
      Returns:
        safe method name

    - #### dropExtension

          protected String dropExtension(String name,
                             ActionMapping mapping)

      Drops the extension from the action name, storing it in the mapping for later use
      Parameters:
        `name` - The action name
        `mapping` - The action mapping to store the extension in
      Returns:
        The action name without its extension

    - #### getDefaultExtension

          protected String getDefaultExtension()

      Returns:
        null if no extension is specified.

    - #### getUriFromActionMapping

          public String getUriFromActionMapping(ActionMapping mapping)

      Description copied from interface: `ActionMapper`
      Convert an ActionMapping into a URI string
      Specified by:
        `getUriFromActionMapping` in interface `ActionMapper`
      Parameters:
        `mapping` - The action mapping
      Returns:
        The URI string that represents this mapping

    - #### handleNamespace

          protected void handleNamespace(ActionMapping mapping,
                             StringBuilder uri)

    - #### handleName

          protected void handleName(ActionMapping mapping,
                        StringBuilder uri)

    - #### handleDynamicMethod

          protected void handleDynamicMethod(ActionMapping mapping,
                                 StringBuilder uri)

    - #### handleExtension

          protected void handleExtension(ActionMapping mapping,
                             StringBuilder uri)

    - #### lookupExtension

          protected String lookupExtension(String extension)

    - #### handleParams

          protected void handleParams(ActionMapping mapping,
                          StringBuilder uri)

Copyright © 2000–2019 Apache Software Foundation. All rights reserved.