1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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              null, servletContext, request, response, portlet, queryString,
89              columnId, new Integer(columnPos), new Integer(columnCount));
90  
91          return null;
92      }
93  
94  }