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