01: package org.emforge.jbpm;
02:
03: import java.util.Date;
04:
05: import org.apache.commons.collections.Transformer;
06: import org.apache.commons.lang.StringUtils;
07: import org.emforge.jbpm.web.bean.WorkflowController;
08: import org.emforge.xfer.HistoryTO;
09: import org.jbpm.graph.def.ProcessDefinition;
10:
11: import ru.emdev.EmForge.EmForgeContext;
12: import ru.emdev.EmForge.util.Helper;
13: import ru.emdev.EmForge.wiki.WikiTextToXHTMLConverter;
14:
15: import com.ecyrd.jspwiki.WikiEngine;
16:
17: /** Transforms process definitions into history list */
18: class ProcessDefToHistoryTransformer implements Transformer {
19: private WikiEngine wikiEngine;
20: private EmForgeContext emForgeContext;
21:
22: public ProcessDefToHistoryTransformer(WikiEngine wikiEngine,
23: EmForgeContext emForgeContext) {
24: this .wikiEngine = wikiEngine;
25: this .emForgeContext = emForgeContext;
26: }
27:
28: public HistoryTO transform(Object i_input) {
29: ProcessDefinition processDef = (ProcessDefinition) i_input;
30: HistoryTO history = new HistoryTO();
31:
32: String comment = null;
33: try {
34: comment = new String(processDef.getFileDefinition()
35: .getBytes(BpmServiceImpl.COMMENT_FILENAME));
36: } catch (Exception ex) {
37: // just ignore it - seems file has no comment
38: }
39:
40: Date date = null;
41: String userName = null;
42: String commentText = null;
43:
44: if (comment != null) {
45: date = new Date(Long.parseLong(StringUtils
46: .substringBetween(comment,
47: BpmServiceImpl.DATE_SEPARATOR,
48: BpmServiceImpl.USER_SEPARATOR)));
49: userName = StringUtils.substringBetween(comment,
50: BpmServiceImpl.USER_SEPARATOR,
51: BpmServiceImpl.MESSAGE_SEPARATOR);
52: commentText = StringUtils.substringAfter(comment,
53: BpmServiceImpl.MESSAGE_SEPARATOR);
54: }
55:
56: history.setActor(userName);
57: history.setDate(date);
58: history.setMessage(processDef.getName() + "("
59: + processDef.getVersion() + ")");
60:
61: if (commentText != null) {
62: // convert comment to html
63: WikiTextToXHTMLConverter converter = new WikiTextToXHTMLConverter(
64: wikiEngine, processDef.getName());
65:
66: // convert page to HTML
67: String htmlComment = converter.getAsString(null, null,
68: commentText);
69: history.setComment(htmlComment);
70: }
71:
72: // create link
73: String link = Helper.concatUrl(emForgeContext
74: .getApplicationPath(),
75: WorkflowController.WORKFLOW_PAGE_NAME);
76:
77: link = Helper.concatUrl(link, processDef.getName());
78: link = Helper.concatUrl(link, String.valueOf(processDef
79: .getVersion()));
80:
81: history.setLink(link);
82:
83: history.setIconLink(ProcessDefTransformer
84: .getWorkflowIconLink(processDef));
85:
86: return history;
87: }
88:
89: }
|