1 5 package org.infoglue.cms.util.workflow; 6 7 import java.security.Principal ; 8 import java.util.Collections ; 9 import java.util.HashMap ; 10 import java.util.Locale ; 11 import java.util.Map ; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 16 import webwork.action.ActionContext; 17 import webwork.dispatcher.GenericDispatcher; 18 19 import com.opensymphony.module.propertyset.PropertySet; 20 import com.opensymphony.workflow.FunctionProvider; 21 import com.opensymphony.workflow.WorkflowContext; 22 import com.opensymphony.workflow.WorkflowException; 23 24 25 39 public class WebWorkExecutor implements FunctionProvider 40 { 41 43 private static final Log log = LogFactory.getLog(WebWorkExecutor.class); 44 45 47 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException 48 { 49 final WorkflowContext wfContext = (WorkflowContext) transientVars.get("context"); 50 51 String actionName = (String ) args.get("action.name"); 52 GenericDispatcher gd = new GenericDispatcher(actionName); 53 gd.prepareContext(); 54 55 ActionContext.setPrincipal(new Principal () { 56 public String getName() { 57 return wfContext.getCaller(); 58 } 59 }); 60 ActionContext.setApplication(args); 61 ActionContext.setSession(ps.getProperties("")); 62 ActionContext.setLocale(Locale.getDefault()); 63 64 Map params = new HashMap (transientVars); 65 params.putAll(args); 66 ActionContext.setParameters(Collections.unmodifiableMap(params)); 67 68 try { 69 gd.prepareContext(); 70 gd.prepareValueStack(); 71 gd.executeAction(); 72 gd.finish(); 73 gd.finalizeContext(); 74 } catch (Exception e) { 75 throw new WorkflowException("Could not execute action " + actionName, e); 76 } 77 } 78 } | Popular Tags |