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.util.GetterUtil;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.kernel.util.WebKeys;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.model.Layout;
023    import com.liferay.portal.service.GroupLocalServiceUtil;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portlet.exportimport.staging.StagingUtil;
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                    String privateLayoutString = request.getParameter("privateLayout");
067    
068                    if (Validator.isNull(privateLayoutString)) {
069                            privateLayoutString = String.valueOf(
070                                    request.getAttribute(WebKeys.PRIVATE_LAYOUT));
071                    }
072    
073                    boolean privateLayout = GetterUtil.getBoolean(
074                            privateLayoutString, layout.isPrivateLayout());
075    
076                    pageContext.setAttribute("privateLayout", privateLayout);
077    
078                    pageContext.setAttribute("stagingGroup", null);
079                    pageContext.setAttribute("stagingGroupId", 0L);
080    
081                    if (!group.isStaged() && !group.isStagedRemotely() &&
082                            !group.hasLocalOrRemoteStagingGroup()) {
083    
084                            return SKIP_BODY;
085                    }
086    
087                    Group liveGroup = StagingUtil.getLiveGroup(group.getGroupId());
088                    Group stagingGroup = StagingUtil.getStagingGroup(group.getGroupId());
089    
090                    pageContext.setAttribute("liveGroup", liveGroup);
091                    pageContext.setAttribute("liveGroupId", liveGroup.getGroupId());
092                    pageContext.setAttribute("stagingGroup", stagingGroup);
093                    pageContext.setAttribute("stagingGroupId", stagingGroup.getGroupId());
094    
095                    if (Validator.isNotNull(_portletId)) {
096                            boolean stagedPortlet = liveGroup.isStagedPortlet(_portletId);
097    
098                            if (group.isStagedRemotely()) {
099                                    stagedPortlet = stagingGroup.isStagedPortlet(_portletId);
100                            }
101    
102                            if (stagedPortlet) {
103                                    pageContext.setAttribute("group", stagingGroup);
104                                    pageContext.setAttribute("groupId", stagingGroup.getGroupId());
105                                    pageContext.setAttribute("scopeGroup", stagingGroup);
106                                    pageContext.setAttribute(
107                                            "scopeGroupId", stagingGroup.getGroupId());
108                            }
109                    }
110    
111                    return SKIP_BODY;
112            }
113    
114            @Override
115            public void setPortletId(String portletId) {
116                    _portletId = portletId;
117            }
118    
119            @Override
120            protected void cleanUp() {
121                    _portletId = null;
122            }
123    
124            private String _portletId;
125    
126    }