001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.tagscompiler;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.portlet.LiferayPortlet;
020    import com.liferay.portal.kernel.util.ArrayUtil;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portal.kernel.util.StringUtil;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portal.util.PortalUtil;
025    import com.liferay.portal.util.PortletKeys;
026    import com.liferay.portal.util.WebKeys;
027    import com.liferay.portlet.RenderParametersPool;
028    import com.liferay.portlet.tagscompiler.util.TagsCompilerSessionUtil;
029    
030    import java.util.Collection;
031    
032    import javax.portlet.RenderRequest;
033    import javax.portlet.RenderResponse;
034    
035    import javax.servlet.http.HttpServletRequest;
036    
037    /**
038     * @author Brian Wing Shun Chan
039     */
040    public class TagsCompilerPortlet extends LiferayPortlet {
041    
042            public void render(
043                    RenderRequest renderRequest, RenderResponse renderResponse) {
044    
045                    // Compile entries
046    
047                    String entriesFromURL = ParamUtil.getString(renderRequest, "entries");
048                    String[] entriesFromURLArray = StringUtil.split(entriesFromURL);
049    
050                    if (_log.isDebugEnabled()) {
051                            _log.debug("Entries from friendly URL " + entriesFromURL);
052                    }
053    
054                    Collection<String> entriesFromSession =
055                            TagsCompilerSessionUtil.getEntries(renderRequest);
056                    String[] entriesFromSessionArray = entriesFromSession.toArray(
057                            new String[entriesFromSession.size()]);
058    
059                    if (_log.isDebugEnabled()) {
060                            _log.debug(
061                                    "Entries from session " +
062                                            StringUtil.merge(entriesFromSessionArray));
063                    }
064    
065                    String[] entries = ArrayUtil.append(
066                            entriesFromURLArray, entriesFromSessionArray);
067    
068                    renderRequest.setAttribute(WebKeys.TAGS_COMPILER_ENTRIES, entries);
069    
070                    // Clear render parameters cache
071    
072                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
073                            renderRequest);
074    
075                    ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
076                            WebKeys.THEME_DISPLAY);
077    
078                    RenderParametersPool.clear(
079                            request, themeDisplay.getPlid(), PortletKeys.TAGS_COMPILER);
080            }
081    
082            private static Log _log = LogFactoryUtil.getLog(TagsCompilerPortlet.class);
083    
084    }