1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.imixs.workflow.plugins;
29
30 import java.text.DateFormat;
31 import java.util.Date;
32 import java.util.List;
33 import java.util.logging.Logger;
34
35 import org.imixs.workflow.ItemCollection;
36 import org.imixs.workflow.Plugin;
37 import org.imixs.workflow.WorkflowKernel;
38 import org.imixs.workflow.exceptions.PluginException;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public class HistoryPlugin extends AbstractPlugin {
78 public ItemCollection documentContext;
79 public ItemCollection documentActivity;
80 List vOldProt, vOldProtRev;
81 private static Logger logger = Logger.getLogger("org.imixs.workflow");
82
83 public int run(ItemCollection adocumentContext,
84 ItemCollection adocumentActivity) throws PluginException {
85 String rtfItemResult;
86
87 documentContext = adocumentContext;
88 documentActivity = adocumentActivity;
89
90
91 rtfItemResult = documentActivity.getItemValueString("rtfresultlog");
92 String aProtokoll = rtfItemResult;
93
94 String sDatumsFormat = documentActivity
95 .getItemValueString("keyLogDateFormat");
96
97 if (sDatumsFormat == null || "".equals(sDatumsFormat))
98 sDatumsFormat = "1";
99 String sZeitFormat = documentActivity
100 .getItemValueString("keylogtimeformat");
101 if (sZeitFormat == null || "".equals(sZeitFormat))
102 sZeitFormat = "2";
103
104 if (ctx.getLogLevel() == WorkflowKernel.LOG_LEVEL_FINE)
105 logger.info("[HistoryPlugin] logtimeformat=" + sZeitFormat);
106 if (ctx.getLogLevel() == WorkflowKernel.LOG_LEVEL_FINE)
107 logger.info("[HistoryPlugin] logdateformat=" + sDatumsFormat);
108
109
110 int iDatumsFormat = -1;
111 int iZeitFormat = -1;
112 try {
113 iDatumsFormat = Integer.parseInt(sDatumsFormat);
114 iZeitFormat = Integer.parseInt(sZeitFormat);
115 } catch (NumberFormatException nfe) {
116
117 if (ctx.getLogLevel() >= WorkflowKernel.LOG_LEVEL_WARNING)
118 logger.severe("[HistoryPlugin] error logtimeformat "
119 + nfe.toString());
120 }
121
122 String sTim = "";
123 if ((iZeitFormat > -1) && (iDatumsFormat > -1)) {
124 sTim = DateFormat.getDateTimeInstance(iDatumsFormat, iZeitFormat)
125 .format(new Date());
126 } else {
127 if ((iZeitFormat == -1) && (iDatumsFormat > -1))
128 sTim = DateFormat.getDateInstance(iDatumsFormat).format(
129 new Date());
130 else if ((iZeitFormat > -1) && (iDatumsFormat == -1))
131 sTim = DateFormat.getTimeInstance(iZeitFormat).format(
132 new Date());
133 }
134
135
136
137 if (!"".equals(aProtokoll)) {
138 String sDoppelpunkt = "";
139 if ((!"".equals(sTim)) && (!"".equals(aProtokoll)))
140 sDoppelpunkt = " : ";
141 aProtokoll = sTim + sDoppelpunkt + aProtokoll;
142
143 aProtokoll = replaceDynamicValues(aProtokoll, documentContext);
144
145 vOldProt = documentContext.getItemValue("txtworkflowhistorylog");
146 vOldProtRev = documentContext
147 .getItemValue("txtworkflowhistorylogrev");
148
149 vOldProt.add(aProtokoll);
150 vOldProtRev.add(0, aProtokoll);
151
152
153 int iMaxLogLength = documentContext
154 .getItemValueInteger("numworkflowhistoryLength");
155 if (iMaxLogLength > 0) {
156 while (vOldProt.size() > iMaxLogLength)
157 vOldProt.remove(0);
158
159 while (vOldProtRev.size() > iMaxLogLength)
160 vOldProtRev.remove(vOldProtRev.size() - 1);
161 }
162
163 }
164
165 return Plugin.PLUGIN_OK;
166 }
167
168
169
170
171
172
173 public void close(int status) throws PluginException {
174
175
176 if (status < Plugin.PLUGIN_ERROR) {
177 if (vOldProt != null)
178
179 documentContext.replaceItemValue("txtworkflowhistorylog",
180 vOldProt);
181
182 if (vOldProtRev != null)
183 documentContext.replaceItemValue("txtworkflowhistorylogrev",
184 vOldProtRev);
185 Date date = new Date();
186
187 documentContext.replaceItemValue("timworkflowlastaccess", date);
188
189 }
190
191 }
192
193 }