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.theme.ThemeDisplay;
23  import com.liferay.portal.util.PortletKeys;
24  import com.liferay.portal.util.PropsValues;
25  import com.liferay.portal.util.WebKeys;
26  import com.liferay.portlet.asset.model.BaseAssetRenderer;
27  import com.liferay.portlet.blogs.model.BlogsEntry;
28  import com.liferay.portlet.blogs.service.permission.BlogsPermission;
29  
30  import javax.portlet.PortletURL;
31  import javax.portlet.RenderRequest;
32  import javax.portlet.RenderResponse;
33  
34  /**
35   * <a href="BlogsEntryAssetRenderer.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Jorge Ferrer
38   */
39  public class BlogsEntryAssetRenderer extends BaseAssetRenderer {
40  
41      public BlogsEntryAssetRenderer(BlogsEntry entry) {
42          _entry = entry;
43      }
44  
45      public long getClassPK() {
46          return _entry.getEntryId();
47      }
48  
49      public String getDiscussionPath() {
50          if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) {
51              return "edit_entry_discussion";
52          }
53          else {
54              return null;
55          }
56      }
57  
58      public long getGroupId() {
59          return _entry.getGroupId();
60      }
61  
62      public String getSummary() {
63          return HtmlUtil.stripHtml(_entry.getContent());
64      }
65  
66      public String getTitle() {
67          return _entry.getTitle();
68      }
69  
70      public PortletURL getURLEdit(
71          LiferayPortletRequest liferayPortletRequest,
72          LiferayPortletResponse liferayPortletResponse) {
73  
74          ThemeDisplay themeDisplay =
75              (ThemeDisplay)liferayPortletRequest.getAttribute(
76                  WebKeys.THEME_DISPLAY);
77  
78          PortletURL editPortletURL = null;
79  
80          if (BlogsPermission.contains(
81                  themeDisplay.getPermissionChecker(),
82                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_ENTRY)) {
83  
84              editPortletURL = liferayPortletResponse.createRenderURL(
85                  PortletKeys.BLOGS);
86  
87              editPortletURL.setParameter("struts_action", "/blogs/edit_entry");
88              editPortletURL.setParameter(
89                  "entryId", String.valueOf(_entry.getEntryId()));
90          }
91  
92          return editPortletURL;
93      }
94  
95      public String getUrlTitle() {
96          return _entry.getUrlTitle();
97      }
98  
99      public String getURLViewInContext(
100         LiferayPortletRequest liferayPortletRequest,
101         LiferayPortletResponse liferayPortletResponse,
102         String noSuchEntryRedirect) {
103 
104         ThemeDisplay themeDisplay =
105             (ThemeDisplay)liferayPortletRequest.getAttribute(
106                 WebKeys.THEME_DISPLAY);
107 
108         return themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
109             "/blogs/find_entry?noSuchEntryRedirect=" +
110                 HttpUtil.encodeURL(noSuchEntryRedirect) + "&entryId=" +
111                     _entry.getEntryId();
112     }
113 
114     public long getUserId() {
115         return _entry.getUserId();
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 }