KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > misc > ReceiptAuditComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jul 8, 2005
14  * @author James Dixon
15  */

16
17 package org.pentaho.plugin.misc;
18
19 import java.util.Date JavaDoc;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.pentaho.messages.Messages;
23 import org.pentaho.plugin.ComponentBase;
24
25 /**
26  * @author James Dixon
27  *
28  * TODO To change the template for this generated type comment go to Window -
29  * Preferences - Java - Code Style - Code Templates
30  */

31 public class ReceiptAuditComponent extends ComponentBase {
32
33     private static final long serialVersionUID = -7641957638192444235L;
34
35     private static final String JavaDoc MESSAGE = "message"; //$NON-NLS-1$
36

37     private static final String JavaDoc DT = "dt"; //$NON-NLS-1$
38

39     public Log getLogger() {
40         return LogFactory.getLog(ReceiptAuditComponent.class);
41     }
42
43     public static String JavaDoc RECEIPT_AUDIT = Messages.getString("ReceiptAuditComponent.CODE_AUDIT_CONTENT_RECEIVED"); //$NON-NLS-1$
44

45     protected boolean validateSystemSettings() {
46         // This component does not have any system settings to validate
47
return true;
48     }
49
50     protected boolean validateAction() {
51
52         // make sure that we have a message
53
if (!isDefinedInput(MESSAGE)) {
54             error(Messages.getErrorString("ReceiptAuditComponent.ERROR_0001_MESSAGE_NOT_SPECIFIED")); //$NON-NLS-1$
55
return false;
56         }
57
58         // make sure that we have a timestamp
59
if (!isDefinedInput(DT)) {
60             error(Messages.getErrorString("ReceiptAuditComponent.ERROR_0002_TIMESTAMP_NOT_SPECIFIED")); //$NON-NLS-1$
61
return false;
62         }
63
64         return true;
65     }
66
67     public void done() {
68     }
69
70     protected boolean executeAction() {
71
72         String JavaDoc message = getInputStringValue(MESSAGE);
73         String JavaDoc dtString = getInputStringValue(DT);
74
75         long dt = new Long JavaDoc(dtString).longValue();
76         long now = new Date JavaDoc().getTime();
77         int duration = (int) ((now - dt) / 1000);
78
79         audit(RECEIPT_AUDIT, message, "", duration); //$NON-NLS-1$
80

81         return false;
82     }
83
84     /*
85      * (non-Javadoc)
86      *
87      * @see org.pentaho.component.ComponentBase#init()
88      */

89     public boolean init() {
90         return true;
91     }
92
93 }
94
Popular Tags