001
014
015 package com.liferay.portlet;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.model.Layout;
020 import com.liferay.portal.model.LayoutSet;
021 import com.liferay.portal.service.LayoutLocalServiceUtil;
022 import com.liferay.portal.util.PropsValues;
023 import com.liferay.portal.util.WebKeys;
024
025 import java.util.HashMap;
026 import java.util.Map;
027 import java.util.concurrent.ConcurrentHashMap;
028
029 import javax.servlet.http.HttpServletRequest;
030 import javax.servlet.http.HttpSession;
031
032
035 public class PublicRenderParametersPool {
036
037 public static Map<String, String[]> get(
038 HttpServletRequest request, long plid) {
039
040 if (PropsValues.PORTLET_PUBLIC_RENDER_PARAMETER_DISTRIBUTION_LAYOUT) {
041 return RenderParametersPool.get(
042 request, plid, _PUBLIC_RENDER_PARAMETERS);
043 }
044
045 HttpSession session = request.getSession();
046
047 Map<Long, Map<String, String[]>> publicRenderParametersPool =
048 (Map<Long, Map<String, String[]>>)session.getAttribute(
049 WebKeys.PUBLIC_RENDER_PARAMETERS_POOL);
050
051 if (publicRenderParametersPool == null) {
052 publicRenderParametersPool =
053 new ConcurrentHashMap<Long, Map<String, String[]>>();
054
055 session.setAttribute(
056 WebKeys.PUBLIC_RENDER_PARAMETERS_POOL,
057 publicRenderParametersPool);
058 }
059
060 try {
061 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
062
063 LayoutSet layoutSet = layout.getLayoutSet();
064
065 Map<String, String[]> publicRenderParameters =
066 publicRenderParametersPool.get(layoutSet.getLayoutSetId());
067
068 if (publicRenderParameters == null) {
069 publicRenderParameters = new HashMap<String, String[]>();
070
071 publicRenderParametersPool.put(
072 layoutSet.getLayoutSetId(), publicRenderParameters);
073 }
074
075 return publicRenderParameters;
076 }
077 catch (Exception e) {
078 if (_log.isWarnEnabled()) {
079 _log.warn(e, e);
080 }
081
082 return new HashMap<String, String[]>();
083 }
084 }
085
086 private static final String _PUBLIC_RENDER_PARAMETERS =
087 "PUBLIC_RENDER_PARAMETERS";
088
089 private static Log _log = LogFactoryUtil.getLog(
090 PublicRenderParametersPool.class);
091
092 }