1
14
15 package com.liferay.portlet.journal.asset;
16
17 import com.liferay.portal.kernel.language.LanguageUtil;
18 import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
19 import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
20 import com.liferay.portal.kernel.util.HtmlUtil;
21 import com.liferay.portal.kernel.util.StringPool;
22 import com.liferay.portal.security.permission.ActionKeys;
23 import com.liferay.portal.security.permission.PermissionChecker;
24 import com.liferay.portal.theme.ThemeDisplay;
25 import com.liferay.portal.util.PortletKeys;
26 import com.liferay.portal.util.PropsValues;
27 import com.liferay.portal.util.WebKeys;
28 import com.liferay.portlet.asset.model.BaseAssetRenderer;
29 import com.liferay.portlet.journal.model.JournalArticle;
30 import com.liferay.portlet.journal.model.JournalArticleDisplay;
31 import com.liferay.portlet.journal.service.permission.JournalArticlePermission;
32 import com.liferay.portlet.journalcontent.util.JournalContentUtil;
33
34 import javax.portlet.PortletURL;
35 import javax.portlet.RenderRequest;
36 import javax.portlet.RenderResponse;
37
38
44 public class JournalArticleAssetRenderer extends BaseAssetRenderer {
45
46 public JournalArticleAssetRenderer(JournalArticle article) {
47 _article = article;
48 }
49
50 public String[] getAvailableLocales() {
51 return _article.getAvailableLocales();
52 }
53
54 public long getClassPK() {
55 return _article.getResourcePrimKey();
56 }
57
58 public String getDiscussionPath() {
59 if (PropsValues.JOURNAL_ARTICLE_COMMENTS_ENABLED) {
60 return "edit_article_discussion";
61 }
62 else {
63 return null;
64 }
65 }
66
67 public long getGroupId() {
68 return _article.getGroupId();
69 }
70
71 public String getSummary() {
72 return HtmlUtil.stripHtml(_article.getContent());
73 }
74
75 public String getTitle() {
76 return _article.getTitle();
77 }
78
79 public PortletURL getURLEdit(
80 LiferayPortletRequest liferayPortletRequest,
81 LiferayPortletResponse liferayPortletResponse) {
82
83 PortletURL editPortletURL = liferayPortletResponse.createRenderURL(
84 PortletKeys.JOURNAL);
85
86 editPortletURL.setParameter(
87 "struts_action", "/journal/edit_article");
88 editPortletURL.setParameter(
89 "groupId", String.valueOf(_article.getGroupId()));
90 editPortletURL.setParameter(
91 "articleId", _article.getArticleId());
92 editPortletURL.setParameter(
93 "version", String.valueOf(_article.getVersion()));
94
95 return editPortletURL;
96 }
97
98 public PortletURL getURLExport(
99 LiferayPortletRequest liferayPortletRequest,
100 LiferayPortletResponse liferayPortletResponse) {
101
102 PortletURL exportPortletURL = liferayPortletResponse.createActionURL();
103
104 exportPortletURL.setParameter(
105 "struts_action", "/asset_publisher/export_journal_article");
106 exportPortletURL.setParameter(
107 "groupId", String.valueOf(_article.getGroupId()));
108 exportPortletURL.setParameter("articleId", _article.getArticleId());
109
110 return exportPortletURL;
111 }
112
113 public String getUrlTitle() {
114 return _article.getUrlTitle();
115 }
116
117 public String getURLViewInContext(
118 LiferayPortletRequest liferayPortletRequest,
119 LiferayPortletResponse liferayPortletResponse,
120 String noSuchEntryRedirect)
121 throws Exception {
122
123 ThemeDisplay themeDisplay =
124 (ThemeDisplay)liferayPortletRequest.getAttribute(
125 WebKeys.THEME_DISPLAY);
126
127 String languageId = LanguageUtil.getLanguageId(liferayPortletRequest);
128
129 JournalArticleDisplay articleDisplay =
130 JournalContentUtil.getDisplay(
131 _article.getGroupId(), _article.getArticleId(),
132 null, null, languageId, themeDisplay);
133
134 String viewURL = StringPool.BLANK;
135
136 if (articleDisplay != null) {
137
138 PortletURL viewPortletURL =
139 liferayPortletResponse.createRenderURL();
140
141 viewPortletURL.setParameter(
142 "struts_action", "/asset_publisher/view_content");
143 viewPortletURL.setParameter("urlTitle", _article.getUrlTitle());
144 viewPortletURL.setParameter(
145 "type", JournalArticleAssetRendererFactory.TYPE);
146
147 viewURL = viewPortletURL.toString();
148 }
149
150 return viewURL;
151 }
152
153 public long getUserId() {
154 return _article.getUserId();
155 }
156
157 public String getViewInContextMessage() {
158 return "view";
159 }
160
161 public boolean hasEditPermission(PermissionChecker permissionChecker) {
162 return JournalArticlePermission.contains(
163 permissionChecker,_article, ActionKeys.UPDATE);
164 }
165
166 public boolean hasViewPermission(PermissionChecker permissionChecker) {
167 return JournalArticlePermission.contains(
168 permissionChecker,_article, ActionKeys.VIEW);
169 }
170
171 public boolean isConvertible() {
172 return true;
173 }
174
175 public boolean isLocalizable() {
176 return true;
177 }
178
179 public boolean isPrintable() {
180 return true;
181 }
182
183 public String render(
184 RenderRequest renderRequest, RenderResponse renderResponse,
185 String template)
186 throws Exception {
187
188 if (template.equals(TEMPLATE_ABSTRACT) ||
189 template.equals(TEMPLATE_FULL_CONTENT)) {
190
191 renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE, _article);
192
193 return "/html/portlet/journal/asset/" + template + ".jsp";
194 }
195 else {
196 return null;
197 }
198 }
199
200 protected String getIconPath(ThemeDisplay themeDisplay) {
201 return themeDisplay.getPathThemeImages() + "/common/history.png";
202 }
203
204 private JournalArticle _article;
205
206 }