001
014
015 package com.liferay.portlet.wiki.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.security.permission.ActionKeys;
021 import com.liferay.portal.security.permission.PermissionChecker;
022 import com.liferay.portal.theme.ThemeDisplay;
023 import com.liferay.portal.util.PortletKeys;
024 import com.liferay.portal.util.PropsValues;
025 import com.liferay.portal.util.WebKeys;
026 import com.liferay.portlet.asset.model.BaseAssetRenderer;
027 import com.liferay.portlet.wiki.model.WikiPage;
028 import com.liferay.portlet.wiki.model.WikiPageConstants;
029 import com.liferay.portlet.wiki.service.permission.WikiPagePermission;
030
031 import javax.portlet.PortletURL;
032 import javax.portlet.RenderRequest;
033 import javax.portlet.RenderResponse;
034
035
038 public class WikiPageAssetRenderer extends BaseAssetRenderer {
039
040 public WikiPageAssetRenderer(WikiPage page) {
041 _page = page;
042 }
043
044 public long getClassPK() {
045 if (!_page.isApproved() &&
046 (_page.getVersion() != WikiPageConstants.DEFAULT_VERSION)) {
047
048 return _page.getPageId();
049 }
050 else {
051 return _page.getResourcePrimKey();
052 }
053 }
054
055 public String getDiscussionPath() {
056 if (PropsValues.WIKI_PAGE_COMMENTS_ENABLED) {
057 return "edit_page_discussion";
058 }
059 else {
060 return null;
061 }
062 }
063
064 public long getGroupId() {
065 return _page.getGroupId();
066 }
067
068 public String getSummary() {
069 String content = _page.getContent();
070
071 if (_page.getFormat().equals("html")) {
072 content = HtmlUtil.stripHtml(content);
073 }
074
075 return content;
076 }
077
078 public String getTitle() {
079 return _page.getTitle();
080 }
081
082 public PortletURL getURLEdit(
083 LiferayPortletRequest liferayPortletRequest,
084 LiferayPortletResponse liferayPortletResponse) {
085
086 PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
087 PortletKeys.WIKI);
088
089 editPortletURL.setParameter("struts_action", "/wiki/edit_page");
090 editPortletURL.setParameter(
091 "nodeId", String.valueOf(_page.getNodeId()));
092 editPortletURL.setParameter("title", _page.getTitle());
093
094 return editPortletURL;
095 }
096
097 public PortletURL getURLExport(
098 LiferayPortletRequest liferayPortletRequest,
099 LiferayPortletResponse liferayPortletResponse) {
100
101 PortletURL exportPortletURL = liferayPortletResponse.createActionURL();
102
103 exportPortletURL.setParameter(
104 "struts_action", "/asset_publisher/export_wiki_page");
105 exportPortletURL.setParameter(
106 "nodeId", String.valueOf(_page.getNodeId()));
107 exportPortletURL.setParameter("title", _page.getTitle());
108
109 return exportPortletURL;
110 }
111
112 public String getURLViewInContext(
113 LiferayPortletRequest liferayPortletRequest,
114 LiferayPortletResponse liferayPortletResponse,
115 String noSuchEntryRedirect) {
116
117 ThemeDisplay themeDisplay =
118 (ThemeDisplay)liferayPortletRequest.getAttribute(
119 WebKeys.THEME_DISPLAY);
120
121 return themeDisplay.getPathMain() +
122 "/wiki/find_page?pageResourcePrimKey=" + _page.getResourcePrimKey();
123 }
124
125 public long getUserId() {
126 return _page.getUserId();
127 }
128
129 public String getUuid() {
130 return _page.getUuid();
131 }
132
133 public boolean hasEditPermission(PermissionChecker permissionChecker) {
134 return WikiPagePermission.contains(
135 permissionChecker, _page, ActionKeys.UPDATE);
136 }
137
138 public boolean hasViewPermission(PermissionChecker permissionChecker) {
139 return WikiPagePermission.contains(
140 permissionChecker, _page, ActionKeys.VIEW);
141 }
142
143 public boolean isConvertible() {
144 return true;
145 }
146
147 public boolean isPrintable() {
148 return true;
149 }
150
151 public String render(
152 RenderRequest renderRequest, RenderResponse renderResponse,
153 String template)
154 throws Exception {
155
156 if (template.equals(TEMPLATE_FULL_CONTENT)) {
157 renderRequest.setAttribute(WebKeys.WIKI_PAGE, _page);
158
159 return "/html/portlet/wiki/asset/" + template + ".jsp";
160 }
161 else {
162 return null;
163 }
164 }
165
166 protected String getIconPath(ThemeDisplay themeDisplay) {
167 return themeDisplay.getPathThemeImages() + "/common/pages.png";
168 }
169
170 private WikiPage _page;
171
172 }