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.portal.action;
016    
017    import com.liferay.portal.kernel.portlet.WindowStateFactory;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.model.Layout;
020    import com.liferay.portal.model.Portlet;
021    import com.liferay.portal.model.User;
022    import com.liferay.portal.service.PortletLocalServiceUtil;
023    import com.liferay.portal.util.PortalUtil;
024    import com.liferay.portal.util.WebKeys;
025    
026    import javax.portlet.WindowState;
027    
028    import javax.servlet.ServletContext;
029    import javax.servlet.http.HttpServletRequest;
030    import javax.servlet.http.HttpServletResponse;
031    
032    import org.apache.struts.action.Action;
033    import org.apache.struts.action.ActionForm;
034    import org.apache.struts.action.ActionForward;
035    import org.apache.struts.action.ActionMapping;
036    
037    /**
038     * @author Brian Wing Shun Chan
039     */
040    public class RenderPortletAction extends Action {
041    
042            public ActionForward execute(
043                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
044                            HttpServletResponse response)
045                    throws Exception {
046    
047                    ServletContext servletContext = (ServletContext)request.getAttribute(
048                            WebKeys.CTX);
049    
050                    String ajaxId = request.getParameter("ajax_id");
051    
052                    long companyId = PortalUtil.getCompanyId(request);
053                    User user = PortalUtil.getUser(request);
054                    Layout layout = (Layout)request.getAttribute(WebKeys.LAYOUT);
055                    String portletId = ParamUtil.getString(request, "p_p_id");
056    
057                    Portlet portlet = PortletLocalServiceUtil.getPortletById(
058                            companyId, portletId);
059    
060                    String queryString = null;
061                    String columnId = ParamUtil.getString(request, "p_p_col_id");
062                    int columnPos = ParamUtil.getInteger(request, "p_p_col_pos");
063                    int columnCount = ParamUtil.getInteger(request, "p_p_col_count");
064                    boolean staticPortlet = ParamUtil.getBoolean(request, "p_p_static");
065                    boolean staticStartPortlet = ParamUtil.getBoolean(
066                            request, "p_p_static_start");
067    
068                    if (staticPortlet) {
069                            portlet = (Portlet)portlet.clone();
070    
071                            portlet.setStatic(true);
072                            portlet.setStaticStart(staticStartPortlet);
073                    }
074    
075                    if (ajaxId != null) {
076                            response.setHeader("Ajax-ID", ajaxId);
077                    }
078    
079                    WindowState windowState = WindowStateFactory.getWindowState(
080                            ParamUtil.getString(request, "p_p_state"));
081    
082                    PortalUtil.updateWindowState(
083                            portletId, user, layout, windowState, request);
084    
085                    PortalUtil.renderPortlet(
086                            servletContext, request, response, portlet, queryString, columnId,
087                            new Integer(columnPos), new Integer(columnCount), true);
088    
089                    return null;
090            }
091    
092    }