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   */
40  public class BlogsEntryAssetRenderer extends BaseAssetRenderer {
41  
42      public BlogsEntryAssetRenderer(BlogsEntry entry) {
43          _entry = entry;
44      }
45  
46      public long getClassPK() {
47          return _entry.getEntryId();
48      }
49  
50      public String getDiscussionPath() {
51          if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
52              return "edit_entry_discussion";
53          }
54          else {
55              return null;
56          }
57      }
58  
59      public long getGroupId() {
60          return _entry.getGroupId();
61      }
62  
63      public String getSummary() {
64          return HtmlUtil.stripHtml(_entry.getContent());
65      }
66  
67      public String getTitle() {
68          return _entry.getTitle();
69      }
70  
71      public PortletURL getURLEdit(
72          LiferayPortletRequest liferayPortletRequest,
73          LiferayPortletResponse liferayPortletResponse) {
74  
75          PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
76              PortletKeys.BLOGS);
77  
78          editPortletURL.setParameter("struts_action", "/blogs/edit_entry");
79          editPortletURL.setParameter(
80              "entryId", String.valueOf(_entry.getEntryId()));
81  
82          return editPortletURL;
83      }
84  
85      public String getUrlTitle() {
86          return _entry.getUrlTitle();
87      }
88  
89      public String getURLViewInContext(
90          LiferayPortletRequest liferayPortletRequest,
91          LiferayPortletResponse liferayPortletResponse,
92          String noSuchEntryRedirect) {
93  
94          ThemeDisplay themeDisplay =
95              (ThemeDisplay)liferayPortletRequest.getAttribute(
96                  WebKeys.THEME_DISPLAY);
97  
98          return themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
99              "/blogs/find_entry?noSuchEntryRedirect=" +
100                 HttpUtil.encodeURL(noSuchEntryRedirect) + "&entryId=" +
101                     _entry.getEntryId();
102     }
103 
104     public long getUserId() {
105         return _entry.getUserId();
106     }
107 
108     public boolean hasEditPermission(PermissionChecker permissionChecker) {
109         return BlogsEntryPermission.contains(
110             permissionChecker, _entry, ActionKeys.UPDATE);
111     }
112 
113     public boolean hasViewPermission(PermissionChecker permissionChecker) {
114         return BlogsEntryPermission.contains(
115             permissionChecker, _entry, ActionKeys.VIEW);
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.BLOGS_ENTRY, _entry);
129 
130             return "/html/portlet/blogs/asset/" + template + ".jsp";
131         }
132         else {
133             return null;
134         }
135     }
136 
137     private BlogsEntry _entry;
138 
139 }