1
14
15 package com.liferay.portal.servlet;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19 import com.liferay.portal.kernel.servlet.ServletVersionDetector;
20 import com.liferay.portal.kernel.util.ArrayUtil;
21 import com.liferay.portal.util.PropsValues;
22
23 import java.util.Enumeration;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpSession;
29
30
37 public class SharedSessionUtil {
38
39 public static Map<String, Object> getSharedSessionAttributes(
40 HttpServletRequest request) {
41
42 HttpSession session = request.getSession();
43
44 if (ServletVersionDetector.is2_5()) {
45 Map<String, Object> attributes = new HashMap<String, Object>();
46
47 Enumeration<String> enu = session.getAttributeNames();
48
49 while (enu.hasMoreElements()) {
50 String name = enu.nextElement();
51
52 Object value = session.getAttribute(name);
53
54 if (value == null) {
55 continue;
56 }
57
58 if (ArrayUtil.contains(
59 PropsValues.SHARED_SESSION_ATTRIBUTES_EXCLUDES, name)) {
60
61 continue;
62 }
63
64 for (String sharedName :
65 PropsValues.SHARED_SESSION_ATTRIBUTES) {
66
67 if (!name.startsWith(sharedName)) {
68 continue;
69 }
70
71 if (_log.isDebugEnabled()) {
72 _log.debug("Sharing " + name);
73 }
74
75 attributes.put(name, value);
76
77 break;
78 }
79 }
80
81 return attributes;
82 }
83 else {
84 SharedSessionAttributeCache sharedSessionAttributeCache =
85 SharedSessionAttributeCache.getInstance(session);
86
87 Map<String, Object> values =
88 sharedSessionAttributeCache.getValues();
89
90 if (_log.isDebugEnabled()) {
91 _log.debug("Shared session attributes " + values);
92 }
93
94 return values;
95 }
96 }
97
98 private static Log _log = LogFactoryUtil.getLog(SharedSessionUtil.class);
99
100 }