KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > audit > LoggingEventListener


1 /*
2  * ____.
3  * __/\ ______| |__/\. _______
4  * __ .____| | \ | +----+ \
5  * _______| /--| | | - \ _ | : - \_________
6  * \\______: :---| : : | : | \________>
7  * |__\---\_____________:______: :____|____:_____\
8  * /_____|
9  *
10  * . . . i n j a h i a w e t r u s t . . .
11  *
12  *
13  *
14  * ----- BEGIN LICENSE BLOCK -----
15  * Version: JCSL 1.0
16  *
17  * The contents of this file are subject to the Jahia Community Source License
18  * 1.0 or later (the "License"); you may not use this file except in
19  * compliance with the License. You may obtain a copy of the License at
20  * http://www.jahia.org/license
21  *
22  * Software distributed under the License is distributed on an "AS IS" basis,
23  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
24  * for the rights, obligations and limitations governing use of the contents
25  * of the file. The Original and Upgraded Code is the Jahia CMS and Portal
26  * Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
27  * Ltd. owns the copyrights in the portions it created. All Rights Reserved.
28  *
29  * The Shared Modifications are Jahia View Helper.
30  *
31  * The Developer of the Shared Modifications is Jahia Solution S�rl.
32  * Portions created by the Initial Developer are Copyright (C) 2002 by the
33  * Initial Developer. All Rights Reserved.
34  *
35  * Contributor(s):
36  * 22-AUG-2003, Jahia Solutions Sarl, Fulco Houkes
37  *
38  * ----- END LICENSE BLOCK -----
39  */

