1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
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  /**
33   * <a href="PublicRenderParametersPool.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Michael Young
36   */
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  }