1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.blogs.asset;
16  
17  import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
18  import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
19  import com.liferay.portal.kernel.util.HtmlUtil;
20  import com.liferay.portal.kernel.util.HttpUtil;
21  import com.liferay.portal.security.permission.ActionKeys;
22  import com.liferay.portal.security.permission.PermissionChecker;
23  import com.liferay.portal.theme.ThemeDisplay;
24  import com.liferay.portal.util.PortletKeys;
25  import com.liferay.portal.util.PropsValues;
26  import com.liferay.portal.util.WebKeys;
27  import com.liferay.portlet.asset.model.BaseAssetRenderer;
28  import com.liferay.portlet.blogs.model.BlogsEntry;
29  import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
30  
31  import javax.portlet.PortletURL;
32  import javax.portlet.RenderRequest;
33  import javax.portlet.RenderResponse;
34  
35  /**
36   * <a href="BlogsEntryAssetRenderer.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Jorge Ferrer
39   * @author Juan Fernández
40   */
41  public class BlogsEntryAssetRenderer extends BaseAssetRenderer {
42  
43      public BlogsEntryAssetRenderer(BlogsEntry entry) {
44          _entry = entry;
45      }
46  
47      public long getClassPK() {
48          return _entry.getEntryId();
49      }
50  
51      public String getDiscussionPath() {
52          if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
53              return "edit_entry_discussion";
54          }
55          else {
56              return null;
57          }
58      }
59  
60      public long getGroupId() {
61          return _entry.getGroupId();
62      }
63  
64      public String getSummary() {
65          return HtmlUtil.stripHtml(_entry.getContent());
66      }
67  
68      public String getTitle() {
69          return _entry.getTitle();
70      }
71  
72      public PortletURL getURLEdit(
73          LiferayPortletRequest liferayPortletRequest,
74          LiferayPortletResponse liferayPortletResponse) {
75  
76          PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
77              PortletKeys.BLOGS);
78  
79          editPortletURL.setParameter("struts_action", "/blogs/edit_entry");
80          editPortletURL.setParameter(
81              "entryId", String.valueOf(_entry.getEntryId()));
82  
83          return editPortletURL;
84      }
85  
86      public String getUrlTitle() {
87          return _entry.getUrlTitle();
88      }
89  
90      public String getURLViewInContext(
91          LiferayPortletRequest liferayPortletRequest,
92          LiferayPortletResponse liferayPortletResponse,
93          String noSuchEntryRedirect) {
94  
95          ThemeDisplay themeDisplay =
96              (ThemeDisplay)liferayPortletRequest.getAttribute(
97                  WebKeys.THEME_DISPLAY);
98  
99          return themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
100             "/blogs/find_entry?noSuchEntryRedirect=" +
101                 HttpUtil.encodeURL(noSuchEntryRedirect) + "&entryId=" +
102                     _entry.getEntryId();
103     }
104 
105     public long getUserId() {
106         return _entry.getUserId();
107     }
108 
109     public boolean hasEditPermission(PermissionChecker permissionChecker) {
110         return BlogsEntryPermission.contains(
111             permissionChecker, _entry, ActionKeys.UPDATE);
112     }
113 
114     public boolean hasViewPermission(PermissionChecker permissionChecker) {
115         return BlogsEntryPermission.contains(
116             permissionChecker, _entry, ActionKeys.VIEW);
117     }
118 
119     public boolean isPrintable() {
120         return true;
121     }
122 
123     public String render(
124             RenderRequest renderRequest, RenderResponse renderResponse,
125             String template)
126         throws Exception {
127 
128         if (template.equals(TEMPLATE_FULL_CONTENT)) {
129             renderRequest.setAttribute(WebKeys.BLOGS_ENTRY, _entry);
130 
131             return "/html/portlet/blogs/asset/" + template + ".jsp";
132         }
133         else {
134             return null;
135         }
136     }
137 
138     protected String getIconPath(ThemeDisplay themeDisplay) {
139         return themeDisplay.getPathThemeImages() + "/blogs/blogs.png";
140     }
141 
142     private BlogsEntry _entry;
143 
144 }