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