1
22
23 package com.liferay.portlet;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.model.Layout;
28 import com.liferay.portal.model.LayoutSet;
29 import com.liferay.portal.service.LayoutLocalServiceUtil;
30 import com.liferay.portal.util.PropsValues;
31 import com.liferay.portal.util.WebKeys;
32
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.concurrent.ConcurrentHashMap;
36
37 import javax.servlet.http.HttpServletRequest;
38 import javax.servlet.http.HttpSession;
39
40
46 public class PublicRenderParametersPool {
47
48 public static Map<String, String[]> get(
49 HttpServletRequest request, long plid) {
50
51 if (PropsValues.PORTLET_PUBLIC_RENDER_PARAMETER_DISTRIBUTION_LAYOUT) {
52 return RenderParametersPool.get(
53 request, plid, _PUBLIC_RENDER_PARAMETERS);
54 }
55
56 HttpSession session = request.getSession();
57
58 Map<Long, Map<String, String[]>> publicRenderParametersPool =
59 (Map<Long, Map<String, String[]>>)session.getAttribute(
60 WebKeys.PUBLIC_RENDER_PARAMETERS_POOL);
61
62 if (publicRenderParametersPool == null) {
63 publicRenderParametersPool =
64 new ConcurrentHashMap<Long, Map<String, String[]>>();
65
66 session.setAttribute(
67 WebKeys.PUBLIC_RENDER_PARAMETERS_POOL,
68 publicRenderParametersPool);
69 }
70
71 try {
72 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
73
74 LayoutSet layoutSet = layout.getLayoutSet();
75
76 Map<String, String[]> publicRenderParameters =
77 publicRenderParametersPool.get(layoutSet.getLayoutSetId());
78
79 if (publicRenderParameters == null) {
80 publicRenderParameters = new HashMap<String, String[]>();
81
82 publicRenderParametersPool.put(
83 layoutSet.getLayoutSetId(), publicRenderParameters);
84 }
85
86 return publicRenderParameters;
87 }
88 catch (Exception e) {
89 if (_log.isWarnEnabled()) {
90 _log.warn(e, e);
91 }
92
93 return new HashMap<String, String[]>();
94 }
95 }
96
97 private static final String _PUBLIC_RENDER_PARAMETERS =
98 "PUBLIC_RENDER_PARAMETERS";
99
100 private static Log _log =
101 LogFactoryUtil.getLog(PublicRenderParametersPool.class);
102
103 }