Commits

Anonymous committed bf9080e

xwork support

Comments (0)

Files changed (2)

lib/optional/xwork-1.0-beta2.jar

Binary file added.

src/java/com/opensymphony/workflow/util/XWorkExecutor.java

+package com.opensymphony.workflow.util;
+
+import com.opensymphony.module.propertyset.PropertySet;
+import com.opensymphony.workflow.FunctionProvider;
+import com.opensymphony.workflow.WorkflowException;
+import com.opensymphony.xwork.ActionContext;
+import com.opensymphony.xwork.ActionProxy;
+import com.opensymphony.xwork.ActionProxyFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Executes an XWork function The following conversion is done:
+ * <ul>
+ *  <li>inputs -> ActionContext#parameters</li>
+ *  <li>variables -> ActionContext#session</li>
+ *  <li>args -> ActionContext#application</li>
+ * </ul>
+ * <p>
+ *
+ * <ul>
+ *  <li><b>action.name</b> - the actionName to ask from the ActionProxy</li>
+ *  <li><b>namespace</b> - the namespace to ask from the ActionProxy</li>
+ * </ul>
+ */
+public class XWorkExecutor implements FunctionProvider {
+    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
+        String actionName = (String) args.get("action.name");
+        String namespace = (String) args.get("namespace.name");
+
+        Map extraContext = new HashMap();
+        extraContext.put(ActionContext.APPLICATION, args);
+        extraContext.put(ActionContext.SESSION, ps.getProperties(""));
+        extraContext.put(ActionContext.LOCALE, Locale.getDefault());
+
+        Map params = new HashMap(transientVars);
+        params.putAll(args);
+        extraContext.put(ActionContext.PARAMETERS, Collections.unmodifiableMap(params));
+
+        try {
+            ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext, false);
+            proxy.execute();
+        } catch (Exception e) {
+            throw new WorkflowException("Could not execute action " + actionName, e);
+        }
+    }
+}