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.journal.action;
022:
023: import com.liferay.portal.kernel.util.ParamUtil;
024: import com.liferay.portal.kernel.util.Validator;
025: import com.liferay.portal.util.PortalUtil;
026: import com.liferay.portal.util.WebKeys;
027: import com.liferay.portlet.journal.model.JournalArticle;
028: import com.liferay.portlet.journal.model.JournalFeed;
029: import com.liferay.portlet.journal.model.JournalStructure;
030: import com.liferay.portlet.journal.model.JournalTemplate;
031: import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
032: import com.liferay.portlet.journal.service.JournalArticleServiceUtil;
033: import com.liferay.portlet.journal.service.JournalFeedServiceUtil;
034: import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
035: import com.liferay.portlet.journal.service.JournalTemplateServiceUtil;
036: import com.liferay.portlet.journal.util.JournalUtil;
037:
038: import javax.portlet.ActionRequest;
039: import javax.portlet.RenderRequest;
040:
041: import javax.servlet.http.HttpServletRequest;
042:
043: /**
044: * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
045: *
046: * @author Brian Wing Shun Chan
047: *
048: */
049: public class ActionUtil {
050:
051: public static void getArticle(ActionRequest req) throws Exception {
052: HttpServletRequest httpReq = PortalUtil
053: .getHttpServletRequest(req);
054:
055: getArticle(httpReq);
056:
057: JournalArticle article = (JournalArticle) req
058: .getAttribute(WebKeys.JOURNAL_ARTICLE);
059:
060: JournalUtil.addRecentArticle(req, article);
061: }
062:
063: public static void getArticle(RenderRequest req) throws Exception {
064: HttpServletRequest httpReq = PortalUtil
065: .getHttpServletRequest(req);
066:
067: getArticle(httpReq);
068:
069: JournalArticle article = (JournalArticle) req
070: .getAttribute(WebKeys.JOURNAL_ARTICLE);
071:
072: JournalUtil.addRecentArticle(req, article);
073: }
074:
075: public static void getArticle(HttpServletRequest req)
076: throws Exception {
077: long groupId = ParamUtil.getLong(req, "groupId");
078: String articleId = ParamUtil.getString(req, "articleId");
079: double version = ParamUtil.getDouble(req, "version",
080: JournalArticleImpl.DEFAULT_VERSION);
081:
082: JournalArticle article = null;
083:
084: if (Validator.isNotNull(articleId)) {
085: article = JournalArticleServiceUtil.getArticle(groupId,
086: articleId, version);
087: }
088:
089: req.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
090: }
091:
092: public static void getFeed(ActionRequest req) throws Exception {
093: HttpServletRequest httpReq = PortalUtil
094: .getHttpServletRequest(req);
095:
096: getFeed(httpReq);
097: }
098:
099: public static void getFeed(RenderRequest req) throws Exception {
100: HttpServletRequest httpReq = PortalUtil
101: .getHttpServletRequest(req);
102:
103: getFeed(httpReq);
104: }
105:
106: public static void getFeed(HttpServletRequest req) throws Exception {
107: long groupId = ParamUtil.getLong(req, "groupId");
108: String feedId = ParamUtil.getString(req, "feedId");
109:
110: JournalFeed feed = null;
111:
112: if (Validator.isNotNull(feedId)) {
113: feed = JournalFeedServiceUtil.getFeed(groupId, feedId);
114: }
115:
116: req.setAttribute(WebKeys.JOURNAL_FEED, feed);
117: }
118:
119: public static void getStructure(ActionRequest req) throws Exception {
120: HttpServletRequest httpReq = PortalUtil
121: .getHttpServletRequest(req);
122:
123: getStructure(httpReq);
124:
125: JournalStructure structure = (JournalStructure) req
126: .getAttribute(WebKeys.JOURNAL_STRUCTURE);
127:
128: JournalUtil.addRecentStructure(req, structure);
129: }
130:
131: public static void getStructure(RenderRequest req) throws Exception {
132: HttpServletRequest httpReq = PortalUtil
133: .getHttpServletRequest(req);
134:
135: getStructure(httpReq);
136:
137: JournalStructure structure = (JournalStructure) req
138: .getAttribute(WebKeys.JOURNAL_STRUCTURE);
139:
140: JournalUtil.addRecentStructure(req, structure);
141: }
142:
143: public static void getStructure(HttpServletRequest req)
144: throws Exception {
145: long groupId = ParamUtil.getLong(req, "groupId");
146: String structureId = ParamUtil.getString(req, "structureId");
147:
148: JournalStructure structure = null;
149:
150: if (Validator.isNotNull(structureId)) {
151: structure = JournalStructureServiceUtil.getStructure(
152: groupId, structureId);
153: }
154:
155: req.setAttribute(WebKeys.JOURNAL_STRUCTURE, structure);
156: }
157:
158: public static void getTemplate(ActionRequest req) throws Exception {
159: HttpServletRequest httpReq = PortalUtil
160: .getHttpServletRequest(req);
161:
162: getTemplate(httpReq);
163:
164: JournalTemplate template = (JournalTemplate) req
165: .getAttribute(WebKeys.JOURNAL_TEMPLATE);
166:
167: JournalUtil.addRecentTemplate(req, template);
168: }
169:
170: public static void getTemplate(RenderRequest req) throws Exception {
171: HttpServletRequest httpReq = PortalUtil
172: .getHttpServletRequest(req);
173:
174: getTemplate(httpReq);
175:
176: JournalTemplate template = (JournalTemplate) req
177: .getAttribute(WebKeys.JOURNAL_TEMPLATE);
178:
179: JournalUtil.addRecentTemplate(req, template);
180: }
181:
182: public static void getTemplate(HttpServletRequest req)
183: throws Exception {
184: long groupId = ParamUtil.getLong(req, "groupId");
185: String templateId = ParamUtil.getString(req, "templateId");
186:
187: JournalTemplate template = null;
188:
189: if (Validator.isNotNull(templateId)) {
190: template = JournalTemplateServiceUtil.getTemplate(groupId,
191: templateId);
192: }
193:
194: req.setAttribute(WebKeys.JOURNAL_TEMPLATE, template);
195: }
196:
197: }
|