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