📄 loggingeventlistener.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//// MJ 18.02.2001//////package org.jahia.services.audit;import java.util.*;import org.jahia.utils.*; // JahiaConsole, JahiaObjectToolimport org.jahia.exceptions.*; // Jahia Exceptionsimport org.jahia.data.events.*; // EventObjectimport org.jahia.data.fields.*; // JahiaFieldimport org.jahia.services.pages.*; // JahiaPageimport org.jahia.data.containers.*; // JahiaContainer, JahiaContainerListimport org.jahia.services.usermanager.*; // JahiaUserimport org.jahia.services.audit.*; // JahiaAuditLogManagerimport org.jahia.registries.ServicesRegistry;public class LoggingEventListener extends JahiaEventListener{ public static final int FIELD_TYPE = JahiaObjectTool.FIELD_TYPE; public static final int CONTAINER_TYPE = JahiaObjectTool.CONTAINER_TYPE; public static final int CONTAINERLIST_TYPE = JahiaObjectTool.CONTAINERLIST_TYPE; public static final int PAGE_TYPE = JahiaObjectTool.PAGE_TYPE; public static final int ACL_TYPE = JahiaObjectTool.ACL_TYPE; private final String MSG_INTERNAL_ERROR = new String ("Logging Event Listener internal error"); private int objectType = 0; // references to needed services. private JahiaAuditLogManagerService mAuditLogManager = null; /** * constructor * get an instance of the Log Manager Service * * @author MJ */ public LoggingEventListener() throws JahiaException { // Try to get the Audit Log Manager Service ServicesRegistry registry = ServicesRegistry.getInstance(); if (registry != null) { mAuditLogManager = registry.getJahiaAuditLogManagerService(); if (mAuditLogManager == null) { throw new JahiaException (MSG_INTERNAL_ERROR, "User manager could not get the Audit Log Manager Service instance.", JahiaException.SERVICE_ERROR, JahiaException.CRITICAL); } } else { throw new JahiaException (MSG_INTERNAL_ERROR, "User manager could not get the Service Registry instance.", JahiaException.REGISTRY_ERROR, JahiaException.CRITICAL); } } // end constructor /*** * triggered when Jahia adds a field * * @param je the associated JahiaEvent * */ public void fieldAdded( JahiaEvent je ) { JahiaField theField = (JahiaField) je.getObject(); mAuditLogManager.logEvent( je, FIELD_TYPE, "added field" ); } /*** * triggered when Jahia updates a field * * @param je the associated JahiaEvent * */ public void fieldUpdated( JahiaEvent je ) { JahiaField theField = (JahiaField) je.getObject(); mAuditLogManager.logEvent( je, FIELD_TYPE, "modified field" ); } /*** * triggered when Jahia deletes a field * * @param je the associated JahiaEvent * */ public void fieldDeleted( JahiaEvent je ) { JahiaField theField = (JahiaField) je.getObject(); mAuditLogManager.logEvent( je, FIELD_TYPE, "deleted field" ); } /*** * triggered when Jahia adds a container * * @param je the associated JahiaEvent * */ public void containerAdded( JahiaEvent je ) { JahiaContainer theContainer = (JahiaContainer) je.getObject(); mAuditLogManager.logEvent( je, CONTAINER_TYPE, "added container" ); } /*** * triggered when Jahia updates a container * @param je the associated JahiaEvent */ public void containerUpdated( JahiaEvent je ) { JahiaContainer theContainer = (JahiaContainer) je.getObject(); mAuditLogManager.logEvent( je, CONTAINER_TYPE, "updated container" ); } /*** * triggered when Jahia deletes a container * @param je the associated JahiaEvent */ public void containerDeleted( JahiaEvent je ) { JahiaContainer theContainer = (JahiaContainer) je.getObject(); mAuditLogManager.logEvent( je, CONTAINER_TYPE, "deleted container" ); } /*** * triggered when Jahia adds a page * @param je the associated JahiaEvent */ public void pageAdded( JahiaEvent je ) { JahiaPage thePage = (JahiaPage) je.getObject(); mAuditLogManager.logEvent( je, PAGE_TYPE, "added page" ); } /*** * triggered when Jahia sets properties on a page * @param je the associated JahiaEvent */ public void pagePropertiesSet( JahiaEvent je ) { JahiaPage thePage = (JahiaPage) je.getObject(); mAuditLogManager.logEvent( je, PAGE_TYPE, "set properties for page" ); } /*** * triggered when template has been processed * * @param je the associated JahiaEvent */ public void templateUpdated( JahiaEvent je ) { if ( je.getObject() != null ){ JahiaPageDefinition theTemplate = (JahiaPageDefinition) je.getObject(); mAuditLogManager.logEvent( je, JahiaObjectTool.TEMPLATE_TYPE, "template updated" ); } } /*** * triggered when Jahia sets properties on a container list * @param je the associated JahiaEvent */ public void containerListPropertiesSet( JahiaEvent je ) { JahiaContainerList theContainerList = (JahiaContainerList) je.getObject(); mAuditLogManager.logEvent( je, CONTAINERLIST_TYPE, "set properties for containerList" ); } /*** * triggered when Jahia sets ACL rights * @param je the associated JahiaEvent */ public void rightsSet( JahiaEvent je ) { Object theObject = je.getObject(); if( theObject instanceof JahiaField ) { mAuditLogManager.logEvent( je, FIELD_TYPE, "set rights" ); } else if( theObject instanceof JahiaField ) { mAuditLogManager.logEvent( je, FIELD_TYPE, "set rights" ); } else if( theObject instanceof JahiaContainer ) { mAuditLogManager.logEvent( je, CONTAINER_TYPE, "set rights" ); } else if( theObject instanceof JahiaContainerList ) { mAuditLogManager.logEvent( je, CONTAINERLIST_TYPE, "set rights" ); } else if( theObject instanceof JahiaPage ) { mAuditLogManager.logEvent( je, PAGE_TYPE, "set rights" ); } } //-------------------------------------------------------------------------- private void toConsole (String message) { JahiaConsole.println ("LoggingEventListener", message); }} // end LoggingEventListener
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -