001
014
015 package com.liferay.portlet.layoutsadmin.display.context;
016
017 import com.liferay.portal.kernel.util.ParamUtil;
018 import com.liferay.portal.kernel.util.UnicodeProperties;
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 import com.liferay.portlet.exportimport.staging.StagingUtil;
024
025 import javax.servlet.http.HttpServletRequest;
026
027
030 public class GroupDisplayContextHelper {
031
032 public GroupDisplayContextHelper(HttpServletRequest request) {
033 _request = request;
034 }
035
036 public Group getGroup() {
037 if (_group != null) {
038 return _group;
039 }
040
041 if (getStagingGroup() != null) {
042 _group = getStagingGroup();
043 }
044 else {
045 _group = getLiveGroup();
046 }
047
048 return _group;
049 }
050
051 public Long getGroupId() {
052 if (_groupId != null) {
053 return _groupId;
054 }
055
056 Group group = getGroup();
057
058 if (group != null) {
059 _groupId = group.getGroupId();
060 }
061
062 return _groupId;
063 }
064
065 public UnicodeProperties getGroupTypeSettings() {
066 if (_groupTypeSettings != null) {
067 return _groupTypeSettings;
068 }
069
070 Group group = getGroup();
071
072 if (group != null) {
073 _groupTypeSettings = group.getTypeSettingsProperties();
074 }
075 else {
076 _groupTypeSettings = new UnicodeProperties();
077 }
078
079 return _groupTypeSettings;
080 }
081
082 public Group getLiveGroup() {
083 if (_liveGroup != null) {
084 return _liveGroup;
085 }
086
087 Group group = getSelGroup();
088
089 if (group == null) {
090 return null;
091 }
092
093 _liveGroup = StagingUtil.getLiveGroup(group.getGroupId());
094
095 return _liveGroup;
096 }
097
098 public Long getLiveGroupId() {
099 if (_liveGroupId != null) {
100 return _liveGroupId;
101 }
102
103 Group liveGroup = getLiveGroup();
104
105 if (liveGroup != null) {
106 _liveGroupId = liveGroup.getGroupId();
107 }
108
109 return _liveGroupId;
110 }
111
112 public Group getSelGroup() {
113 if (_selGroup != null) {
114 return _selGroup;
115 }
116
117 long groupId = ParamUtil.getLong(_request, "groupId");
118
119 _selGroup = GroupLocalServiceUtil.fetchGroup(groupId);
120
121 if (_selGroup == null) {
122 _selGroup = (Group)_request.getAttribute(WebKeys.GROUP);
123 }
124
125 if (_selGroup == null) {
126 ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute(
127 WebKeys.THEME_DISPLAY);
128
129 _selGroup = themeDisplay.getScopeGroup();
130 }
131
132 return _selGroup;
133 }
134
135 public Group getStagingGroup() {
136 if (_stagingGroup != null) {
137 return _stagingGroup;
138 }
139
140 Group group = getSelGroup();
141
142 if (group == null) {
143 return null;
144 }
145
146 _stagingGroup = StagingUtil.getStagingGroup(group.getGroupId());
147
148 return _stagingGroup;
149 }
150
151 public Long getStagingGroupId() {
152 if (_stagingGroupId != null) {
153 return _stagingGroupId;
154 }
155
156 Group stagingGroup = getStagingGroup();
157
158 if (stagingGroup != null) {
159 _stagingGroupId = stagingGroup.getGroupId();
160 }
161
162 return _stagingGroupId;
163 }
164
165 private Group _group;
166 private Long _groupId;
167 private UnicodeProperties _groupTypeSettings;
168 private Group _liveGroup;
169 private Long _liveGroupId;
170 private final HttpServletRequest _request;
171 private Group _selGroup;
172 private Group _stagingGroup;
173 private Long _stagingGroupId;
174
175 }