struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r911403 - /struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
Date Thu, 18 Feb 2010 13:52:47 GMT
Author: lukaszlenart
Date: Thu Feb 18 13:52:47 2010
New Revision: 911403

URL: http://svn.apache.org/viewvc?rev=911403&view=rev
Log:
Solved WW-3355 - handling empty action extensiomn in proper way

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java?rev=911403&r1=911402&r2=911403&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
Thu Feb 18 13:52:47 2010
@@ -21,67 +21,71 @@
 
 package org.apache.struts2.dispatcher.mapper;
 
-import java.util.*;
-
-import javax.servlet.http.HttpServletRequest;
-
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.inject.Inject;
 import org.apache.struts2.RequestUtils;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.dispatcher.ServletRedirectResult;
 import org.apache.struts2.util.PrefixTrie;
 
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.config.Configuration;
-import com.opensymphony.xwork2.config.ConfigurationManager;
-import com.opensymphony.xwork2.config.entities.PackageConfig;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.inject.Container;
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * <!-- START SNIPPET: javadoc -->
- *
+ * <p/>
  * Default action mapper implementation, using the standard *.[ext] (where ext
  * usually "action") pattern. The extension is looked up from the Struts
  * configuration key <b>struts.action.extension</b>.
- *
+ * <p/>
  * <p/> To help with dealing with buttons and other related requirements, this
  * mapper (and other {@link 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:
- *
+ * <p/>
  * <ul>
- *
+ * <p/>
  * <li>Method prefix - <i>method:default</i></li>
- *
+ * <p/>
  * <li>Action prefix - <i>action:dashboard</i></li>
- *
+ * <p/>
  * <li>Redirect prefix - <i>redirect:cancel.jsp</i></li>
- *
+ * <p/>
  * <li>Redirect-action prefix - <i>redirectAction:cancel</i></li>
- *
+ * <p/>
  * </ul>
- *
+ * <p/>
  * <p/> In addition to these four prefixes, this mapper also understands the
  * action naming pattern of <i>foo!bar</i> 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 <i>foo</i> and the method <i>bar</i>.
- *
+ * <p/>
  * <!-- END SNIPPET: javadoc -->
- *
+ * <p/>
  * <p/> <b>Method Prefix</b> <p/>
- *
+ * <p/>
  * <!-- START SNIPPET: method -->
- *
+ * <p/>
  * 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.
- *
+ * <p/>
  * <!-- END SNIPPET: method -->
- *
+ * <p/>
  * <pre>
  *  &lt;!-- START SNIPPET: method-example --&gt;
  *  &lt;s:form action=&quot;baz&quot;&gt;
@@ -91,18 +95,18 @@
  *  &lt;/s:form&gt;
  *  &lt;!-- END SNIPPET: method-example --&gt;
  * </pre>
- *
+ * <p/>
  * <p/> <b>Action prefix</b> <p/>
- *
+ * <p/>
  * <!-- START SNIPPET: action -->
- *
+ * <p/>
  * With action-prefix, instead of executing baz action's execute() method (by
  * default if it isn't overriden in struts.xml to be something else), the
  * anotherAction action's execute() method (assuming again if it isn't overriden
  * with something else in struts.xml) will be executed.
- *
+ * <p/>
  * <!-- END SNIPPET: action -->
- *
+ * <p/>
  * <pre>
  *  &lt;!-- START SNIPPET: action-example --&gt;
  *  &lt;s:form action=&quot;baz&quot;&gt;
@@ -112,18 +116,18 @@
  *  &lt;/s:form&gt;
  *  &lt;!-- END SNIPPET: action-example --&gt;
  * </pre>
- *
+ * <p/>
  * <p/> <b>Redirect prefix</b> <p/>
- *
+ * <p/>
  * <!-- START SNIPPET: redirect -->
- *
+ * <p/>
  * With redirect-prefix, instead of executing baz action's execute() method (by
  * default it isn't overriden in struts.xml to be something else), it will get
  * redirected to, in this case to www.google.com. Internally it uses
  * ServletRedirectResult to do the task.
- *
+ * <p/>
  * <!-- END SNIPPET: redirect -->
- *
+ * <p/>
  * <pre>
  *  &lt;!-- START SNIPPET: redirect-example --&gt;
  *  &lt;s:form action=&quot;baz&quot;&gt;
@@ -133,19 +137,19 @@
  *  &lt;/s:form&gt;
  *  &lt;!-- END SNIPPET: redirect-example --&gt;
  * </pre>
- *
+ * <p/>
  * <p/> <b>Redirect-action prefix</b> <p/>
- *
+ * <p/>
  * <!-- START SNIPPET: redirect-action -->
- *
+ * <p/>
  * With redirect-action-prefix, instead of executing baz action's execute()
  * method (by default it isn't overriden in struts.xml to be something else), it
  * will get redirected to, in this case 'dashboard.action'. Internally it uses
  * ServletRedirectResult to do the task and read off the extension from the
  * struts.properties.
- *
+ * <p/>
  * <!-- END SNIPPET: redirect-action -->
- *
+ * <p/>
  * <pre>
  *  &lt;!-- START SNIPPET: redirect-action-example --&gt;
  *  &lt;s:form action=&quot;baz&quot;&gt;
@@ -155,7 +159,6 @@
  *  &lt;/s:form&gt;
  *  &lt;!-- END SNIPPET: redirect-action-example --&gt;
  * </pre>
- *
  */
 public class DefaultActionMapper implements ActionMapper {
 
@@ -175,7 +178,10 @@
 
     protected PrefixTrie prefixTrie = null;
 
-    protected List<String> extensions = new ArrayList<String>() {{ add("action");
add("");}};
+    protected List<String> extensions = new ArrayList<String>() {{
+        add("action");
+        add("");
+    }};
 
     protected Container container;
 
@@ -186,7 +192,7 @@
                     public void execute(String key, ActionMapping mapping) {
                         if (allowDynamicMethodCalls) {
                             mapping.setMethod(key.substring(
-                                                   METHOD_PREFIX.length()));
+                                    METHOD_PREFIX.length()));
                         }
                     }
                 });
