1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
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  /**
39   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   * @author Raymond Augé
43   */
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              // Don't decorate this portlet if there is no content. This will
96              // prevent end users from seeing empty portlets from expired
97              // articles. Administrators can still see the portlet and either
98              // remove the portlet or select a new article.
99  
100             renderRequest.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.FALSE);
101         }
102 
103         return mapping.findForward("portlet.journal_content.view");
104     }
105 
106 }