001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.StringPool;
021    import com.liferay.portal.kernel.util.Validator;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.WebKeys;
024    import com.liferay.portlet.journal.model.JournalArticleDisplay;
025    import com.liferay.portlet.journalcontent.util.JournalContentUtil;
026    import com.liferay.util.portlet.PortletRequestUtil;
027    
028    import javax.portlet.PortletConfig;
029    import javax.portlet.PortletPreferences;
030    import javax.portlet.RenderRequest;
031    import javax.portlet.RenderResponse;
032    
033    import org.apache.struts.action.ActionForm;
034    import org.apache.struts.action.ActionForward;
035    import org.apache.struts.action.ActionMapping;
036    
037    /**
038     * @author Brian Wing Shun Chan
039     * @author Raymond Augé
040     */
041    public class ViewAction extends WebContentAction {
042    
043            public ActionForward render(
044                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
045                            RenderRequest renderRequest, RenderResponse renderResponse)
046                    throws Exception {
047    
048                    PortletPreferences preferences = renderRequest.getPreferences();
049    
050                    ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
051                            WebKeys.THEME_DISPLAY);
052    
053                    long groupId = ParamUtil.getLong(renderRequest, "groupId");
054    
055                    if (groupId < 1) {
056                            groupId = GetterUtil.getLong(
057                                    preferences.getValue("group-id", StringPool.BLANK));
058                    }
059    
060                    String articleId = ParamUtil.getString(renderRequest, "articleId");
061                    String templateId = ParamUtil.getString(renderRequest, "templateId");
062    
063                    if (Validator.isNull(articleId)) {
064                            articleId = GetterUtil.getString(
065                                    preferences.getValue("article-id", StringPool.BLANK));
066                            templateId = GetterUtil.getString(
067                                    preferences.getValue("template-id", StringPool.BLANK));
068                    }
069    
070                    String viewMode = ParamUtil.getString(renderRequest, "viewMode");
071                    String languageId = LanguageUtil.getLanguageId(renderRequest);
072                    int page = ParamUtil.getInteger(renderRequest, "page", 1);
073                    String xmlRequest = PortletRequestUtil.toXML(
074                            renderRequest, renderResponse);
075    
076                    JournalArticleDisplay articleDisplay = null;
077    
078                    if ((groupId > 0) && Validator.isNotNull(articleId)) {
079                            articleDisplay = JournalContentUtil.getDisplay(
080                                    groupId, articleId, templateId, viewMode, languageId,
081                                    themeDisplay, page, xmlRequest);
082                    }
083    
084                    if (articleDisplay != null) {
085                            renderRequest.setAttribute(
086                                    WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay);
087                    }
088                    else {
089                            renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
090                    }
091    
092                    return mapping.findForward("portlet.journal_content.view");
093            }
094    
095    }