Commits

Anonymous committed a72f310

ActionChainResult evaluates namespace and action name properties (can't find Jira issue right now)

Also, some Java 1.3 fixes... new MessageFormat(string, locale) wasn't there until 1.4, and neither was Boolean.valueOf(boolean).

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@324e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 6d89d3c

Comments (0)

Files changed (5)

File src/java/com/opensymphony/xwork/ActionChainResult.java

 package com.opensymphony.xwork;
 
 import com.opensymphony.xwork.interceptor.component.ComponentInterceptor;
+import com.opensymphony.xwork.util.OgnlValueStack;
+import com.opensymphony.xwork.util.TextParseUtil;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
      * @param invocation the DefaultActionInvocation calling the action call stack
      */
     public void execute(ActionInvocation invocation) throws Exception {
-        if (isInChainHistory(namespace, actionName)) {
+        // if the finalNamespace wasn't explicitly defined, assume the current one
+        if (this.namespace == null) {
+            this.namespace = invocation.getProxy().getNamespace();
+        }
+
+        OgnlValueStack stack = ActionContext.getContext().getValueStack();
+        String finalNamespace = TextParseUtil.translateVariables(namespace, stack);
+        String finalActionName = TextParseUtil.translateVariables(actionName, stack);
+
+        if (isInChainHistory(finalNamespace, finalActionName)) {
             throw new XworkException("infinite recursion detected");
         }
 
-        addToHistory(namespace, actionName);
+        addToHistory(finalNamespace, finalActionName);
 
         HashMap extraContext = new HashMap();
         extraContext.put(ActionContext.VALUE_STACK, ActionContext.getContext().getValueStack());
         extraContext.put(CHAIN_HISTORY, ActionContext.getContext().get(CHAIN_HISTORY));
 
         if (log.isDebugEnabled()) {
-            log.debug("Chaining to action " + actionName);
-        }
-
-        // if the namespace wasn't explicitly defined, assume the current one
-        if (this.namespace == null) {
-            this.namespace = invocation.getProxy().getNamespace();
+            log.debug("Chaining to action " + finalActionName);
         }
 
-        proxy = ActionProxyFactory.getFactory().createActionProxy(this.namespace, actionName, extraContext);
+        proxy = ActionProxyFactory.getFactory().createActionProxy(finalNamespace, finalActionName, extraContext);
         proxy.execute();
     }
 

File src/java/com/opensymphony/xwork/util/LocalizedTextUtil.java

      * @throws MissingResourceException if no message can be found for the specified key
      */
     public static String findDefaultText(String aTextName, Locale locale, Object[] params) throws MissingResourceException {
-        MessageFormat mf = new MessageFormat(findDefaultText(aTextName, locale), locale);
+        MessageFormat mf = buildMessageFormat(findDefaultText(aTextName, locale), locale);
 
         return mf.format(params);
     }
             reloadBundles(bundle);
 
             String message = TextParseUtil.translateVariables(bundle.getString(aTextName), valueStack);
-            MessageFormat mf = new MessageFormat(message, locale);
+            MessageFormat mf = buildMessageFormat(message, locale);
 
             return mf.format(args);
         } catch (MissingResourceException ex) {
 
             // defaultMessage may be null
             if (message != null) {
-                MessageFormat mf = new MessageFormat(TextParseUtil.translateVariables(message, valueStack), locale);
+                MessageFormat mf = buildMessageFormat(TextParseUtil.translateVariables(message, valueStack), locale);
 
                 return mf.format(args);
             }
 
             String message = TextParseUtil.translateVariables(bundle.getString(key), valueStack);
 
-            MessageFormat mf = new MessageFormat(message, locale);
+            MessageFormat mf = buildMessageFormat(message, locale);
 
             return mf.format(args);
         } catch (MissingResourceException ex) {
         }
     }
 
