001
014
015 package com.liferay.portlet.bookmarks.asset;
016
017 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
018 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
019 import com.liferay.portal.kernel.util.HtmlUtil;
020 import com.liferay.portal.security.permission.ActionKeys;
021 import com.liferay.portal.security.permission.PermissionChecker;
022 import com.liferay.portal.theme.ThemeDisplay;
023 import com.liferay.portal.util.PortletKeys;
024 import com.liferay.portal.util.WebKeys;
025 import com.liferay.portlet.asset.model.BaseAssetRenderer;
026 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
027 import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
028
029 import javax.portlet.PortletURL;
030 import javax.portlet.RenderRequest;
031 import javax.portlet.RenderResponse;
032
033
037 public class BookmarksEntryAssetRenderer extends BaseAssetRenderer {
038
039 public BookmarksEntryAssetRenderer(BookmarksEntry entry) {
040 _entry = entry;
041 }
042
043 public long getClassPK() {
044 return _entry.getEntryId();
045 }
046
047 public long getGroupId() {
048 return _entry.getGroupId();
049 }
050
051 public String getSummary() {
052 return HtmlUtil.stripHtml(_entry.getComments());
053 }
054
055 public String getTitle() {
056 return _entry.getName();
057 }
058
059 public PortletURL getURLEdit(
060 LiferayPortletRequest liferayPortletRequest,
061 LiferayPortletResponse liferayPortletResponse) {
062
063 PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
064 PortletKeys.BOOKMARKS);
065
066 editPortletURL.setParameter("struts_action", "/bookmarks/edit_entry");
067 editPortletURL.setParameter(
068 "folderId", String.valueOf(_entry.getFolderId()));
069 editPortletURL.setParameter(
070 "entryId", String.valueOf(_entry.getEntryId()));
071
072 return editPortletURL;
073 }
074
075 public String getURLViewInContext(
076 LiferayPortletRequest liferayPortletRequest,
077 LiferayPortletResponse liferayPortletResponse,
078 String noSuchEntryRedirect) {
079
080 ThemeDisplay themeDisplay =
081 (ThemeDisplay)liferayPortletRequest.getAttribute(
082 WebKeys.THEME_DISPLAY);
083
084 return themeDisplay.getPathMain() + "/bookmarks/open_entry?entryId=" +
085 _entry.getEntryId();
086 }
087
088 public long getUserId() {
089 return _entry.getUserId();
090 }
091
092 public String getUuid() {
093 return _entry.getUuid();
094 }
095
096 public boolean hasEditPermission(PermissionChecker permissionChecker) {
097 try {
098 return BookmarksEntryPermission.contains(
099 permissionChecker, _entry, ActionKeys.UPDATE);
100 }
101 catch (Exception e) {
102 }
103
104 return false;
105 }
106
107 public boolean hasViewPermission(PermissionChecker permissionChecker) {
108 try {
109 return BookmarksEntryPermission.contains(
110 permissionChecker, _entry, ActionKeys.VIEW);
111 }
112 catch (Exception e) {
113 }
114
115 return true;
116 }
117
118 public boolean isPrintable() {
119 return true;
120 }
121
122 public String render(
123 RenderRequest renderRequest, RenderResponse renderResponse,
124 String template)
125 throws Exception {
126
127 if (template.equals(TEMPLATE_FULL_CONTENT)) {
128 renderRequest.setAttribute(WebKeys.BOOKMARKS_ENTRY, _entry);
129
130 return "/html/portlet/bookmarks/asset/" + template + ".jsp";
131 }
132 else {
133 return null;
134 }
135 }
136
137 protected String getIconPath(ThemeDisplay themeDisplay) {
138 return themeDisplay.getPathThemeImages() + "/ratings/star_hover.png";
139 }
140
141 private BookmarksEntry _entry;
142
143 }