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