KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > module > workflow > flows > SimpleFlowDefinitionManager


1 /**
2  *
3  */

4 package info.magnolia.module.workflow.flows;
5
6 import info.magnolia.cms.util.ClasspathResourcesUtil;
7 import info.magnolia.module.workflow.WorkflowConstants;
8
9 import java.io.IOException JavaDoc;
10 import java.io.InputStream JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
13
14 import openwfe.org.engine.workitem.LaunchItem;
15
16 import org.apache.commons.io.IOUtils;
17 import org.apache.commons.lang.StringUtils;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21
22 /**
23  * Used in the community edition. Only the default activation flow is supported.
24  * @author philipp
25  * @version $Id: SimpleFlowDefinitionManager.java 7308 2006-11-09 19:15:34Z philipp $
26  *
27  */

28 public class SimpleFlowDefinitionManager implements FlowDefinitionManager {
29
30     /**
31      * Logger.
32      */

33     private static Logger log = LoggerFactory.getLogger(SimpleFlowDefinitionManager.class);
34
35     public void configure(LaunchItem launchItem, String JavaDoc workflowName) throws FlowDefinionException {
36         if(!StringUtils.equals(workflowName, WorkflowConstants.DEFAULT_WORKFLOW)){
37             throw new FlowDefinionException("only default workflow supported in Community Edition, will fallback to default flow");
38         }
39         
40         launchItem.setWorkflowDefinitionUrl(WorkflowConstants.ATTRIBUTE_WORKFLOW_DEFINITION_URL);
41         String JavaDoc flowDef = readDefinition(WorkflowConstants.DEFAULT_WORKFLOW);
42         launchItem.getAttributes().puts(WorkflowConstants.ATTRIBUTE_DEFINITION, flowDef);
43     }
44
45     public String JavaDoc readDefinition(String JavaDoc workflowName) throws FlowDefinionException{
46         if(!StringUtils.equals(workflowName, WorkflowConstants.DEFAULT_WORKFLOW)){
47             throw new FlowDefinionException("only default workflow supported in Community Edition, will fallback to default flow");
48         }
49
50         InputStream JavaDoc stream = null;
51         try {
52             stream = ClasspathResourcesUtil.getStream("info/magnolia/module/workflow/default.xml");
53             return IOUtils.toString(stream);
54         }
55         catch (IOException JavaDoc e) {
56             log.error("can't read flow definition", e);
57         }
58         finally{
59             IOUtils.closeQuietly(stream);
60         }
61         return StringUtils.EMPTY;
62     }
63
64     public void saveDefinition(String JavaDoc definition) throws FlowDefinionException {
65         throw new FlowDefinionException("saving of workflow definitions is not supported in the Community Edition");
66     }
67
68     public List JavaDoc getDefinitionNames() {
69         List JavaDoc list = new ArrayList JavaDoc();
70         list.add("default");
71         return list;
72     }
73 }
74
Popular Tags