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:
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 PrefixWith 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 -->
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 and Description |
---|
DefaultActionMapper() |
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) |
protected static final String METHOD_PREFIX
protected static final String ACTION_PREFIX
protected boolean allowDynamicMethodCalls
protected boolean allowSlashesInActionNames
protected boolean alwaysSelectFullNamespace
protected PrefixTrie prefixTrie
protected Pattern allowedNamespaceNames
protected String defaultNamespaceName
protected Pattern allowedActionNames
protected String defaultActionName
protected Pattern allowedMethodNames
protected String defaultMethodName
protected Container container
protected void addParameterAction(String prefix, ParameterAction parameterAction)
prefix
- The string prefix to trigger the actionparameterAction
- The parameter action to executepublic void setAllowDynamicMethodCalls(String enableDynamicMethodCalls)
public void setSlashesInActionNames(String enableSlashesInActionNames)
public void setAlwaysSelectFullNamespace(String alwaysSelectFullNamespace)
public void setAllowedNamespaceNames(String allowedNamespaceNames)
public void setDefaultNamespaceName(String defaultNamespaceName)
public void setAllowedActionNames(String allowedActionNames)
public void setDefaultActionName(String defaultActionName)
public void setAllowedMethodNames(String allowedMethodNames)
public void setDefaultMethodName(String defaultMethodName)
public void setAllowActionPrefix(String allowActionPrefix)
public void setAllowActionCrossNamespaceAccess(String allowActionCrossNamespaceAccess)
public void setContainer(Container container)
public void setExtensions(String extensions)
public ActionMapping getMappingFromActionName(String actionName)
ActionMapper
getMappingFromActionName
in interface ActionMapper
actionName
- The name of the action that may have other information embedded in itpublic boolean isSlashesInActionNames()
public ActionMapping getMapping(javax.servlet.http.HttpServletRequest request, ConfigurationManager configManager)
ActionMapper
getMapping
in interface ActionMapper
request
- The servlet requestconfigManager
- The current configuration managerprotected ActionMapping parseActionName(ActionMapping mapping)
public void handleSpecialParameters(javax.servlet.http.HttpServletRequest request, ActionMapping mapping)
request
- The requestmapping
- The action mappingprotected void parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager)
uri
- The urimapping
- The action mapping to populateconfigManager
- configuration managerprotected String cleanupNamespaceName(String rawNamespace)
rawNamespace
- name extracted from URIprotected String cleanupActionName(String rawActionName)
rawActionName
- action name extracted from URIprotected String cleanupMethodName(String rawMethodName)
rawMethodName
- method name extracted from URIprotected String dropExtension(String name, ActionMapping mapping)
name
- The action namemapping
- The action mapping to store the extension inprotected String getDefaultExtension()
public String getUriFromActionMapping(ActionMapping mapping)
ActionMapper
getUriFromActionMapping
in interface ActionMapper
mapping
- The action mappingprotected void handleNamespace(ActionMapping mapping, StringBuilder uri)
protected void handleName(ActionMapping mapping, StringBuilder uri)
protected void handleDynamicMethod(ActionMapping mapping, StringBuilder uri)
protected void handleExtension(ActionMapping mapping, StringBuilder uri)
protected void handleParams(ActionMapping mapping, StringBuilder uri)
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.