001
014
015 package com.liferay.portal.kernel.servlet;
016
017 import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdHttpSession;
018 import com.liferay.portal.kernel.servlet.filters.compoundsessionid.CompoundSessionIdSplitterUtil;
019
020 import java.util.ArrayList;
021 import java.util.List;
022
023 import javax.servlet.http.HttpSessionEvent;
024 import javax.servlet.http.HttpSessionListener;
025
026
034 public class PortletSessionListenerManager implements HttpSessionListener {
035
036 public static void addHttpSessionListener(
037 HttpSessionListener httpSessionListener) {
038
039 _httpSessionListeners.add(httpSessionListener);
040 }
041
042 public static void removeHttpSessionListener(
043 HttpSessionListener httpSessionListener) {
044
045 _httpSessionListeners.remove(httpSessionListener);
046 }
047
048 public void sessionCreated(HttpSessionEvent httpSessionEvent) {
049 httpSessionEvent = getHttpSessionEvent(httpSessionEvent);
050
051 Thread currentThread = Thread.currentThread();
052
053 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
054
055 try {
056 for (HttpSessionListener httpSessionListener :
057 _httpSessionListeners) {
058
059 Class<?> clazz = httpSessionListener.getClass();
060
061 ClassLoader classLoader = clazz.getClassLoader();
062
063 currentThread.setContextClassLoader(classLoader);
064
065 httpSessionListener.sessionCreated(httpSessionEvent);
066 }
067 }
068 finally {
069 currentThread.setContextClassLoader(contextClassLoader);
070 }
071 }
072
073 public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
074 httpSessionEvent = getHttpSessionEvent(httpSessionEvent);
075
076 for (HttpSessionListener httpSessionListener : _httpSessionListeners) {
077 httpSessionListener.sessionDestroyed(httpSessionEvent);
078 }
079 }
080
081 protected HttpSessionEvent getHttpSessionEvent(
082 HttpSessionEvent httpSessionEvent) {
083
084 if (CompoundSessionIdSplitterUtil.hasSessionDelimiter()) {
085 CompoundSessionIdHttpSession compoundSessionIdHttpSession =
086 new CompoundSessionIdHttpSession(httpSessionEvent.getSession());
087
088 httpSessionEvent = new HttpSessionEvent(
089 compoundSessionIdHttpSession);
090 }
091
092 return httpSessionEvent;
093 }
094
095 private static List<HttpSessionListener> _httpSessionListeners =
096 new ArrayList<HttpSessionListener>();
097
098 }