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