1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.action;
16  
17  import com.liferay.portal.kernel.portlet.WindowStateFactory;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.model.Layout;
20  import com.liferay.portal.model.Portlet;
21  import com.liferay.portal.model.User;
22  import com.liferay.portal.service.PortletLocalServiceUtil;
23  import com.liferay.portal.util.PortalUtil;
24  import com.liferay.portal.util.WebKeys;
25  
26  import javax.portlet.WindowState;
27  
28  import javax.servlet.ServletContext;
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  
32  import org.apache.struts.action.Action;
33  import org.apache.struts.action.ActionForm;
34  import org.apache.struts.action.ActionForward;
35  import org.apache.struts.action.ActionMapping;
36  
37  /**
38   * <a href="RenderPortletAction.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class RenderPortletAction extends Action {
43  
44      public ActionForward execute(
45              ActionMapping mapping, ActionForm form, HttpServletRequest request,
46              HttpServletResponse response)
47          throws Exception {
48  
49          ServletContext servletContext = (ServletContext)request.getAttribute(
50              WebKeys.CTX);
51  
52          String ajaxId = request.getParameter("ajax_id");
53  
54          long companyId = PortalUtil.getCompanyId(request);
55          User user = PortalUtil.getUser(request);
56          Layout layout = (Layout)request.getAttribute(WebKeys.LAYOUT);
57          String portletId = ParamUtil.getString(request, "p_p_id");
58  
59          Portlet portlet = PortletLocalServiceUtil.getPortletById(
60              companyId, portletId);
61  
62          String queryString = null;
63          String columnId = ParamUtil.getString(request, "p_p_col_id");
64          int columnPos = ParamUtil.getInteger(request, "p_p_col_pos");
65          int columnCount = ParamUtil.getInteger(request, "p_p_col_count");
66          boolean staticPortlet = ParamUtil.getBoolean(request, "p_p_static");
67          boolean staticStartPortlet = ParamUtil.getBoolean(
68              request, "p_p_static_start");
69  
70          if (staticPortlet) {
71              portlet = (Portlet)portlet.clone();
72  
73              portlet.setStatic(true);
74              portlet.setStaticStart(staticStartPortlet);
75          }
76  
77          if (ajaxId != null) {
78              response.setHeader("Ajax-ID", ajaxId);
79          }
80  
81          WindowState windowState = WindowStateFactory.getWindowState(
82              ParamUtil.getString(request, "p_p_state"));
83  
84          PortalUtil.updateWindowState(
85              portletId, user, layout, windowState, request);
86  
87          PortalUtil.renderPortlet(
88              servletContext, request, response, portlet, queryString, columnId,
89              new Integer(columnPos), new Integer(columnCount), true);
90  
91          return null;
92      }
93  
94  }