001
014
015 package com.liferay.portal.servlet;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.servlet.ServletVersionDetector;
020 import com.liferay.portal.kernel.util.ArrayUtil;
021 import com.liferay.portal.util.PropsValues;
022
023 import java.util.Enumeration;
024 import java.util.HashMap;
025 import java.util.Map;
026
027 import javax.servlet.http.HttpServletRequest;
028 import javax.servlet.http.HttpSession;
029
030
035 public class SharedSessionUtil {
036
037 public static Map<String, Object> getSharedSessionAttributes(
038 HttpServletRequest request) {
039
040 HttpSession session = request.getSession();
041
042 if (ServletVersionDetector.is2_5()) {
043 Map<String, Object> attributes = new HashMap<String, Object>();
044
045 Enumeration<String> enu = session.getAttributeNames();
046
047 while (enu.hasMoreElements()) {
048 String name = enu.nextElement();
049
050 Object value = session.getAttribute(name);
051
052 if (value == null) {
053 continue;
054 }
055
056 if (ArrayUtil.contains(
057 PropsValues.SHARED_SESSION_ATTRIBUTES_EXCLUDES, name)) {
058
059 continue;
060 }
061
062 for (String sharedName :
063 PropsValues.SHARED_SESSION_ATTRIBUTES) {
064
065 if (!name.startsWith(sharedName)) {
066 continue;
067 }
068
069 if (_log.isDebugEnabled()) {
070 _log.debug("Sharing " + name);
071 }
072
073 attributes.put(name, value);
074
075 break;
076 }
077 }
078
079 return attributes;
080 }
081 else {
082 SharedSessionAttributeCache sharedSessionAttributeCache =
083 SharedSessionAttributeCache.getInstance(session);
084
085 Map<String, Object> values =
086 sharedSessionAttributeCache.getValues();
087
088 if (_log.isDebugEnabled()) {
089 _log.debug("Shared session attributes " + values);
090 }
091
092 return values;
093 }
094 }
095
096 private static Log _log = LogFactoryUtil.getLog(SharedSessionUtil.class);
097
098 }