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.messageboards.action;
022:
023: import com.liferay.portal.kernel.util.ParamUtil;
024: import com.liferay.portal.theme.ThemeDisplay;
025: import com.liferay.portal.util.PortalUtil;
026: import com.liferay.portal.util.WebKeys;
027: import com.liferay.portlet.messageboards.model.MBCategory;
028: import com.liferay.portlet.messageboards.model.MBMessage;
029: import com.liferay.portlet.messageboards.model.MBThread;
030: import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
031: import com.liferay.portlet.messageboards.service.MBBanLocalServiceUtil;
032: import com.liferay.portlet.messageboards.service.MBCategoryServiceUtil;
033: import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
034: import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
035:
036: import javax.portlet.ActionRequest;
037: import javax.portlet.RenderRequest;
038:
039: import javax.servlet.http.HttpServletRequest;
040:
041: /**
042: * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
043: *
044: * @author Brian Wing Shun Chan
045: *
046: */
047: public class ActionUtil {
048:
049: public static void getCategory(ActionRequest req) throws Exception {
050: HttpServletRequest httpReq = PortalUtil
051: .getHttpServletRequest(req);
052:
053: getCategory(httpReq);
054: }
055:
056: public static void getCategory(RenderRequest req) throws Exception {
057: HttpServletRequest httpReq = PortalUtil
058: .getHttpServletRequest(req);
059:
060: getCategory(httpReq);
061: }
062:
063: public static void getCategory(HttpServletRequest req)
064: throws Exception {
065:
066: // Add redundant check here because the JSP does not check permissions
067: // on the initial search container
068:
069: ThemeDisplay themeDisplay = (ThemeDisplay) req
070: .getAttribute(WebKeys.THEME_DISPLAY);
071:
072: MBBanLocalServiceUtil.checkBan(
073: themeDisplay.getPortletGroupId(), themeDisplay
074: .getUserId());
075:
076: long categoryId = ParamUtil.getLong(req, "categoryId");
077:
078: MBCategory category = null;
079:
080: if ((categoryId > 0)
081: && (categoryId != MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
082:
083: category = MBCategoryServiceUtil.getCategory(categoryId);
084: }
085:
086: req.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category);
087: }
088:
089: public static void getMessage(ActionRequest req) throws Exception {
090: HttpServletRequest httpReq = PortalUtil
091: .getHttpServletRequest(req);
092:
093: getMessage(httpReq);
094: }
095:
096: public static void getMessage(RenderRequest req) throws Exception {
097: HttpServletRequest httpReq = PortalUtil
098: .getHttpServletRequest(req);
099:
100: getMessage(httpReq);
101: }
102:
103: public static void getMessage(HttpServletRequest req)
104: throws Exception {
105: long messageId = ParamUtil.getLong(req, "messageId");
106:
107: MBMessage message = null;
108:
109: if (messageId > 0) {
110: message = MBMessageServiceUtil.getMessage(messageId);
111: }
112:
113: req.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
114: }
115:
116: public static void getThreadMessage(RenderRequest req)
117: throws Exception {
118: HttpServletRequest httpReq = PortalUtil
119: .getHttpServletRequest(req);
120:
121: getThreadMessage(httpReq);
122: }
123:
124: public static void getThreadMessage(ActionRequest req)
125: throws Exception {
126: HttpServletRequest httpReq = PortalUtil
127: .getHttpServletRequest(req);
128:
129: getThreadMessage(httpReq);
130: }
131:
132: public static void getThreadMessage(HttpServletRequest req)
133: throws Exception {
134:
135: long threadId = ParamUtil.getLong(req, "threadId");
136:
137: MBMessage message = null;
138:
139: if (threadId > 0) {
140: MBThread thread = MBThreadLocalServiceUtil
141: .getThread(threadId);
142:
143: message = MBMessageServiceUtil.getMessage(thread
144: .getRootMessageId());
145: }
146:
147: req.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
148: }
149:
150: }
|