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.Layout;
030 import com.liferay.portal.security.permission.PermissionChecker;
031 import com.liferay.portal.theme.PortletDisplay;
032 import com.liferay.portal.theme.ThemeDisplay;
033 import com.liferay.portal.util.PortalUtil;
034 import com.liferay.portal.util.PortletKeys;
035 import com.liferay.portlet.asset.AssetRendererFactoryRegistryUtil;
036 import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
037 import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
038 import com.liferay.portlet.trash.util.TrashUtil;
039
040 import java.util.Date;
041 import java.util.Locale;
042
043 import javax.portlet.PortletMode;
044 import javax.portlet.PortletPreferences;
045 import javax.portlet.PortletRequest;
046 import javax.portlet.PortletResponse;
047 import javax.portlet.PortletURL;
048 import javax.portlet.RenderRequest;
049 import javax.portlet.RenderResponse;
050 import javax.portlet.WindowState;
051
052
056 public abstract class BaseAssetRenderer implements AssetRenderer {
057
058 @Override
059 public String getAddToPagePortletId() throws Exception {
060 return PortletKeys.ASSET_PUBLISHER;
061 }
062
063 public AssetRendererFactory getAssetRendererFactory() {
064 if (_assetRendererFactory != null) {
065 return _assetRendererFactory;
066 }
067
068 _assetRendererFactory =
069 AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
070 getClassName());
071
072 return _assetRendererFactory;
073 }
074
075 @Override
076 public int getAssetRendererType() {
077 return _assetRendererType;
078 }
079
080 @Override
081 public String[] getAvailableLanguageIds() {
082 return _AVAILABLE_LANGUAGE_IDS;
083 }
084
085
088 @Override
089 public String[] getAvailableLocales() {
090 return getAvailableLanguageIds();
091 }
092
093 @Override
094 public String getDiscussionPath() {
095 return null;
096 }
097
098 @Override
099 public Date getDisplayDate() {
100 return null;
101 }
102
103 @Override
104 public String getIconPath(PortletRequest portletRequest) {
105 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
106 WebKeys.THEME_DISPLAY);
107
108 return getIconPath(themeDisplay);
109 }
110
111 @Override
112 public String getNewName(String oldName, String token) {
113 return TrashUtil.getNewName(oldName, token);
114 }
115
116 @Override
117 public String getPreviewPath(
118 PortletRequest portletRequest, PortletResponse PortletResponse)
119 throws Exception {
120
121 return "/html/portlet/asset_publisher/display/preview.jsp";
122 }
123
124 @Override
125 public String getSearchSummary(Locale locale) {
126 return getSummary(locale);
127 }
128
129 @Override
130 public String getThumbnailPath(PortletRequest portletRequest)
131 throws Exception {
132
133 ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
134 WebKeys.THEME_DISPLAY);
135
136 return themeDisplay.getPathThemeImages() +
137 "/file_system/large/default.png";
138 }
139
140 @Override
141 public String getURLDownload(ThemeDisplay themeDisplay) {
142 return null;
143 }
144
145 @Override
146 public PortletURL getURLEdit(
147 LiferayPortletRequest liferayPortletRequest,
148 LiferayPortletResponse liferayPortletResponse)
149 throws Exception {
150
151 return null;
152 }
153
154 @Override
155 public PortletURL getURLEdit(
156 LiferayPortletRequest liferayPortletRequest,
157 LiferayPortletResponse liferayPortletResponse,
158 WindowState windowState, PortletURL redirectURL)
159 throws Exception {
160
161 LiferayPortletURL editPortletURL = (LiferayPortletURL)getURLEdit(
162 liferayPortletRequest, liferayPortletResponse);
163
164 if (editPortletURL == null) {
165 return null;
166 }
167
168 ThemeDisplay themeDisplay =
169 (ThemeDisplay)liferayPortletRequest.getAttribute(
170 WebKeys.THEME_DISPLAY);
171
172 Group group = themeDisplay.getScopeGroup();
173
174 if (group.isLayout()) {
175 Layout layout = themeDisplay.getLayout();
176
177 group = layout.getGroup();
178 }
179
180 if (group.hasStagingGroup()) {
181 return null;
182 }
183
184 editPortletURL.setDoAsGroupId(getGroupId());
185
186 editPortletURL.setParameter("redirect", redirectURL.toString());
187
188 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
189
190 String portletResource = ParamUtil.getString(
191 liferayPortletRequest, "portletResource", portletDisplay.getId());
192
193 if (Validator.isNotNull(portletResource)) {
194 editPortletURL.setParameter(
195 "referringPortletResource", portletResource);
196 }
197 else {
198 editPortletURL.setParameter(
199 "referringPortletResource", portletDisplay.getId());
200 }
201
202 editPortletURL.setPortletMode(PortletMode.VIEW);
203 editPortletURL.setRefererPlid(themeDisplay.getPlid());
204 editPortletURL.setWindowState(windowState);
205
206 return editPortletURL;
207 }
208
209 @Override
210 public PortletURL getURLExport(
211 LiferayPortletRequest liferayPortletRequest,
212 LiferayPortletResponse liferayPortletResponse)
213 throws Exception {
214
215 return null;
216 }
217
218 @Override
219 public String getURLImagePreview(PortletRequest portletRequest)
220 throws Exception {
221
222 return getThumbnailPath(portletRequest);
223 }
224
225 @Override
226 public String getUrlTitle() {
227 return null;
228 }
229
230 @Override
231 public PortletURL getURLView(
232 LiferayPortletResponse liferayPortletResponse,
233 WindowState windowState)
234 throws Exception {
235
236 return null;
237 }
238
239 @Override
240 public String getURLViewInContext(
241 LiferayPortletRequest liferayPortletRequest,
242 LiferayPortletResponse liferayPortletResponse,
243 String noSuchEntryRedirect)
244 throws Exception {
245
246 return null;
247 }
248
249 @Override
250 public String getViewInContextMessage() {
251 return "view-in-context";
252 }
253
254 @Override
255 @SuppressWarnings("unused")
256 public boolean hasEditPermission(PermissionChecker permissionChecker)
257 throws PortalException, SystemException {
258
259 return false;
260 }
261
262 @Override
263 @SuppressWarnings("unused")
264 public boolean hasViewPermission(PermissionChecker permissionChecker)
265 throws PortalException, SystemException {
266
267 return true;
268 }
269
270 @Override
271 public boolean isConvertible() {
272 return false;
273 }
274
275 @Override
276 public boolean isDisplayable() {
277 return true;
278 }
279
280 @Override
281 public boolean isLocalizable() {
282 return false;
283 }
284
285 @Override
286 public boolean isPreviewInContext() {
287 return false;
288 }
289
290 @Override
291 public boolean isPrintable() {
292 return false;
293 }
294
295 public String renderActions(
296 RenderRequest renderRequest, RenderResponse renderResponse)
297 throws Exception {
298
299 return null;
300 }
301
302 @Override
303 public void setAddToPagePreferences(
304 PortletPreferences preferences, String portletId,
305 ThemeDisplay themeDisplay)
306 throws Exception {
307
308 preferences.setValue("displayStyle", "full-content");
309 preferences.setValue(
310 "emailAssetEntryAddedEnabled", Boolean.FALSE.toString());
311 preferences.setValue("selectionStyle", "manual");
312 preferences.setValue("showAddContentButton", Boolean.FALSE.toString());
313
314 AssetEntry entry = AssetEntryLocalServiceUtil.getEntry(
315 getClassName(), getClassPK());
316
317 AssetPublisherUtil.addSelection(
318 themeDisplay, preferences, portletId, entry.getEntryId(), -1,
319 entry.getClassName());
320 }
321
322 public void setAssetRendererType(int assetRendererType) {
323 _assetRendererType = assetRendererType;
324 }
325
326 protected long getControlPanelPlid(
327 LiferayPortletRequest liferayPortletRequest)
328 throws PortalException, SystemException {
329
330 return PortalUtil.getControlPanelPlid(liferayPortletRequest);
331 }
332
333 protected long getControlPanelPlid(ThemeDisplay themeDisplay)
334 throws PortalException, SystemException {
335
336 return PortalUtil.getControlPanelPlid(themeDisplay.getCompanyId());
337 }
338
339 protected String getIconPath(ThemeDisplay themeDisplay) {
340 return themeDisplay.getPathThemeImages() + "/common/page.png";
341 }
342
343 protected String getURLViewInContext(
344 LiferayPortletRequest liferayPortletRequest, String noSuchEntryRedirect,
345 String path, String primaryKeyParameterName,
346 long primaryKeyParameterValue) {
347
348 ThemeDisplay themeDisplay =
349 (ThemeDisplay)liferayPortletRequest.getAttribute(
350 WebKeys.THEME_DISPLAY);
351
352 StringBundler sb = new StringBundler(11);
353
354 sb.append(themeDisplay.getPortalURL());
355 sb.append(themeDisplay.getPathMain());
356 sb.append(path);
357 sb.append("?p_l_id=");
358 sb.append(themeDisplay.getPlid());
359 sb.append("&noSuchEntryRedirect=");
360 sb.append(HttpUtil.encodeURL(noSuchEntryRedirect));
361 sb.append(StringPool.AMPERSAND);
362 sb.append(primaryKeyParameterName);
363 sb.append(StringPool.EQUAL);
364 sb.append(primaryKeyParameterValue);
365
366 return PortalUtil.addPreservedParameters(themeDisplay, sb.toString());
367 }
368
369 private static final String[] _AVAILABLE_LANGUAGE_IDS = new String[0];
370
371 private AssetRendererFactory _assetRendererFactory;
372 private int _assetRendererType = AssetRendererFactory.TYPE_LATEST_APPROVED;
373
374 }