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.tagscompiler;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.portlet.LiferayPortlet;
20  import com.liferay.portal.kernel.util.ArrayUtil;
21  import com.liferay.portal.kernel.util.ParamUtil;
22  import com.liferay.portal.kernel.util.StringUtil;
23  import com.liferay.portal.theme.ThemeDisplay;
24  import com.liferay.portal.util.PortalUtil;
25  import com.liferay.portal.util.PortletKeys;
26  import com.liferay.portal.util.WebKeys;
27  import com.liferay.portlet.RenderParametersPool;
28  import com.liferay.portlet.tagscompiler.util.TagsCompilerSessionUtil;
29  
30  import java.util.Collection;
31  
32  import javax.portlet.RenderRequest;
33  import javax.portlet.RenderResponse;
34  
35  import javax.servlet.http.HttpServletRequest;
36  
37  /**
38   * <a href="TagsCompilerPortlet.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class TagsCompilerPortlet extends LiferayPortlet {
43  
44      public void render(
45          RenderRequest renderRequest, RenderResponse renderResponse) {
46  
47          // Compile entries
48  
49          String entriesFromURL = ParamUtil.getString(renderRequest, "entries");
50          String[] entriesFromURLArray = StringUtil.split(entriesFromURL);
51  
52          if (_log.isDebugEnabled()) {
53              _log.debug("Entries from friendly URL " + entriesFromURL);
54          }
55  
56          Collection<String> entriesFromSession =
57              TagsCompilerSessionUtil.getEntries(renderRequest);
58          String[] entriesFromSessionArray = entriesFromSession.toArray(
59              new String[entriesFromSession.size()]);
60  
61          if (_log.isDebugEnabled()) {
62              _log.debug(
63                  "Entries from session " +
64                      StringUtil.merge(entriesFromSessionArray));
65          }
66  
67          String[] entries = ArrayUtil.append(
68              entriesFromURLArray, entriesFromSessionArray);
69  
70          renderRequest.setAttribute(WebKeys.TAGS_COMPILER_ENTRIES, entries);
71  
72          // Clear render parameters cache
73  
74          HttpServletRequest request = PortalUtil.getHttpServletRequest(
75              renderRequest);
76  
77          ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
78              WebKeys.THEME_DISPLAY);
79  
80          RenderParametersPool.clear(
81              request, themeDisplay.getPlid(), PortletKeys.TAGS_COMPILER);
82      }
83  
84      private static Log _log = LogFactoryUtil.getLog(TagsCompilerPortlet.class);
85  
86  }