1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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  /**
41   * <a href="PublicRenderParametersPool.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Michael Young
44   *
45   */
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 }