1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.mypages.action;
24  
25  import com.liferay.portal.model.Group;
26  import com.liferay.portal.model.RoleConstants;
27  import com.liferay.portal.model.User;
28  import com.liferay.portal.service.RoleLocalServiceUtil;
29  import com.liferay.portal.struts.PortletAction;
30  import com.liferay.portal.util.PortalUtil;
31  import com.liferay.portal.util.PropsValues;
32  import com.liferay.portlet.RenderRequestImpl;
33  import com.liferay.portlet.communities.action.ActionUtil;
34  import com.liferay.util.servlet.DynamicServletRequest;
35  
36  import javax.portlet.PortletConfig;
37  import javax.portlet.RenderRequest;
38  import javax.portlet.RenderResponse;
39  import javax.portlet.WindowState;
40  
41  import org.apache.struts.action.ActionForm;
42  import org.apache.struts.action.ActionForward;
43  import org.apache.struts.action.ActionMapping;
44  
45  /**
46   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Jorge Ferrer
49   * @author Amos Fong
50   */
51  public class ViewAction extends PortletAction {
52  
53      public ActionForward render(
54              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
55              RenderRequest renderRequest, RenderResponse renderResponse)
56          throws Exception {
57  
58          if (renderRequest.getRemoteUser() == null) {
59              return mapping.findForward("portlet.my_pages.view");
60          }
61  
62          if (!renderRequest.getWindowState().equals(WindowState.MAXIMIZED)) {
63              return mapping.findForward("portlet.my_pages.view");
64          }
65  
66          User user = PortalUtil.getUser(renderRequest);
67  
68          RenderRequestImpl renderRequestImpl = (RenderRequestImpl)renderRequest;
69  
70          DynamicServletRequest dynamicRequest =
71              (DynamicServletRequest)renderRequestImpl.getHttpServletRequest();
72  
73          dynamicRequest.setParameter(
74              "p_u_i_d", String.valueOf(user.getUserId()));
75  
76          String tabs1 = "public-pages";
77  
78          boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
79              user.getUserId(), user.getCompanyId(), RoleConstants.POWER_USER,
80              true);
81  
82          if (!PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_MODIFIABLE ||
83              (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
84               !hasPowerUserRole)) {
85  
86              tabs1 = "private-pages";
87          }
88  
89          dynamicRequest.setParameter("tabs1", tabs1);
90  
91          Group group = user.getGroup();
92  
93          dynamicRequest.setParameter(
94              "groupId", String.valueOf(group.getGroupId()));
95  
96          ActionUtil.getGroup(renderRequest);
97  
98          return mapping.findForward("portlet.my_pages.edit_pages");
99      }
100 
101 }