KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > workflow > commands > FlowCommand


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.module.workflow.commands;
14
15 import info.magnolia.cms.util.FactoryUtil;
16 import info.magnolia.commands.MgnlCommand;
17 import info.magnolia.context.Context;
18 import info.magnolia.context.MgnlContext;
19 import info.magnolia.context.WebContextImpl;
20 import info.magnolia.module.workflow.WorkflowConstants;
21 import info.magnolia.module.workflow.WorkflowModule;
22 import info.magnolia.module.workflow.WorkflowUtil;
23 import info.magnolia.module.workflow.flows.FlowDefinionException;
24 import info.magnolia.module.workflow.flows.FlowDefinitionManager;
25
26 import java.io.InputStream JavaDoc;
27 import java.io.Serializable JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.net.URLConnection JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35
36 import openwfe.org.engine.workitem.AttributeUtils;
37 import openwfe.org.engine.workitem.LaunchItem;
38 import openwfe.org.engine.workitem.StringMapAttribute;
39
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43
44 public class FlowCommand extends MgnlCommand {
45
46     /**
47      * The name of the workflow to start
48      */

49     private String JavaDoc workflowName = WorkflowConstants.DEFAULT_WORKFLOW;
50
51     private static Logger log = LoggerFactory.getLogger(FlowCommand.class);
52
53     public boolean execute(Context ctx) throws FlowDefinionException {
54         // Get the references
55
LaunchItem li = new LaunchItem();
56         prepareLaunchItem(ctx, li);
57         WorkflowUtil.launchFlow(li, getWorkflowName());
58         return true;
59     }
60
61     /**
62      * The default implementation puts all the contexts attributes which are in the request scope into the work item.
63      * @param context
64      * @param launchItem
65      */

66     public void prepareLaunchItem(Context context, LaunchItem launchItem) {
67         Map JavaDoc map = context.getAttributes(Context.LOCAL_SCOPE);
68         // create map for workflowItem with all serializable entries from the context
69
Map JavaDoc serializableMap = new HashMap JavaDoc();
70         for (Iterator JavaDoc iter = map.keySet().iterator(); iter.hasNext();) {
71             Object JavaDoc key = iter.next();
72             Object JavaDoc val = map.get(key);
73             if (val instanceof Serializable JavaDoc) {
74                 serializableMap.put(key, val);
75             }
76         }
77         serializableMap.put(WorkflowConstants.ATTRIBUTE_USERNAME, context.getUser().getName());
78         StringMapAttribute attrs = AttributeUtils.java2attributes(serializableMap);
79         launchItem.setAttributes(attrs);
80     }
81
82     public String JavaDoc getWorkflowName() {
83         return workflowName;
84     }
85
86     public void setWorkflowName(String JavaDoc flowName) {
87         this.workflowName = flowName;
88     }
89 }
90
Popular Tags