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.wiki.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.security.permission.ActionKeys;
21  import com.liferay.portal.theme.ThemeDisplay;
22  import com.liferay.portal.util.PortletKeys;
23  import com.liferay.portal.util.PropsValues;
24  import com.liferay.portal.util.WebKeys;
25  import com.liferay.portlet.asset.model.BaseAssetRenderer;
26  import com.liferay.portlet.wiki.model.WikiPage;
27  import com.liferay.portlet.wiki.service.permission.WikiPermission;
28  
29  import javax.portlet.PortletURL;
30  import javax.portlet.RenderRequest;
31  import javax.portlet.RenderResponse;
32  
33  /**
34   * <a href="WikiPageAssetRenderer.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Julio Camarero
37   */
38  public class WikiPageAssetRenderer extends BaseAssetRenderer {
39  
40      public WikiPageAssetRenderer(WikiPage page) {
41          _page = page;
42      }
43  
44      public long getClassPK() {
45          return _page.getPageId();
46      }
47  
48      public String getDiscussionPath() {
49          if (PropsValues.WIKI_PAGE_COMMENTS_ENABLED) {
50              return "edit_page_discussion";
51          }
52          else {
53              return null;
54          }
55      }
56  
57      public long getGroupId() {
58          return _page.getGroupId();
59      }
60  
61      public String getSummary() {
62          String content = _page.getContent();
63  
64          if (_page.getFormat().equals("html")) {
65              content = HtmlUtil.stripHtml(content);
66          }
67  
68          return content;
69      }
70  
71      public String getTitle() {
72          return _page.getTitle();
73      }
74  
75      public PortletURL getURLEdit(
76          LiferayPortletRequest liferayPortletRequest,
77          LiferayPortletResponse liferayPortletResponse) {
78  
79          ThemeDisplay themeDisplay =
80              (ThemeDisplay)liferayPortletRequest.getAttribute(
81                  WebKeys.THEME_DISPLAY);
82  
83          PortletURL editPortletURL = null;
84  
85          if (WikiPermission.contains(
86                  themeDisplay.getPermissionChecker(),
87                  themeDisplay.getScopeGroupId(), ActionKeys.ADD_PAGE)) {
88  
89              editPortletURL = liferayPortletResponse.createRenderURL(
90                  PortletKeys.WIKI);
91  
92              editPortletURL.setParameter("struts_action", "/wiki/edit_page");
93              editPortletURL.setParameter(
94                  "nodeId", String.valueOf(_page.getNodeId()));
95              editPortletURL.setParameter("title", _page.getTitle());
96          }
97  
98          return editPortletURL;
99      }
100 
101     public PortletURL getURLExport(
102         LiferayPortletRequest liferayPortletRequest,
103         LiferayPortletResponse liferayPortletResponse) {
104 
105         PortletURL exportPortletURL = liferayPortletResponse.createActionURL();
106 
107         exportPortletURL.setParameter(
108             "struts_action", "/asset_publisher/export_wiki_page");
109         exportPortletURL.setParameter(
110             "nodeId", String.valueOf(_page.getNodeId()));
111         exportPortletURL.setParameter("title", _page.getTitle());
112 
113         return exportPortletURL;
114     }
115 
116     public String getURLViewInContext(
117         LiferayPortletRequest liferayPortletRequest,
118         LiferayPortletResponse liferayPortletResponse,
119         String noSuchEntryRedirect) {
120 
121         ThemeDisplay themeDisplay =
122             (ThemeDisplay)liferayPortletRequest.getAttribute(
123                 WebKeys.THEME_DISPLAY);
124 
125         return themeDisplay.getPathMain() +
126             "/wiki/find_page?pageResourcePrimKey=" + _page.getResourcePrimKey();
127     }
128 
129     public long getUserId() {
130         return _page.getUserId();
131     }
132 
133     public boolean isConvertible() {
134         return true;
135     }
136 
137     public boolean isPrintable() {
138         return true;
139     }
140 
141     public String render(
142             RenderRequest renderRequest, RenderResponse renderResponse,
143             String template)
144         throws Exception {
145 
146         if (template.equals(TEMPLATE_FULL_CONTENT)) {
147             renderRequest.setAttribute(WebKeys.WIKI_PAGE, _page);
148 
149             return "/html/portlet/wiki/asset/" + template + ".jsp";
150         }
151         else {
152             return null;
153         }
154     }
155 
156     private WikiPage _page;
157 
158 }