1
14
15 package com.liferay.portlet.journalcontent.action;
16
17 import com.liferay.portal.kernel.language.LanguageUtil;
18 import com.liferay.portal.kernel.util.GetterUtil;
19 import com.liferay.portal.kernel.util.ParamUtil;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.kernel.util.Validator;
22 import com.liferay.portal.struts.PortletAction;
23 import com.liferay.portal.theme.ThemeDisplay;
24 import com.liferay.portal.util.WebKeys;
25 import com.liferay.portlet.journal.model.JournalArticleDisplay;
26 import com.liferay.portlet.journalcontent.util.JournalContentUtil;
27 import com.liferay.util.portlet.PortletRequestUtil;
28
29 import javax.portlet.PortletConfig;
30 import javax.portlet.PortletPreferences;
31 import javax.portlet.RenderRequest;
32 import javax.portlet.RenderResponse;
33
34 import org.apache.struts.action.ActionForm;
35 import org.apache.struts.action.ActionForward;
36 import org.apache.struts.action.ActionMapping;
37
38
44 public class ViewAction extends PortletAction {
45
46 public ActionForward render(
47 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
48 RenderRequest renderRequest, RenderResponse renderResponse)
49 throws Exception {
50
51 PortletPreferences prefs = renderRequest.getPreferences();
52
53 ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
54 WebKeys.THEME_DISPLAY);
55
56 long groupId = ParamUtil.getLong(renderRequest, "groupId");
57
58 if (groupId < 1) {
59 groupId = GetterUtil.getLong(
60 prefs.getValue("group-id", StringPool.BLANK));
61 }
62
63 String articleId = ParamUtil.getString(renderRequest, "articleId");
64 String templateId = ParamUtil.getString(renderRequest, "templateId");
65
66 if (Validator.isNull(articleId)) {
67 articleId = GetterUtil.getString(
68 prefs.getValue("article-id", StringPool.BLANK));
69 templateId = GetterUtil.getString(
70 prefs.getValue("template-id", StringPool.BLANK));
71 }
72
73 String languageId = LanguageUtil.getLanguageId(renderRequest);
74
75 int page = ParamUtil.getInteger(renderRequest, "page", 1);
76
77 String xmlRequest = PortletRequestUtil.toXML(
78 renderRequest, renderResponse);
79
80 JournalArticleDisplay articleDisplay = null;
81
82 if ((groupId > 0) && Validator.isNotNull(articleId)) {
83 articleDisplay = JournalContentUtil.getDisplay(
84 groupId, articleId, templateId, languageId, themeDisplay,
85 page, xmlRequest);
86 }
87
88 if (articleDisplay != null) {
89 renderRequest.setAttribute(
90 WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay);
91 }
92 else {
93 renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
94
95
100 renderRequest.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.FALSE);
101 }
102
103 return mapping.findForward("portlet.journal_content.view");
104 }
105
106 }