webwork/src/main/webwork/dispatcher DynamicViewMapping.java,1.1,1.2

[email protected]
Newsgroups gmane.comp.java.open-symphony.cvs
Message-ID <[email protected]>
Update of /cvsroot/opensymphony/webwork/src/main/webwork/dispatcher
In directory sc8-pr-cvs1:/tmp/cvs-serv1524/src/main/webwork/dispatcher

Modified Files:
	DynamicViewMapping.java 
Log Message:
Avoid creating an extra tokenizer, and more robust handling for multiple params.

Index: DynamicViewMapping.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/dispatcher/DynamicViewMapping.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- DynamicViewMapping.java	1 Jul 2003 13:45:11 -0000	1.1
+++ DynamicViewMapping.java	31 Oct 2003 01:01:39 -0000	1.2
@@ -15,7 +15,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import webwork.action.Action;
 import webwork.action.ActionContext;
 import webwork.config.Configuration;
 import webwork.util.ValueStack;
@@ -39,12 +38,12 @@
 {
    protected static Log log = LogFactory.getLog(DynamicViewMapping.class);
 
-   protected ViewMapping delegate;   
+   protected ViewMapping delegate;
    protected Map cache;
    protected String actionSuffix;
    protected String actionSuffixParam;
    protected final Object NULL_VIEW = new Object();
-   
+
    public DynamicViewMapping(ViewMapping aDelegate)
    {
       delegate = aDelegate;
@@ -55,12 +54,12 @@
       }
       catch(IllegalArgumentException iae)
       {
-         actionSuffix = ".action";	
+         actionSuffix = ".action";
          log.warn("Unable to find \'webwork.action.extension\' property setting. Defaulting to \'action\'");
       }
       actionSuffixParam = actionSuffix + "?";
    }
-   
+
    /**
     * Get view corresponding to given action and view name
     */
@@ -85,18 +84,18 @@
          return null;
       }
       String viewString = view.toString();
-      // If the viewString is null, just cache the view object and return      
+      // If the viewString is null, just cache the view object and return
       if (viewString == null)
       {
          cache.put(cacheKey, view);
          return view;
       }
-      
+
       // Check if the view contains any dynamic values and in that case look them up
       // dynamicView is null if it was not a dynamic view. Otherwise it is the view
       // after dynamic lookups has beem made
       String dynamicView = checkDynamicView(viewString);
-            
+
       if (dynamicView != null)
       {
          viewString = dynamicView;
@@ -109,7 +108,7 @@
       // If the view maps to an action with parameters
       if (actionIndex != -1)
       {
-        	String newActionName = viewString.substring(0, actionIndex); 
+        	String newActionName = viewString.substring(0, actionIndex);
          // The action has parameters, get the parameters as a Map
          Map parameters = getParams(viewString.substring(actionIndex + actionSuffixParam.length()));
          view = new ViewActionWrapper(newActionName, parameters);
@@ -117,7 +116,7 @@
       // Else check if view ends with an action suffix
       else if (viewString.endsWith(actionSuffix))
       {
-        	String newActionName = viewString.substring(0, viewString.length() - actionSuffix.length()); 
+        	String newActionName = viewString.substring(0, viewString.length() - actionSuffix.length());
          // The action has no parameters, just create the wrapper
          view = new ViewActionWrapper(newActionName);
       }
@@ -144,7 +143,7 @@
          return null;
       StringBuffer dynView = new StringBuffer(view.length() + 40);
       ValueStack stack = ActionContext.getValueStack();
-      int dynEnd = -1;
+      int dynEnd;
       int last = 0;
       do
       {
@@ -163,7 +162,7 @@
             dynView.append(view.substring(last, dynStart));
          dynView.append(valString);
          last = dynEnd + 1;
-         dynStart = view.indexOf("${", last);   		
+         dynStart = view.indexOf("${", last);
       }
       while(dynStart != -1);
       // If nothing appended there was no end brace and thus no dynamic expression
@@ -174,7 +173,7 @@
          dynView.append(view.substring(last));
       return dynView.toString();
    }
-   
+
    protected int getMatchingBrace(String view, int dynStart)
    {
       int depth = 0;
@@ -209,11 +208,14 @@
          Map params = new HashMap();
          while (stParams.hasMoreTokens()) {
              String nameValue = stParams.nextToken();
-             StringTokenizer stNameValuePairs = new StringTokenizer(nameValue, "=");
-             while (stNameValuePairs.hasMoreTokens()) {
-                 String name = stNameValuePairs.nextToken();
-                 String value = stNameValuePairs.nextToken();
-                 params.put(name, value);
+             int eq = nameValue.indexOf('=');
+             if(eq==-1) {
+               params.put(nameValue, "");
+             }
+             else {
+               String name = nameValue.substring(0, eq);
+               String value = nameValue.substring(eq+1, nameValue.length());
+               params.put(name, value);
              }
          }
          return params;




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.