40
41
42 package org.jahia.services.audit;
43
44 import org.jahia.data.containers.JahiaContainer;
45 import org.jahia.data.containers.JahiaContainerList;
46 import org.jahia.data.events.JahiaEvent;
47 import org.jahia.data.events.JahiaEventListener;
48 import org.jahia.data.fields.JahiaField;
49 import org.jahia.exceptions.JahiaException;
50 import org.jahia.registries.ServicesRegistry;
51 import org.jahia.services.pages.JahiaPage;
52 import org.jahia.services.pages.JahiaPageDefinition;
53 import org.jahia.utils.JahiaObjectTool;
54
55
56 public class LoggingEventListener extends JahiaEventListener {
57
58     public static final int FIELD_TYPE = JahiaObjectTool.FIELD_TYPE;
59     public static final int CONTAINER_TYPE = JahiaObjectTool.CONTAINER_TYPE;
60     public static final int CONTAINERLIST_TYPE = JahiaObjectTool.CONTAINERLIST_TYPE;
61     public static final int PAGE_TYPE = JahiaObjectTool.PAGE_TYPE;
62     public static final int ACL_TYPE = JahiaObjectTool.ACL_TYPE;
63
64     private final String JavaDoc MSG_INTERNAL_ERROR = new String JavaDoc ("Logging Event Listener internal error");
65
66     private int objectType = 0;
67
68     // references to needed services.
69
private JahiaAuditLogManagerService mAuditLogManager = null;
70
71
72     /**
73      * constructor
74      * get an instance of the Log Manager Service
75      */

76     public LoggingEventListener ()
77             throws JahiaException {
78         // Try to get the Audit Log Manager Service
79
ServicesRegistry registry = ServicesRegistry.getInstance ();
80         if (registry != null) {
81             mAuditLogManager = registry.getJahiaAuditLogManagerService ();
82             if (mAuditLogManager == null) {
83                 throw new JahiaException (MSG_INTERNAL_ERROR, "User manager could not get the Audit Log Manager Service instance.",
84                         JahiaException.SERVICE_ERROR, JahiaException.CRITICAL_SEVERITY);
85             }
86
87         } else {
88             throw new JahiaException (MSG_INTERNAL_ERROR, "User manager could not get the Service Registry instance.",
89                     JahiaException.REGISTRY_ERROR, JahiaException.CRITICAL_SEVERITY);
90         }
91     } // end constructor
92

93
94     /***
95      * triggered when Jahia adds a field
96      *
97      * @param je the associated JahiaEvent
98      *
99      */

100     public void fieldAdded (JahiaEvent je) {
101         if (je != null && je.getObject () != null) {
102             JahiaField theField = (JahiaField)je.getObject ();
103             mAuditLogManager.logEvent (je, FIELD_TYPE, "added field");
104         }
105     }
106
107
108     /***
109      * triggered when Jahia updates a field
110      *
111      * @param je the associated JahiaEvent
112      *
113      */

114     public void fieldUpdated (JahiaEvent je) {
115         JahiaField theField = (JahiaField)je.getObject ();
116         mAuditLogManager.logEvent (je, FIELD_TYPE, "modified field");
117     }
118
119
120     /***
121      * triggered when Jahia deletes a field
122      *
123      * @param je the associated JahiaEvent
124      *
125      */

126     public void fieldDeleted (JahiaEvent je) {
127         JahiaField theField = (JahiaField)je.getObject ();
128         mAuditLogManager.logEvent (je, FIELD_TYPE, "deleted field");
129     }
130
131
132     /***
133      * triggered when Jahia adds a container
134      *
135      * @param je the associated JahiaEvent
136      *
137      */

138     public void containerAdded (JahiaEvent je) {
139         JahiaContainer theContainer = (JahiaContainer)je.getObject ();
140         mAuditLogManager.logEvent (je, CONTAINER_TYPE, "added container");
141     }
142
143
144     /***
145      * triggered when Jahia updates a container
146      * @param je the associated JahiaEvent
147      */

148     public void containerUpdated (JahiaEvent je) {
149         JahiaContainer theContainer = (JahiaContainer)je.getObject ();
150         mAuditLogManager.logEvent (je, CONTAINER_TYPE, "updated container");
151     }
152
153
154     /***
155      * triggered when Jahia deletes a container
156      * @param je the associated JahiaEvent
157      */

158     public void containerDeleted (JahiaEvent je) {
159         JahiaContainer theContainer = (JahiaContainer)je.getObject ();
160         mAuditLogManager.logEvent (je, CONTAINER_TYPE, "deleted container");
161     }
162
163
164     /***
165      * triggered when Jahia adds a page
166      * @param je the associated JahiaEvent
167      */

168     public void pageAdded (JahiaEvent je) {
169         JahiaPage thePage = (JahiaPage)je.getObject ();
170         mAuditLogManager.logEvent (je, PAGE_TYPE, "added page");
171     }
172
173
174     /***
175      * triggered when Jahia sets properties on a page
176      * @param je the associated JahiaEvent
177      */

178     public void pagePropertiesSet (JahiaEvent je) {
179         JahiaPage thePage = (JahiaPage)je.getObject ();
180         mAuditLogManager.logEvent (je, PAGE_TYPE, "set properties for page");
181     }
182
183
184     /***
185      * triggered when template has been processed
186      *
187      * @param je the associated JahiaEvent
188      */

189     public void templateUpdated (JahiaEvent je) {
190         if (je.getObject () != null) {
191             JahiaPageDefinition theTemplate = (JahiaPageDefinition)je.getObject ();
192             mAuditLogManager.logEvent (je, JahiaObjectTool.TEMPLATE_TYPE, "template updated");
193         }
194     }
195
196
197     /***
198      * triggered when Jahia sets properties on a container list
199      * @param je the associated JahiaEvent
200      */

201     public void containerListPropertiesSet (JahiaEvent je) {
202         JahiaContainerList theContainerList = (JahiaContainerList)je.getObject ();
203         mAuditLogManager.logEvent (je, CONTAINERLIST_TYPE, "set properties for containerList");
204     }
205
206
207     /***
208      * triggered when Jahia sets ACL rights
209      * @param je the associated JahiaEvent
210      */

211     public void rightsSet (JahiaEvent je) {
212         Object JavaDoc theObject = je.getObject ();
213         if (theObject instanceof JahiaField) {
214             mAuditLogManager.logEvent (je, FIELD_TYPE, "set rights");
215         } else if (theObject instanceof JahiaField) {
216             mAuditLogManager.logEvent (je, FIELD_TYPE, "set rights");
217         } else if (theObject instanceof JahiaContainer) {
218             mAuditLogManager.logEvent (je, CONTAINER_TYPE, "set rights");
219         } else if (theObject instanceof JahiaContainerList) {
220             mAuditLogManager.logEvent (je, CONTAINERLIST_TYPE, "set rights");
221         } else if (theObject instanceof JahiaPage) {
222             mAuditLogManager.logEvent (je, PAGE_TYPE, "set rights");
223         }
224     }
225
226 }
227
Popular Tags