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