1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet;
21  
22  import com.liferay.portal.util.WebKeys;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  import java.util.concurrent.ConcurrentHashMap;
27  
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpSession;
30  
31  /**
32   * <a href="RenderParametersPool.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   *
36   */
37  public class RenderParametersPool {
38  
39      public static void clear(HttpServletRequest request, long plid) {
40          Map<String, Map<String, String[]>> plidPool = get(request, plid);
41  
42          plidPool.clear();
43      }
44  
45      public static void clear(
46          HttpServletRequest request, long plid, String portletId) {
47  
48          Map<String, String[]> params = get(request, plid, portletId);
49  
50          params.clear();
51      }
52  
53      public static Map<String, Map<String, String[]>> get(
54          HttpServletRequest request, long plid) {
55  
56          HttpSession session = request.getSession();
57  
58          if (plid <= 0) {
59              return new ConcurrentHashMap<String, Map<String, String[]>>();
60          }
61  
62          Map<Long, Map<String, Map<String, String[]>>> pool =
63              _getRenderParametersPool(session);
64  
65          Map<String, Map<String, String[]>> plidPool = pool.get(plid);
66  
67          if (plidPool == null) {
68              plidPool = new ConcurrentHashMap<String, Map<String, String[]>>();
69  
70              pool.put(plid, plidPool);
71          }
72  
73          return plidPool;
74      }
75  
76      public static Map<String, String[]> get(
77          HttpServletRequest request, long plid, String portletId) {
78  
79          Map<String, Map<String, String[]>> plidPool = get(request, plid);
80  
81          Map<String, String[]> params = plidPool.get(portletId);
82  
83          if (params == null) {
84              params = new HashMap<String, String[]>();
85  
86              plidPool.put(portletId, params);
87          }
88  
89          return params;
90      }
91  
92      public static void put(
93          HttpServletRequest request, long plid, String portletId,
94          Map<String, String[]> params) {
95  
96          Map<String, Map<String, String[]>> plidPool = get(request, plid);
97  
98          plidPool.put(portletId, params);
99      }
100 
101     private static Map<Long, Map<String, Map<String, String[]>>>
102         _getRenderParametersPool(HttpSession session) {
103 
104         Map<Long, Map<String, Map<String, String[]>>> renderParametersPool =
105             (Map<Long, Map<String, Map<String, String[]>>>)session.getAttribute(
106                 WebKeys.PORTLET_RENDER_PARAMETERS);
107 
108         if (renderParametersPool == null) {
109             renderParametersPool = new ConcurrentHashMap
110                 <Long, Map<String, Map<String, String[]>>>();
111 
112             session.setAttribute(
113                 WebKeys.PORTLET_RENDER_PARAMETERS, renderParametersPool);
114         }
115 
116         return renderParametersPool;
117     }
118 
119 }