+    private static MessageFormat buildMessageFormat(String pattern, Locale locale) {
+        MessageFormat format = new MessageFormat(pattern);
+        format.setLocale(locale);
+
+        return format;
+    }
+
     /**
      * Traverse up class hierarchy looking for message.  Looks at class, then implemented interface,
      * before going up hierarchy.

File src/java/com/opensymphony/xwork/util/OgnlValueStack.java

 
         try {
             context.put(XWorkConverter.CONVERSION_PROPERTY_FULLNAME, expr);
-            context.put(REPORT_ERRORS_ON_NO_PROP, Boolean.valueOf(throwExceptionOnFailure));
+            context.put(REPORT_ERRORS_ON_NO_PROP, new Boolean(throwExceptionOnFailure));
             OgnlUtil.setValue(expr, context, root, value);
         } catch (OgnlException e) {
             // ignore

File src/java/com/opensymphony/xwork/util/XWorkBasicConverter.java

             List intArray = new ArrayList(x.length);
 
             for (int i = 0; i < x.length; i++) {
-                intArray.add(Boolean.valueOf(x[i]));
+                intArray.add(new Boolean(x[i]));
             }
 
             result = TextUtils.join(", ", intArray);

File src/test/com/opensymphony/xwork/ChainResultTest.java

  */
 package com.opensymphony.xwork;
 
+import com.mockobjects.dynamic.Mock;
+
 import com.opensymphony.xwork.config.ConfigurationManager;
+import com.opensymphony.xwork.util.OgnlValueStack;
 
 import junit.framework.TestCase;
 
+import java.util.HashMap;
+import java.util.Map;
+
 
 /**
  * @author CameronBraid
 public class ChainResultTest extends TestCase {
     //~ Methods ////////////////////////////////////////////////////////////////
 
+    public void testNamespaceAndActionExpressionEvaluation() throws Exception {
+        ActionChainResult result = new ActionChainResult();
+        result.setActionName("${actionName}");
+        result.setNamespace("${namespace}");
+
+        String expectedActionName = "testActionName";
+        String expectedNamespace = "testNamespace";
+        Map values = new HashMap();
+        values.put("actionName", expectedActionName);
+        values.put("namespace", expectedNamespace);
+
+        OgnlValueStack stack = new OgnlValueStack();
+        stack.push(values);
+
+        Mock actionProxyMock = new Mock(ActionProxy.class);
+        actionProxyMock.expect("execute");
+
+        ActionProxyFactory testActionProxyFactory = new NamespaceActionNameTestActionProxyFactory(expectedNamespace, expectedActionName, (ActionProxy) actionProxyMock.proxy());
+
+        try {
+            ActionProxyFactory.setFactory(testActionProxyFactory);
+
+            ActionContext testContext = new ActionContext(stack.getContext());
+            ActionContext.setContext(testContext);
+            result.execute(null);
+            actionProxyMock.verify();
+        } finally {
+            ActionProxyFactory.setFactory(new DefaultActionProxyFactory());
+            ActionContext.setContext(null);
+        }
+    }
+
     public void testRecursiveChain() throws Exception {
         ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", "InfiniteRecursionChain", null);
 
         ConfigurationManager.clearConfigurationProviders();
         ConfigurationManager.getConfiguration().reload();
     }
+
+    //~ Inner Classes //////////////////////////////////////////////////////////
+
+    private class NamespaceActionNameTestActionProxyFactory extends ActionProxyFactory {
+        private ActionProxy returnVal;
+        private String expectedActionName;
+        private String expectedNamespace;
+
+        public NamespaceActionNameTestActionProxyFactory(String expectedNamespace, String expectedActionName, ActionProxy returnVal) {
+            this.expectedNamespace = expectedNamespace;
+            this.expectedActionName = expectedActionName;
+            this.returnVal = returnVal;
+        }
+
+        public ActionInvocation createActionInvocation(ActionProxy actionProxy, Map extraContext) throws Exception {
+            return null;
+        }
+
+        public ActionInvocation createActionInvocation(ActionProxy actionProxy) throws Exception {
+            return null;
+        }
+
+        public ActionInvocation createActionInvocation(ActionProxy actionProxy, Map extraContext, boolean pushAction) throws Exception {
+            return null;
+        }
+
+        public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext) throws Exception {
+            TestCase.assertEquals(expectedNamespace, namespace);
+            TestCase.assertEquals(expectedActionName, actionName);
+
+            return returnVal;
+        }
+
+        public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext, boolean executeResult) throws Exception {
+            TestCase.assertEquals(expectedNamespace, namespace);
+            TestCase.assertEquals(expectedActionName, actionName);
+
+            return returnVal;
+        }
+    }
 }