001
014
015 package com.liferay.portlet.journalcontent.action;
016
017 import com.liferay.portal.kernel.language.LanguageUtil;
018 import com.liferay.portal.kernel.portlet.PortletRequestModel;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.ParamUtil;
021 import com.liferay.portal.kernel.util.PrefsParamUtil;
022 import com.liferay.portal.kernel.util.Validator;
023 import com.liferay.portal.kernel.workflow.WorkflowConstants;
024 import com.liferay.portal.theme.ThemeDisplay;
025 import com.liferay.portal.util.WebKeys;
026 import com.liferay.portlet.journal.model.JournalArticle;
027 import com.liferay.portlet.journal.model.JournalArticleDisplay;
028 import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
029 import com.liferay.portlet.journalcontent.util.JournalContentUtil;
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 JournalArticle article = null;
073 JournalArticleDisplay articleDisplay = null;
074
075 if ((articleGroupId > 0) && Validator.isNotNull(articleId)) {
076 String viewMode = ParamUtil.getString(renderRequest, "viewMode");
077 String languageId = LanguageUtil.getLanguageId(renderRequest);
078 int page = ParamUtil.getInteger(renderRequest, "page", 1);
079
080 article = JournalArticleLocalServiceUtil.fetchLatestArticle(
081 articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
082
083 try {
084 if (article == null) {
085 article = JournalArticleLocalServiceUtil.getLatestArticle(
086 articleGroupId, articleId,
087 WorkflowConstants.STATUS_ANY);
088 }
089
090 double version = article.getVersion();
091
092 articleDisplay = JournalContentUtil.getDisplay(
093 articleGroupId, articleId, version, ddmTemplateKey,
094 viewMode, languageId, page,
095 new PortletRequestModel(renderRequest, renderResponse),
096 themeDisplay);
097 }
098 catch (Exception e) {
099 renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE);
100
101 articleDisplay = JournalContentUtil.getDisplay(
102 articleGroupId, articleId, ddmTemplateKey, viewMode,
103 languageId, page,
104 new PortletRequestModel(renderRequest, renderResponse),
105 themeDisplay);
106 }
107 }
108
109 if (article != null) {
110 renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
111 }
112
113 if (articleDisplay != null) {
114 renderRequest.setAttribute(
115 WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay);
116 }
117 else {
118 renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
119 }
120
121 return actionMapping.findForward("portlet.journal_content.view");
122 }
123
124 }