001
014
015 package com.liferay.portlet.asset.model;
016
017 import com.liferay.portal.kernel.exception.PortalException;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
020 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
021 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
022 import com.liferay.portal.kernel.util.HttpUtil;
023 import com.liferay.portal.kernel.util.ParamUtil;
024 import com.liferay.portal.kernel.util.StringBundler;
025 import com.liferay.portal.kernel.util.StringPool;
026 import com.liferay.portal.kernel.util.Validator;
027 import com.liferay.portal.kernel.util.WebKeys;
028 import com.liferay.portal.model.Group;
029 import com.liferay.portal.model.GroupConstants;
030 import com.liferay.portal.model.Layout;
031 import com.liferay.portal.security.permission.PermissionChecker;
032 import com.liferay.portal.service.GroupLocalServiceUtil;
033 import com.liferay.portal.service.LayoutLocalServiceUtil;
034 import com.liferay.portal.theme.PortletDisplay;
035 import com.liferay.portal.theme.ThemeDisplay;
036
037 import java.util.Locale;
038
039 import javax.portlet.PortletMode;
040 import javax.portlet.PortletRequest;
041 import javax.portlet.PortletURL;
042 import javax.portlet.WindowState;
043
044 import javax.servlet.http.HttpServletRequest;
045
046
050 public abstract class BaseAssetRenderer implements AssetRenderer {
051
052 @Override
053 public String[] getAvailableLocales() {
054 return _AVAILABLE_LOCALES;
055 }
056
057 @Override
058 public String getDiscussionPath() {
059 return null;
060 }
061
062 @Override
063 public String getIconPath(PortletRequest portletRequest) {
064 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
065 WebKeys.THEME_DISPLAY);
066
067 return getIconPath(themeDisplay);
068 }
069
070 @Override
071 public String getSearchSummary(Locale locale) {
072 return getSummary(locale);
073 }
074
075 @Override
076 public PortletURL getURLEdit(
077 LiferayPortletRequest liferayPortletRequest,
078 LiferayPortletResponse liferayPortletResponse)
079 throws Exception {
080
081 return null;
082 }
083
084 @Override
085 public PortletURL getURLEdit(
086 LiferayPortletRequest liferayPortletRequest,
087 LiferayPortletResponse liferayPortletResponse,
088 WindowState windowState, PortletURL redirectURL)
089 throws Exception {
090
091 LiferayPortletURL editPortletURL =
092 (LiferayPortletURL)getURLEdit(
093 liferayPortletRequest, liferayPortletResponse);
094
095 if (editPortletURL == null) {
096 return null;
097 }
098
099 ThemeDisplay themeDisplay =
100 (ThemeDisplay)liferayPortletRequest.getAttribute(
101 WebKeys.THEME_DISPLAY);
102
103 Group group = themeDisplay.getScopeGroup();
104
105 if (group.isLayout()) {
106 Layout layout = themeDisplay.getLayout();
107
108 group = layout.getGroup();
109 }
110
111 if (group.hasStagingGroup()) {
112 return null;
113 }
114
115 editPortletURL.setDoAsGroupId(getGroupId());
116
117 editPortletURL.setParameter("redirect", redirectURL.toString());
118 editPortletURL.setParameter("originalRedirect", redirectURL.toString());
119
120 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
121
122 String portletResource = ParamUtil.getString(
123 liferayPortletRequest, "portletResource", portletDisplay.getId());
124
125 if (Validator.isNotNull(portletResource)) {
126 editPortletURL.setParameter(
127 "referringPortletResource", portletResource);
128 }
129 else {
130 editPortletURL.setParameter(
131 "referringPortletResource", portletDisplay.getId());
132 }
133
134 editPortletURL.setPortletMode(PortletMode.VIEW);
135 editPortletURL.setRefererPlid(themeDisplay.getPlid());
136 editPortletURL.setWindowState(windowState);
137
138 return editPortletURL;
139 }
140
141 @Override
142 public PortletURL getURLExport(
143 LiferayPortletRequest liferayPortletRequest,
144 LiferayPortletResponse liferayPortletResponse)
145 throws Exception {
146
147 return null;
148 }
149
150 @Override
151 public String getUrlTitle() {
152 return null;
153 }
154
155 @Override
156 public PortletURL getURLView(
157 LiferayPortletResponse liferayPortletResponse,
158 WindowState windowState)
159 throws Exception {
160
161 return null;
162 }
163
164 @Override
165 public String getURLViewInContext(
166 LiferayPortletRequest liferayPortletRequest,
167 LiferayPortletResponse liferayPortletResponse,
168 String noSuchEntryRedirect)
169 throws Exception {
170
171 return null;
172 }
173
174 @Override
175 public String getViewInContextMessage() {
176 return "view-in-context";
177 }
178
179 @Override
180 @SuppressWarnings("unused")
181 public boolean hasEditPermission(PermissionChecker permissionChecker)
182 throws PortalException, SystemException {
183
184 return false;
185 }
186
187 @Override
188 @SuppressWarnings("unused")
189 public boolean hasViewPermission(PermissionChecker permissionChecker)
190 throws PortalException, SystemException {
191
192 return true;
193 }
194
195 @Override
196 public boolean isConvertible() {
197 return false;
198 }
199
200 @Override
201 public boolean isDisplayable() {
202 return true;
203 }
204
205 @Override
206 public boolean isLocalizable() {
207 return false;
208 }
209
210 @Override
211 public boolean isPreviewInContext() {
212 return false;
213 }
214
215 @Override
216 public boolean isPrintable() {
217 return false;
218 }
219
220 protected long getControlPanelPlid(
221 LiferayPortletRequest liferayPortletRequest)
222 throws PortalException, SystemException {
223
224 HttpServletRequest request =
225 liferayPortletRequest.getHttpServletRequest();
226
227 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
228 WebKeys.THEME_DISPLAY);
229
230 Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
231 themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
232
233 return LayoutLocalServiceUtil.getDefaultPlid(
234 controlPanelGroup.getGroupId(), true);
235 }
236
237 protected long getControlPanelPlid(ThemeDisplay themeDisplay)
238 throws PortalException, SystemException {
239
240 Group controlPanelGroup = GroupLocalServiceUtil.getGroup(
241 themeDisplay.getCompanyId(), GroupConstants.CONTROL_PANEL);
242
243 return LayoutLocalServiceUtil.getDefaultPlid(
244 controlPanelGroup.getGroupId(), true);
245 }
246
247 protected String getIconPath(ThemeDisplay themeDisplay) {
248 return themeDisplay.getPathThemeImages() + "/common/page.png";
249 }
250
251 protected String getURLViewInContext(
252 LiferayPortletRequest liferayPortletRequest, String noSuchEntryRedirect,
253 String path, String primaryKeyParameterName,
254 long primaryKeyParameterValue) {
255
256 ThemeDisplay themeDisplay =
257 (ThemeDisplay)liferayPortletRequest.getAttribute(
258 WebKeys.THEME_DISPLAY);
259
260 StringBundler sb = new StringBundler(11);
261
262 sb.append(themeDisplay.getPortalURL());
263 sb.append(themeDisplay.getPathMain());
264 sb.append(path);
265 sb.append("?p_l_id=");
266 sb.append(themeDisplay.getPlid());
267 sb.append("&noSuchEntryRedirect=");
268 sb.append(HttpUtil.encodeURL(noSuchEntryRedirect));
269 sb.append(StringPool.AMPERSAND);
270 sb.append(primaryKeyParameterName);
271 sb.append(StringPool.EQUAL);
272 sb.append(primaryKeyParameterValue);
273
274 return sb.toString();
275 }
276
277 private static final String[] _AVAILABLE_LOCALES = new String[0];
278
279 }