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 TYPE = "bookmark";
048
049 @Override
050 public AssetRenderer getAssetRenderer(long classPK, int type)
051 throws PortalException, SystemException {
052
053 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
054
055 BookmarksEntryAssetRenderer bookmarksEntryAssetRenderer =
056 new BookmarksEntryAssetRenderer(entry);
057
058 bookmarksEntryAssetRenderer.setAssetRendererType(type);
059
060 return bookmarksEntryAssetRenderer;
061 }
062
063 @Override
064 public String getClassName() {
065 return BookmarksEntry.class.getName();
066 }
067
068 @Override
069 public String getType() {
070 return TYPE;
071 }
072
073 @Override
074 public PortletURL getURLAdd(
075 LiferayPortletRequest liferayPortletRequest,
076 LiferayPortletResponse liferayPortletResponse)
077 throws PortalException, SystemException {
078
079 ThemeDisplay themeDisplay =
080 (ThemeDisplay)liferayPortletRequest.getAttribute(
081 WebKeys.THEME_DISPLAY);
082
083 if (!BookmarksPermission.contains(
084 themeDisplay.getPermissionChecker(),
085 themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
086
087 return null;
088 }
089
090 PortletURL portletURL = PortletURLFactoryUtil.create(
091 liferayPortletRequest, PortletKeys.BOOKMARKS,
092 getControlPanelPlid(themeDisplay), PortletRequest.RENDER_PHASE);
093
094 portletURL.setParameter("struts_action", "/bookmarks/edit_entry");
095 portletURL.setParameter(
096 "folderId",
097 String.valueOf(
098 AssetPublisherUtil.getRecentFolderId(
099 liferayPortletRequest, getClassName())));
100
101 return portletURL;
102 }
103
104 @Override
105 public boolean hasPermission(
106 PermissionChecker permissionChecker, long classPK, String actionId)
107 throws Exception {
108
109 return BookmarksEntryPermission.contains(
110 permissionChecker, classPK, actionId);
111 }
112
113 @Override
114 public boolean isLinkable() {
115 return _LINKABLE;
116 }
117
118 @Override
119 protected String getIconPath(ThemeDisplay themeDisplay) {
120 return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
121 }
122
123 private static final boolean _LINKABLE = true;
124
125 }