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