1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.servlet;
16  
17  import com.liferay.portal.events.EventsProcessorUtil;
18  import com.liferay.portal.kernel.events.ActionException;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.util.PortalInitableUtil;
22  import com.liferay.portal.kernel.util.PropsKeys;
23  import com.liferay.portal.util.PropsValues;
24  
25  import javax.servlet.http.HttpSession;
26  import javax.servlet.http.HttpSessionEvent;
27  import javax.servlet.http.HttpSessionListener;
28  
29  /**
30   * <a href="PortalSessionListener.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class PortalSessionListener implements HttpSessionListener {
35  
36      public void sessionCreated(HttpSessionEvent event) {
37          if (PropsValues.SESSION_DISABLED) {
38              return;
39          }
40  
41          HttpSession session = event.getSession();
42  
43          PortalSessionContext.put(session.getId(), session);
44  
45          // Process session created events
46  
47          try {
48              EventsProcessorUtil.process(
49                  PropsKeys.SERVLET_SESSION_CREATE_EVENTS,
50                  PropsValues.SERVLET_SESSION_CREATE_EVENTS, session);
51          }
52          catch (ActionException ae) {
53              _log.error(ae, ae);
54          }
55      }
56  
57      public void sessionDestroyed(HttpSessionEvent event) {
58          PortalSessionDestroyer portalSessionDestroyer =
59              new PortalSessionDestroyer(event);
60  
61          PortalInitableUtil.init(portalSessionDestroyer);
62      }
63  
64      private static Log _log = LogFactoryUtil.getLog(
65          PortalSessionListener.class);
66  
67  }