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.theme.ThemeDisplay;
23  import com.liferay.portal.util.WebKeys;
24  import com.liferay.portlet.journal.model.JournalArticleDisplay;
25  import com.liferay.portlet.journalcontent.util.JournalContentUtil;
26  import com.liferay.util.portlet.PortletRequestUtil;
27  
28  import javax.portlet.PortletConfig;
29  import javax.portlet.PortletPreferences;
30  import javax.portlet.RenderRequest;
31  import javax.portlet.RenderResponse;
32  
33  import org.apache.struts.action.ActionForm;
34  import org.apache.struts.action.ActionForward;
35  import org.apache.struts.action.ActionMapping;
36  
37  /**
38   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   * @author Raymond Augé
42   */
43  public class ViewAction extends WebContentAction {
44  
45      public ActionForward render(
46              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
47              RenderRequest renderRequest, RenderResponse renderResponse)
48          throws Exception {
49  
50          PortletPreferences preferences = renderRequest.getPreferences();
51  
52          ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
53              WebKeys.THEME_DISPLAY);
54  
55          long groupId = ParamUtil.getLong(renderRequest, "groupId");
56  
57          if (groupId < 1) {
58              groupId = GetterUtil.getLong(
59                  preferences.getValue("group-id", StringPool.BLANK));
60          }
61  
62          String articleId = ParamUtil.getString(renderRequest, "articleId");
63          String templateId = ParamUtil.getString(renderRequest, "templateId");
64  
65          if (Validator.isNull(articleId)) {
66              articleId = GetterUtil.getString(
67                  preferences.getValue("article-id", StringPool.BLANK));
68              templateId = GetterUtil.getString(
69                  preferences.getValue("template-id", StringPool.BLANK));
70          }
71  
72          String viewMode = ParamUtil.getString(renderRequest, "viewMode");
73          String languageId = LanguageUtil.getLanguageId(renderRequest);
74          int page = ParamUtil.getInteger(renderRequest, "page", 1);
75          String xmlRequest = PortletRequestUtil.toXML(
76              renderRequest, renderResponse);
77  
78          JournalArticleDisplay articleDisplay = null;
79  
80          if ((groupId > 0) && Validator.isNotNull(articleId)) {
81              articleDisplay = JournalContentUtil.getDisplay(
82                  groupId, articleId, templateId, viewMode, languageId,
83                  themeDisplay, page, xmlRequest);
84          }
85  
86          if (articleDisplay != null) {
87              renderRequest.setAttribute(
88                  WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay);
89          }
90          else {
91              renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
92          }
93  
94          return mapping.findForward("portlet.journal_content.view");
95      }
96  
97  }