@@ -237,10 +243,10 @@
     /**
      * Adds a parameter action.  Should only be called during initialization
      *
-     * @param prefix The string prefix to trigger the action
+     * @param prefix          The string prefix to trigger the action
      * @param parameterAction The parameter action to execute
      * @since 2.1.0
-    */
+     */
     protected void addParameterAction(String prefix, ParameterAction parameterAction) {
         prefixTrie.put(prefix, parameterAction);
     }
@@ -293,8 +299,9 @@
      *
      * @see org.apache.struts2.dispatcher.mapper.ActionMapper#getMapping(javax.servlet.http.HttpServletRequest)
      */
+
     public ActionMapping getMapping(HttpServletRequest request,
-            ConfigurationManager configManager) {
+                                    ConfigurationManager configManager) {
         ActionMapping mapping = new ActionMapping();
         String uri = getUri(request);
 
@@ -339,13 +346,11 @@
      * Special parameters, as described in the class-level comment, are searched
      * for and handled.
      *
-     * @param request
-     *            The request
-     * @param mapping
-     *            The action mapping
+     * @param request The request
+     * @param mapping The action mapping
      */
     public void handleSpecialParameters(HttpServletRequest request,
-            ActionMapping mapping) {
+                                        ActionMapping mapping) {
         // handle special parameter prefixes.
         Set<String> uniqueParameters = new HashSet<String>();
         Map parameterMap = request.getParameterMap();
@@ -357,7 +362,7 @@
             if (key.endsWith(".x") || key.endsWith(".y")) {
                 key = key.substring(0, key.length() - 2);
             }
-            
+
             // Ensure a parameter doesn't get processed twice
             if (!uniqueParameters.contains(key)) {
                 ParameterAction parameterAction = (ParameterAction) prefixTrie
@@ -374,13 +379,11 @@
     /**
      * Parses the name and namespace from the uri
      *
-     * @param uri
-     *            The uri
-     * @param mapping
-     *            The action mapping to populate
+     * @param uri     The uri
+     * @param mapping The action mapping to populate
      */
     protected void parseNameAndNamespace(String uri, ActionMapping mapping,
-            ConfigurationManager configManager) {
+                                         ConfigurationManager configManager) {
         String namespace, name;
         int lastSlash = uri.lastIndexOf("/");
         if (lastSlash == -1) {
@@ -437,8 +440,7 @@
     /**
      * Drops the extension from the action name
      *
-     * @param name
-     *            The action name
+     * @param name The action name
      * @return The action name without its extension
      * @deprecated Since 2.1, use {@link #dropExtension(java.lang.String,org.apache.struts2.dispatcher.mapper.ActionMapping)}
instead
      */
@@ -449,8 +451,7 @@
     /**
      * Drops the extension from the action name, storing it in the mapping for later use
      *
-     * @param name
-     *            The action name
+     * @param name    The action name
      * @param mapping The action mapping to store the extension in
      * @return The action name without its extension
      */
@@ -493,8 +494,7 @@
     /**
      * Gets the uri from the request
      *
-     * @param request
-     *            The request
+     * @param request The request
      * @return The uri
      */
     protected String getUri(HttpServletRequest request) {
@@ -519,6 +519,7 @@
      *
      * @see org.apache.struts2.dispatcher.mapper.ActionMapper#getUriFromActionMapping(org.apache.struts2.dispatcher.mapper.ActionMapping)
      */
+
     public String getUriFromActionMapping(ActionMapping mapping) {
         StringBuilder uri = new StringBuilder();
 
@@ -542,7 +543,6 @@
 
         String extension = mapping.getExtension();
         if (extension == null) {
-            extension = getDefaultExtension();
             // Look for the current extension, if available
             ActionContext context = ActionContext.getContext();
             if (context != null) {
@@ -551,26 +551,28 @@
                     extension = orig.getExtension();
                 }
             }
+            if (extension == null) {
+                extension = getDefaultExtension();
+            }
         }
 
         if (extension != null) {
-
             if (extension.length() == 0 || (extension.length() > 0 && uri.indexOf('.'
+ extension) == -1)) {
                 if (extension.length() > 0) {
                     uri.append(".").append(extension);
                 }
-                if (params.length() > 0) {
-                    uri.append(params);
-                }
             }
         }
+        if (params.length() > 0) {
+            uri.append(params);
+        }
 
         return uri.toString();
     }
 
 
-	public boolean isSlashesInActionNames() {
-		return allowSlashesInActionNames;
-	}
+    public boolean isSlashesInActionNames() {
+        return allowSlashesInActionNames;
+    }
 
 }



Mime
View raw message