001
014
015 package com.liferay.portlet;
016
017 import com.liferay.portal.util.WebKeys;
018
019 import java.util.HashMap;
020 import java.util.Map;
021 import java.util.concurrent.ConcurrentHashMap;
022
023 import javax.servlet.http.HttpServletRequest;
024 import javax.servlet.http.HttpSession;
025
026
029 public class RenderParametersPool {
030
031 public static void clear(HttpServletRequest request, long plid) {
032 Map<String, Map<String, String[]>> plidPool = get(request, plid);
033
034 plidPool.clear();
035 }
036
037 public static void clear(
038 HttpServletRequest request, long plid, String portletId) {
039
040 Map<String, String[]> params = get(request, plid, portletId);
041
042 params.clear();
043 }
044
045 public static Map<String, Map<String, String[]>> get(
046 HttpServletRequest request, long plid) {
047
048 HttpSession session = request.getSession();
049
050 if (plid <= 0) {
051 return new ConcurrentHashMap<String, Map<String, String[]>>();
052 }
053
054 Map<Long, Map<String, Map<String, String[]>>> pool =
055 _getRenderParametersPool(session);
056
057 Map<String, Map<String, String[]>> plidPool = pool.get(plid);
058
059 if (plidPool == null) {
060 plidPool = new ConcurrentHashMap<String, Map<String, String[]>>();
061
062 pool.put(plid, plidPool);
063 }
064
065 return plidPool;
066 }
067
068 public static Map<String, String[]> get(
069 HttpServletRequest request, long plid, String portletId) {
070
071 Map<String, Map<String, String[]>> plidPool = get(request, plid);
072
073 Map<String, String[]> params = plidPool.get(portletId);
074
075 if (params == null) {
076 params = new HashMap<String, String[]>();
077
078 plidPool.put(portletId, params);
079 }
080
081 return params;
082 }
083
084 public static void put(
085 HttpServletRequest request, long plid, String portletId,
086 Map<String, String[]> params) {
087
088 Map<String, Map<String, String[]>> plidPool = get(request, plid);
089
090 plidPool.put(portletId, params);
091 }
092
093 private static Map<Long, Map<String, Map<String, String[]>>>
094 _getRenderParametersPool(HttpSession session) {
095
096 Map<Long, Map<String, Map<String, String[]>>> renderParametersPool =
097 (Map<Long, Map<String, Map<String, String[]>>>)session.getAttribute(
098 WebKeys.PORTLET_RENDER_PARAMETERS);
099
100 if (renderParametersPool == null) {
101 renderParametersPool = new ConcurrentHashMap
102 <Long, Map<String, Map<String, String[]>>>();
103
104 session.setAttribute(
105 WebKeys.PORTLET_RENDER_PARAMETERS, renderParametersPool);
106 }
107
108 return renderParametersPool;
109 }
110
111 }