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.ParamUtil;
019    import com.liferay.portal.kernel.util.WebKeys;
020    import com.liferay.portal.model.Group;
021    import com.liferay.portal.service.GroupLocalServiceUtil;
022    import com.liferay.portal.theme.ThemeDisplay;
023    
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.jsp.tagext.TagSupport;
026    
027    /**
028     * @author Levente Hud??k
029     */
030    public class DefineObjectsTag extends TagSupport {
031    
032            @Override
033            public int doStartTag() {
034                    HttpServletRequest request =
035                            (HttpServletRequest)pageContext.getRequest();
036    
037                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
038                            WebKeys.THEME_DISPLAY);
039    
040                    long groupId = ParamUtil.getLong(request, "groupId");
041    
042                    Group group = GroupLocalServiceUtil.fetchGroup(groupId);
043    
044                    if (group == null) {
045                            group = (Group)request.getAttribute(WebKeys.GROUP);
046                    }
047    
048                    if (group == null) {
049                            group = themeDisplay.getScopeGroup();
050                    }
051    
052                    if (group == null) {
053                            return SKIP_BODY;
054                    }
055    
056                    Group liveGroup = StagingUtil.getLiveGroup(group.getGroupId());
057                    Group stagingGroup = StagingUtil.getStagingGroup(group.getGroupId());
058    
059                    pageContext.setAttribute("group", group);
060                    pageContext.setAttribute("groupId", group.getGroupId());
061                    pageContext.setAttribute("liveGroup", liveGroup);
062                    pageContext.setAttribute("liveGroupId", liveGroup.getGroupId());
063                    pageContext.setAttribute(
064                            "privateLayout", ParamUtil.getBoolean(request, "privateLayout"));
065                    pageContext.setAttribute("stagingGroup", stagingGroup);
066                    pageContext.setAttribute("stagingGroupId", stagingGroup.getGroupId());
067    
068                    return SKIP_BODY;
069            }
070    
071    }