001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }