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.portlet.mypages.action;
16  
17  import com.liferay.portal.model.Group;
18  import com.liferay.portal.model.RoleConstants;
19  import com.liferay.portal.model.User;
20  import com.liferay.portal.service.RoleLocalServiceUtil;
21  import com.liferay.portal.struts.PortletAction;
22  import com.liferay.portal.util.PortalUtil;
23  import com.liferay.portal.util.PropsValues;
24  import com.liferay.portlet.RenderRequestImpl;
25  import com.liferay.portlet.communities.action.ActionUtil;
26  import com.liferay.util.servlet.DynamicServletRequest;
27  
28  import javax.portlet.PortletConfig;
29  import javax.portlet.RenderRequest;
30  import javax.portlet.RenderResponse;
31  import javax.portlet.WindowState;
32  
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="ViewAction.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Jorge Ferrer
41   * @author Amos Fong
42   */
43  public class ViewAction extends PortletAction {
44  
45      public ActionForward render(
46              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
47              RenderRequest renderRequest, RenderResponse renderResponse)
48          throws Exception {
49  
50          if (renderRequest.getRemoteUser() == null) {
51              return mapping.findForward("portlet.my_pages.view");
52          }
53  
54          if (!renderRequest.getWindowState().equals(WindowState.MAXIMIZED)) {
55              return mapping.findForward("portlet.my_pages.view");
56          }
57  
58          User user = PortalUtil.getUser(renderRequest);
59  
60          RenderRequestImpl renderRequestImpl = (RenderRequestImpl)renderRequest;
61  
62          DynamicServletRequest dynamicRequest =
63              (DynamicServletRequest)renderRequestImpl.getHttpServletRequest();
64  
65          dynamicRequest.setParameter(
66              "p_u_i_d", String.valueOf(user.getUserId()));
67  
68          String tabs1 = "public-pages";
69  
70          boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
71              user.getUserId(), user.getCompanyId(), RoleConstants.POWER_USER,
72              true);
73  
74          if (!PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_MODIFIABLE ||
75              (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
76               !hasPowerUserRole)) {
77  
78              tabs1 = "private-pages";
79          }
80  
81          dynamicRequest.setParameter("tabs1", tabs1);
82  
83          Group group = user.getGroup();
84  
85          dynamicRequest.setParameter(
86              "groupId", String.valueOf(group.getGroupId()));
87  
88          ActionUtil.getGroup(renderRequest);
89  
90          return mapping.findForward("portlet.my_pages.edit_pages");
91      }
92  
93  }