001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.mypages.action;
016    
017    import com.liferay.portal.model.Group;
018    import com.liferay.portal.model.RoleConstants;
019    import com.liferay.portal.model.User;
020    import com.liferay.portal.service.RoleLocalServiceUtil;
021    import com.liferay.portal.struts.PortletAction;
022    import com.liferay.portal.util.PortalUtil;
023    import com.liferay.portal.util.PropsValues;
024    import com.liferay.portlet.RenderRequestImpl;
025    import com.liferay.portlet.communities.action.ActionUtil;
026    import com.liferay.util.servlet.DynamicServletRequest;
027    
028    import javax.portlet.PortletConfig;
029    import javax.portlet.RenderRequest;
030    import javax.portlet.RenderResponse;
031    import javax.portlet.WindowState;
032    
033    import org.apache.struts.action.ActionForm;
034    import org.apache.struts.action.ActionForward;
035    import org.apache.struts.action.ActionMapping;
036    
037    /**
038     * @author Jorge Ferrer
039     * @author Amos Fong
040     */
041    public class ViewAction extends PortletAction {
042    
043            public ActionForward render(
044                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
045                            RenderRequest renderRequest, RenderResponse renderResponse)
046                    throws Exception {
047    
048                    if (renderRequest.getRemoteUser() == null) {
049                            return mapping.findForward("portlet.my_pages.view");
050                    }
051    
052                    if (!renderRequest.getWindowState().equals(WindowState.MAXIMIZED)) {
053                            return mapping.findForward("portlet.my_pages.view");
054                    }
055    
056                    User user = PortalUtil.getUser(renderRequest);
057    
058                    RenderRequestImpl renderRequestImpl = (RenderRequestImpl)renderRequest;
059    
060                    DynamicServletRequest dynamicRequest =
061                            (DynamicServletRequest)renderRequestImpl.getHttpServletRequest();
062    
063                    dynamicRequest.setParameter(
064                            "p_u_i_d", String.valueOf(user.getUserId()));
065    
066                    String tabs1 = "public-pages";
067    
068                    boolean hasPowerUserRole = RoleLocalServiceUtil.hasUserRole(
069                            user.getUserId(), user.getCompanyId(), RoleConstants.POWER_USER,
070                            true);
071    
072                    if (!PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_MODIFIABLE ||
073                            (PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED &&
074                             !hasPowerUserRole)) {
075    
076                            tabs1 = "private-pages";
077                    }
078    
079                    dynamicRequest.setParameter("tabs1", tabs1);
080    
081                    Group group = user.getGroup();
082    
083                    dynamicRequest.setParameter(
084                            "groupId", String.valueOf(group.getGroupId()));
085    
086                    ActionUtil.getGroup(renderRequest);
087    
088                    return mapping.findForward("portlet.my_pages.edit_pages");
089            }
090    
091    }