001    /**
002     * Copyright (c) 2000-present 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.portal.action;
016    
017    import com.liferay.portal.kernel.portlet.PortletContainerUtil;
018    import com.liferay.portal.kernel.portlet.WindowStateFactory;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.kernel.util.WebKeys;
022    import com.liferay.portal.model.Layout;
023    import com.liferay.portal.model.Portlet;
024    import com.liferay.portal.model.User;
025    import com.liferay.portal.service.PortletLocalServiceUtil;
026    import com.liferay.portal.theme.ThemeDisplay;
027    import com.liferay.portal.util.PortalUtil;
028    
029    import javax.portlet.WindowState;
030    
031    import javax.servlet.http.HttpServletRequest;
032    import javax.servlet.http.HttpServletResponse;
033    
034    import org.apache.struts.action.Action;
035    import org.apache.struts.action.ActionForm;
036    import org.apache.struts.action.ActionForward;
037    import org.apache.struts.action.ActionMapping;
038    
039    /**
040     * @author Brian Wing Shun Chan
041     */
042    public class RenderPortletAction extends Action {
043    
044            @Override
045            public ActionForward execute(
046                            ActionMapping actionMapping, ActionForm actionForm,
047                            HttpServletRequest request, HttpServletResponse response)
048                    throws Exception {
049    
050                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
051                            WebKeys.THEME_DISPLAY);
052    
053                    themeDisplay.setAjax(true);
054    
055                    String ajaxId = request.getParameter("ajax_id");
056    
057                    long companyId = PortalUtil.getCompanyId(request);
058                    User user = PortalUtil.getUser(request);
059                    Layout layout = (Layout)request.getAttribute(WebKeys.LAYOUT);
060                    String portletId = ParamUtil.getString(request, "p_p_id");
061    
062                    Portlet portlet = PortletLocalServiceUtil.getPortletById(
063                            companyId, portletId);
064    
065                    String columnId = ParamUtil.getString(request, "p_p_col_id");
066                    int columnPos = ParamUtil.getInteger(request, "p_p_col_pos");
067                    int columnCount = ParamUtil.getInteger(request, "p_p_col_count");
068    
069                    Boolean boundary = null;
070    
071                    String boundaryParam = ParamUtil.getString(
072                            request, "p_p_boundary", null);
073    
074                    if (boundaryParam != null) {
075                            boundary = GetterUtil.getBoolean(boundaryParam);
076                    }
077    
078                    Boolean decorate = null;
079    
080                    String decorateParam = ParamUtil.getString(
081                            request, "p_p_decorate", null);
082    
083                    if (decorateParam != null) {
084                            decorate = GetterUtil.getBoolean(decorateParam);
085                    }
086    
087                    boolean staticPortlet = ParamUtil.getBoolean(request, "p_p_static");
088                    boolean staticStartPortlet = ParamUtil.getBoolean(
089                            request, "p_p_static_start");
090    
091                    if (staticPortlet) {
092                            portlet = (Portlet)portlet.clone();
093    
094                            portlet.setStatic(true);
095                            portlet.setStaticStart(staticStartPortlet);
096                    }
097    
098                    if (ajaxId != null) {
099                            response.setHeader("Ajax-ID", ajaxId);
100                    }
101    
102                    WindowState windowState = WindowStateFactory.getWindowState(
103                            ParamUtil.getString(request, "p_p_state"));
104    
105                    PortalUtil.updateWindowState(
106                            portletId, user, layout, windowState, request);
107    
108                    request = PortletContainerUtil.setupOptionalRenderParameters(
109                            request, null, columnId, columnPos, columnCount, boundary,
110                            decorate);
111    
112                    PortletContainerUtil.render(request, response, portlet);
113    
114                    return null;
115            }
116    
117    }