Confluence Docs 3.0 : EventListener Example This page last changed on Jan 04, 2005 by cmiller. Find an example of an EventListener below, which listens for the LoginEvent and LogoutEvent .
    package com.atlassian.confluence.extra.userlister;

    import com.atlassian.confluence.event.EventListener;
    import com.atlassian.confluence.event.events.ConfluenceEvent;
    import com.atlassian.confluence.event.events.LoginEvent;
    import com.atlassian.confluence.event.events.LogoutEvent;
    import com.atlassian.plugin.PluginManager;
    import bucket.container.ContainerManager;

    public class UserListener implements EventListener
    {
        private UserLister userLister;
        private PluginManager pluginManager;

        Class[] handledClasses = new Class[]{ LoginEvent.class, LogoutEvent.class};

        public void handleEvent(ConfluenceEvent event)
        {
            if (event instanceof LoginEvent)
            {
                LoginEvent loginEvent = (LoginEvent) event;
                getUserLister().userLoggedIn(loginEvent.getUsername(), loginEvent.getSessionId());
            }
            else if (event instanceof LogoutEvent)
            {
                LogoutEvent logoutEvent = (LogoutEvent) event;
                getUserLister().userLoggedIn(logoutEvent. getUsername(), logoutEvent.getSessionId());
            }

        }

        public UserLister getUserLister()
        {
            if (userLister == null)
            {
                if (pluginManager == null)
                {
                    pluginManager = (PluginManager) ContainerManager.getInstance().getContainerContext().getComponent("pluginManager");

                    userLister = (UserLister) pluginManager.getEnabledPluginModule("userlister");
                }
            }

            return userLister;
        }

        public Class[] getHandledEventClasses()
        {
            return handledClasses;
        }
    }

Document generated by Confluence on Nov 05, 2009 23:34