001
014
015 package com.liferay.portlet.blogs.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.kernel.util.HttpUtil;
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.PropsValues;
026 import com.liferay.portal.util.WebKeys;
027 import com.liferay.portlet.asset.model.BaseAssetRenderer;
028 import com.liferay.portlet.blogs.model.BlogsEntry;
029 import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
030
031 import javax.portlet.PortletURL;
032 import javax.portlet.RenderRequest;
033 import javax.portlet.RenderResponse;
034
035
039 public class BlogsEntryAssetRenderer extends BaseAssetRenderer {
040
041 public BlogsEntryAssetRenderer(BlogsEntry entry) {
042 _entry = entry;
043 }
044
045 public long getClassPK() {
046 return _entry.getEntryId();
047 }
048
049 public String getDiscussionPath() {
050 if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
051 return "edit_entry_discussion";
052 }
053 else {
054 return null;
055 }
056 }
057
058 public long getGroupId() {
059 return _entry.getGroupId();
060 }
061
062 public String getSummary() {
063 return HtmlUtil.stripHtml(_entry.getContent());
064 }
065
066 public String getTitle() {
067 return _entry.getTitle();
068 }
069
070 public PortletURL getURLEdit(
071 LiferayPortletRequest liferayPortletRequest,
072 LiferayPortletResponse liferayPortletResponse) {
073
074 PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
075 PortletKeys.BLOGS);
076
077 editPortletURL.setParameter("struts_action", "/blogs/edit_entry");
078 editPortletURL.setParameter(
079 "entryId", String.valueOf(_entry.getEntryId()));
080
081 return editPortletURL;
082 }
083
084 public String getUrlTitle() {
085 return _entry.getUrlTitle();
086 }
087
088 public String getURLViewInContext(
089 LiferayPortletRequest liferayPortletRequest,
090 LiferayPortletResponse liferayPortletResponse,
091 String noSuchEntryRedirect) {
092
093 ThemeDisplay themeDisplay =
094 (ThemeDisplay)liferayPortletRequest.getAttribute(
095 WebKeys.THEME_DISPLAY);
096
097 return themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
098 "/blogs/find_entry?noSuchEntryRedirect=" +
099 HttpUtil.encodeURL(noSuchEntryRedirect) + "&entryId=" +
100 _entry.getEntryId();
101 }
102
103 public long getUserId() {
104 return _entry.getUserId();
105 }
106
107 public String getUuid() {
108 return _entry.getUuid();
109 }
110
111 public boolean hasEditPermission(PermissionChecker permissionChecker) {
112 return BlogsEntryPermission.contains(
113 permissionChecker, _entry, ActionKeys.UPDATE);
114 }
115
116 public boolean hasViewPermission(PermissionChecker permissionChecker) {
117 return BlogsEntryPermission.contains(
118 permissionChecker, _entry, ActionKeys.VIEW);
119 }
120
121 public boolean isPrintable() {
122 return true;
123 }
124
125 public String render(
126 RenderRequest renderRequest, RenderResponse renderResponse,
127 String template)
128 throws Exception {
129
130 if (template.equals(TEMPLATE_FULL_CONTENT)) {
131 renderRequest.setAttribute(WebKeys.BLOGS_ENTRY, _entry);
132
133 return "/html/portlet/blogs/asset/" + template + ".jsp";
134 }
135 else {
136 return null;
137 }
138 }
139
140 protected String getIconPath(ThemeDisplay themeDisplay) {
141 return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
142 }
143
144 private BlogsEntry _entry;
145
146 }