001    /**
002     * Copyright (c) 2000-2011 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.ParamUtil;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortalUtil;
024    import com.liferay.portal.util.PortletKeys;
025    import com.liferay.portal.util.WebKeys;
026    import com.liferay.portlet.RenderParametersPool;
027    import com.liferay.portlet.tagscompiler.util.TagsCompilerSessionUtil;
028    
029    import java.util.Collection;
030    
031    import javax.portlet.RenderRequest;
032    import javax.portlet.RenderResponse;
033    
034    import javax.servlet.http.HttpServletRequest;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    public class TagsCompilerPortlet extends LiferayPortlet {
040    
041            @Override
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    
057                    String[] entries =
058                            new String[entriesFromURLArray.length + entriesFromSession.size()];
059    
060                    System.arraycopy(
061                            entriesFromURLArray, 0, entries, 0, entriesFromURLArray.length);
062    
063                    int index = entriesFromURLArray.length;
064    
065                    for (String entry : entriesFromSession) {
066                            entries[index++] = entry;
067                    }
068    
069                    if (_log.isDebugEnabled()) {
070                            _log.debug(
071                                    "Entries from session " +
072                                            StringUtil.merge(entriesFromSession.toArray()));
073                    }
074    
075                    renderRequest.setAttribute(WebKeys.TAGS_COMPILER_ENTRIES, entries);
076    
077                    // Clear render parameters cache
078    
079                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
080                            renderRequest);
081    
082                    ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
083                            WebKeys.THEME_DISPLAY);
084    
085                    RenderParametersPool.clear(
086                            request, themeDisplay.getPlid(), PortletKeys.TAGS_COMPILER);
087            }
088    
089            private static Log _log = LogFactoryUtil.getLog(TagsCompilerPortlet.class);
090    
091    }