001
014
015 package com.liferay.portlet.bookmarks.asset;
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.security.permission.ActionKeys;
022 import com.liferay.portal.security.permission.PermissionChecker;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portal.util.PortletKeys;
025 import com.liferay.portal.util.WebKeys;
026 import com.liferay.portlet.PortletURLFactoryUtil;
027 import com.liferay.portlet.asset.model.AssetRenderer;
028 import com.liferay.portlet.asset.model.BaseAssetRendererFactory;
029 import com.liferay.portlet.assetpublisher.util.AssetPublisherUtil;
030 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
031 import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
032 import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
033 import com.liferay.portlet.bookmarks.service.permission.BookmarksPermission;
034
035 import javax.portlet.PortletRequest;
036 import javax.portlet.PortletURL;
037
038
044 public class BookmarksEntryAssetRendererFactory
045 extends BaseAssetRendererFactory {
046
047 public static final String CLASS_NAME = BookmarksEntry.class.getName();
048
049 public static final String TYPE = "bookmark";
050
051 public AssetRenderer getAssetRenderer(long classPK, int type)
052 throws PortalException, SystemException {
053
054 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
055
056 return new BookmarksEntryAssetRenderer(entry);
057 }
058
059 public String getClassName() {
060 return CLASS_NAME;
061 }
062
063 public String getType() {
064 return TYPE;
065 }
066
067 @Override
068 public PortletURL getURLAdd(
069 LiferayPortletRequest liferayPortletRequest,
070 LiferayPortletResponse liferayPortletResponse)
071 throws PortalException, SystemException {
072
073 ThemeDisplay themeDisplay =
074 (ThemeDisplay)liferayPortletRequest.getAttribute(
075 WebKeys.THEME_DISPLAY);
076
077 if (!BookmarksPermission.contains(
078 themeDisplay.getPermissionChecker(),
079 themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
080
081 return null;
082 }
083
084 PortletURL portletURL = PortletURLFactoryUtil.create(
085 liferayPortletRequest, PortletKeys.BOOKMARKS,
086 getControlPanelPlid(themeDisplay), PortletRequest.RENDER_PHASE);
087
088 portletURL.setParameter("struts_action", "/bookmarks/edit_entry");
089 portletURL.setParameter(
090 "folderId",
091 String.valueOf(
092 AssetPublisherUtil.getRecentFolderId(
093 liferayPortletRequest, CLASS_NAME)));
094
095 return portletURL;
096 }
097
098 @Override
099 public boolean hasPermission(
100 PermissionChecker permissionChecker, long classPK, String actionId)
101 throws Exception {
102
103 return BookmarksEntryPermission.contains(
104 permissionChecker, classPK, actionId);
105 }
106
107 @Override
108 public boolean isLinkable() {
109 return _LINKABLE;
110 }
111
112 @Override
113 protected String getIconPath(ThemeDisplay themeDisplay) {
114 return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
115 }
116
117 private static final boolean _LINKABLE = true;
118
119 }