View Javadoc

1   /*******************************************************************************
2    *  Imixs Workflow 
3    *  Copyright (C) 2001, 2011 Imixs Software Solutions GmbH,  
4    *  http://www.imixs.com
5    *  
6    *  This program is free software; you can redistribute it and/or 
7    *  modify it under the terms of the GNU General Public License 
8    *  as published by the Free Software Foundation; either version 2 
9    *  of the License, or (at your option) any later version.
10   *  
11   *  This program is distributed in the hope that it will be useful, 
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
14   *  General Public License for more details.
15   *  
16   *  You can receive a copy of the GNU General Public
17   *  License at http://www.gnu.org/licenses/gpl.html
18   *  
19   *  Project: 
20   *  	http://www.imixs.org
21   *  	http://java.net/projects/imixs-workflow
22   *  
23   *  Contributors:  
24   *  	Imixs Software Solutions GmbH - initial API and implementation
25   *  	Ralph Soika - Software Developer
26   *******************************************************************************/
27  
28  package org.imixs.workflow.plugins;
29  
30  import java.util.List;
31  
32  import org.imixs.workflow.ItemCollection;
33  import org.imixs.workflow.Plugin;
34  import org.imixs.workflow.exceptions.PluginException;
35  
36  /**
37   * This Pluginmodul cuts the length of the technical log entries generated by
38   * the WorkflowKernel:
39   * 
40   * txtWorkflowPluginLog
41   * 
42   * txtWorkflowActivityLog
43   * 
44   * The Attribute numWorkflowLogLength indicates the maximum number of entries.
45   * if <= 0 no limit is set.
46   * 
47   * 
48   * @author Ralph Soika
49   * @version 1.2
50   * @see org.imixs.workflow.WorkflowManager
51   * 
52   */
53  
54  public class LogPlugin extends AbstractPlugin {
55  	public ItemCollection documentContext;
56  	List vPluginLog, vActivityLog;
57  
58  	/**
59  	 * the log entries generated form the kernel will be cut if the attribute
60  	 * numWorkflowLogLength was provided
61  	 */
62  	public int run(ItemCollection adocumentContext,
63  			ItemCollection adocumentActivity) throws PluginException {
64  		documentContext = adocumentContext;
65  
66  		vPluginLog = documentContext.getItemValue("txtWorkflowPluginLog");
67  		vActivityLog = documentContext.getItemValue("txtWorkflowActivityLog");
68  
69  		// check if maximum length is defined
70  		int iMaxLogLength = documentContext
71  				.getItemValueInteger("numWorkflowLogLength");
72  		if (iMaxLogLength > 0) {
73  			while (vPluginLog.size() >= iMaxLogLength)
74  				vPluginLog.remove(0);
75  
76  			while (vActivityLog.size() >= iMaxLogLength)
77  				vActivityLog.remove(0);
78  
79  			// update Log entries now...
80  			documentContext
81  					.replaceItemValue("txtWorkflowPluginLog", vPluginLog);
82  			documentContext.replaceItemValue("txtWorkflowActivityLog",
83  					vActivityLog);
84  		}
85  
86  		return Plugin.PLUGIN_OK;
87  	}
88  
89  	/**
90  	 * nothing to do
91  	 */
92  	public void close(int status) {
93  
94  	}
95  
96  }