001
014
015 package com.liferay.portlet.journalcontent.action;
016
017 import com.liferay.portal.kernel.language.LanguageUtil;
018 import com.liferay.portal.kernel.util.GetterUtil;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.kernel.util.PrefsParamUtil;
021 import com.liferay.portal.kernel.util.Validator;
022 import com.liferay.portal.kernel.workflow.WorkflowConstants;
023 import com.liferay.portal.theme.ThemeDisplay;
024 import com.liferay.portal.util.WebKeys;
025 import com.liferay.portlet.journal.model.JournalArticle;
026 import com.liferay.portlet.journal.model.JournalArticleDisplay;
027 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
028 import com.liferay.portlet.journalcontent.util.JournalContentUtil;
029 import com.liferay.util.portlet.PortletRequestUtil;
030
031 import javax.portlet.PortletConfig;
032 import javax.portlet.PortletPreferences;
033 import javax.portlet.RenderRequest;
034 import javax.portlet.RenderResponse;
035
036 import org.apache.struts.action.ActionForm;
037 import org.apache.struts.action.ActionForward;
038 import org.apache.struts.action.ActionMapping;
039
040
044 public class ViewAction extends WebContentAction {
045
046 @Override
047 public ActionForward render(
048 ActionMapping actionMapping, ActionForm actionForm,
049 PortletConfig portletConfig, RenderRequest renderRequest,
050 RenderResponse renderResponse)
051 throws Exception {
052
053 PortletPreferences portletPreferences = renderRequest.getPreferences();
054
055 ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
056 WebKeys.THEME_DISPLAY);
057
058 long articleGroupId = ParamUtil.getLong(
059 renderRequest, "articleGroupId");
060
061 if (articleGroupId <= 0) {
062 articleGroupId = GetterUtil.getLong(
063 portletPreferences.getValue(
064 "groupId", String.valueOf(themeDisplay.getScopeGroupId())));
065 }
066
067 String articleId = PrefsParamUtil.getString(
068 portletPreferences, renderRequest, "articleId");
069 String ddmTemplateKey = PrefsParamUtil.getString(
070 portletPreferences, renderRequest, "ddmTemplateKey");
071
072 String viewMode = ParamUtil.getString(renderRequest, "viewMode");
073 String languageId = LanguageUtil.getLanguageId(renderRequest);
074 int page = ParamUtil.getInteger(renderRequest, "page", 1);
075 String xmlRequest = PortletRequestUtil.toXML(
076 renderRequest, renderResponse);
077
078 JournalArticle article = null;
079 JournalArticleDisplay articleDisplay = null;
080
081 if ((articleGroupId > 0) && Validator.isNotNull(articleId)) {
082 article = JournalArticleLocalServiceUtil.fetchLatestArticle(
083 articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
084
085 try {
086 if (article == null) {
087 article = JournalArticleLocalServiceUtil.getLatestArticle(
088 articleGroupId, articleId,
089 WorkflowConstants.STATUS_ANY);
090 }
091
092 double version = article.getVersion();
093
094 articleDisplay = JournalContentUtil.getDisplay(
095 articleGroupId, articleId, version, ddmTemplateKey,
096 viewMode, languageId, themeDisplay, page, xmlRequest);
097 }
098 catch (Exception e) {
099 renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE);
100
101 articleDisplay = JournalContentUtil.getDisplay(
102 articleGroupId, articleId, ddmTemplateKey, viewMode,
103 languageId, themeDisplay, page, xmlRequest);
104 }
105 }
106
107 if (article != null) {
108 renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
109 }
110
111 if (articleDisplay != null) {
112 renderRequest.setAttribute(
113 WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay);
114 }
115 else {
116 renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
117 }
118
119 return actionMapping.findForward("portlet.journal_content.view");
120 }
121
122 }