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