001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.journalcontent.action;
022:
023: import com.liferay.portal.kernel.language.LanguageUtil;
024: import com.liferay.portal.kernel.util.GetterUtil;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.StringPool;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.struts.PortletAction;
029: import com.liferay.portal.theme.ThemeDisplay;
030: import com.liferay.portal.util.WebKeys;
031: import com.liferay.portlet.journal.model.JournalArticleDisplay;
032: import com.liferay.portlet.journalcontent.util.JournalContentUtil;
033: import com.liferay.util.portlet.PortletRequestUtil;
034:
035: import javax.portlet.PortletConfig;
036: import javax.portlet.PortletPreferences;
037: import javax.portlet.RenderRequest;
038: import javax.portlet.RenderResponse;
039:
040: import org.apache.struts.action.ActionForm;
041: import org.apache.struts.action.ActionForward;
042: import org.apache.struts.action.ActionMapping;
043:
044: /**
045: * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
046: *
047: * @author Brian Wing Shun Chan
048: * @author Raymond Augé
049: *
050: */
051: public class ViewAction extends PortletAction {
052:
053: public ActionForward render(ActionMapping mapping, ActionForm form,
054: PortletConfig config, RenderRequest req, RenderResponse res)
055: throws Exception {
056:
057: PortletPreferences prefs = req.getPreferences();
058:
059: ThemeDisplay themeDisplay = (ThemeDisplay) req
060: .getAttribute(WebKeys.THEME_DISPLAY);
061:
062: long groupId = ParamUtil.getLong(req, "groupId");
063:
064: if (groupId < 1) {
065: groupId = GetterUtil.getLong(prefs.getValue("group-id",
066: StringPool.BLANK));
067: }
068:
069: String articleId = ParamUtil.getString(req, "articleId");
070: String templateId = ParamUtil.getString(req, "templateId");
071:
072: if (Validator.isNull(articleId)) {
073: articleId = GetterUtil.getString(prefs.getValue(
074: "article-id", StringPool.BLANK));
075: templateId = GetterUtil.getString(prefs.getValue(
076: "template-id", StringPool.BLANK));
077: }
078:
079: String languageId = LanguageUtil.getLanguageId(req);
080:
081: int page = ParamUtil.getInteger(req, "page", 1);
082:
083: String xmlRequest = PortletRequestUtil.toXML(req, res);
084:
085: JournalArticleDisplay articleDisplay = null;
086:
087: if ((groupId > 0) && Validator.isNotNull(articleId)) {
088: articleDisplay = JournalContentUtil.getDisplay(groupId,
089: articleId, templateId, languageId, themeDisplay,
090: page, xmlRequest);
091: }
092:
093: if (articleDisplay != null) {
094: req.setAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY,
095: articleDisplay);
096: } else {
097: req.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY);
098:
099: // Don't decorate this portlet if there is no content. This will
100: // prevent end users from seeing empty portlets from expired
101: // articles. Administrators can still see the portlet and either
102: // remove the portlet or select a new article.
103:
104: req.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.FALSE);
105: }
106:
107: return mapping.findForward("portlet.journal_content.view");
108: }
109:
110: }
|