001    /**
002     * Copyright (c) 2000-present 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.taglib.staging;
016    
017    import com.liferay.portal.kernel.staging.StagingUtil;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.kernel.util.ParamUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.kernel.util.WebKeys;
022    import com.liferay.portal.model.Group;
023    import com.liferay.portal.model.Layout;
024    import com.liferay.portal.service.GroupLocalServiceUtil;
025    import com.liferay.portal.theme.ThemeDisplay;
026    import com.liferay.taglib.util.IncludeTag;
027    
028    import javax.servlet.http.HttpServletRequest;
029    
030    /**
031     * @author Levente Hud??k
032     */
033    public class DefineObjectsTag extends IncludeTag {
034    
035            @Override
036            public int doStartTag() {
037                    HttpServletRequest request =
038                            (HttpServletRequest)pageContext.getRequest();
039    
040                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
041                            WebKeys.THEME_DISPLAY);
042    
043                    long groupId = ParamUtil.getLong(request, "groupId");
044    
045                    Group group = GroupLocalServiceUtil.fetchGroup(groupId);
046    
047                    if (group == null) {
048                            group = (Group)request.getAttribute(WebKeys.GROUP);
049                    }
050    
051                    if (group == null) {
052                            group = themeDisplay.getScopeGroup();
053                    }
054    
055                    if (group == null) {
056                            return SKIP_BODY;
057                    }
058    
059                    pageContext.setAttribute("group", group);
060                    pageContext.setAttribute("groupId", group.getGroupId());
061                    pageContext.setAttribute("liveGroup", null);
062                    pageContext.setAttribute("liveGroupId", 0L);
063    
064                    Layout layout = themeDisplay.getLayout();
065    
066                    boolean privateLayout = GetterUtil.getBoolean(
067                            ParamUtil.getBoolean(
068                                    request, "privateLayout", layout.isPrivateLayout()));
069    
070                    pageContext.setAttribute("privateLayout", privateLayout);
071    
072                    pageContext.setAttribute("stagingGroup", null);
073                    pageContext.setAttribute("stagingGroupId", 0L);
074    
075                    if (!group.isStaged() && !group.isStagedRemotely() &&
076                            !group.hasLocalOrRemoteStagingGroup()) {
077    
078                            return SKIP_BODY;
079                    }
080    
081                    Group liveGroup = StagingUtil.getLiveGroup(group.getGroupId());
082                    Group stagingGroup = StagingUtil.getStagingGroup(group.getGroupId());
083    
084                    pageContext.setAttribute("liveGroup", liveGroup);
085                    pageContext.setAttribute("liveGroupId", liveGroup.getGroupId());
086                    pageContext.setAttribute("stagingGroup", stagingGroup);
087                    pageContext.setAttribute("stagingGroupId", stagingGroup.getGroupId());
088    
089                    if (Validator.isNotNull(_portletId)) {
090                            boolean stagedPortlet = liveGroup.isStagedPortlet(_portletId);
091    
092                            if (group.isStagedRemotely()) {
093                                    stagedPortlet = stagingGroup.isStagedPortlet(_portletId);
094                            }
095    
096                            if (stagedPortlet) {
097                                    pageContext.setAttribute("group", stagingGroup);
098                                    pageContext.setAttribute("groupId", stagingGroup.getGroupId());
099                                    pageContext.setAttribute("scopeGroup", stagingGroup);
100                                    pageContext.setAttribute(
101                                            "scopeGroupId", stagingGroup.getGroupId());
102                            }
103                    }
104    
105                    return SKIP_BODY;
106            }
107    
108            @Override
109            public void setPortletId(String portletId) {
110                    _portletId = portletId;
111            }
112    
113            @Override
114            protected void cleanUp() {
115                    _portletId = null;
116            }
117    
118            private String _portletId;
119    
120    }