001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.messageboards.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.theme.ThemeDisplay;
019    import com.liferay.portal.util.PortalUtil;
020    import com.liferay.portal.util.WebKeys;
021    import com.liferay.portlet.messageboards.model.MBCategory;
022    import com.liferay.portlet.messageboards.model.MBMessage;
023    import com.liferay.portlet.messageboards.model.MBThread;
024    import com.liferay.portlet.messageboards.service.MBBanLocalServiceUtil;
025    import com.liferay.portlet.messageboards.service.MBCategoryServiceUtil;
026    import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
027    import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
028    import com.liferay.portlet.messageboards.util.MBUtil;
029    
030    import javax.portlet.PortletRequest;
031    
032    import javax.servlet.http.HttpServletRequest;
033    
034    /**
035     * @author Brian Wing Shun Chan
036     */
037    public class ActionUtil {
038    
039            public static void getCategory(HttpServletRequest request)
040                    throws Exception {
041    
042                    // Add redundant check here because the JSP does not check permissions
043                    // on the initial search container
044    
045                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
046                            WebKeys.THEME_DISPLAY);
047    
048                    MBBanLocalServiceUtil.checkBan(
049                            themeDisplay.getScopeGroupId(), themeDisplay.getUserId());
050    
051                    long categoryId = ParamUtil.getLong(request, "mbCategoryId");
052    
053                    MBCategory category = null;
054    
055                    if ((categoryId > 0) && !MBUtil.isDefaultParentCategoryId(categoryId)) {
056                            category = MBCategoryServiceUtil.getCategory(categoryId);
057                    }
058    
059                    request.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category);
060            }
061    
062            public static void getCategory(PortletRequest portletRequest)
063                    throws Exception {
064    
065                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
066                            portletRequest);
067    
068                    getCategory(request);
069            }
070    
071            public static void getMessage(HttpServletRequest request) throws Exception {
072                    long messageId = ParamUtil.getLong(request, "messageId");
073    
074                    MBMessage message = null;
075    
076                    if (messageId > 0) {
077                            message = MBMessageServiceUtil.getMessage(messageId);
078                    }
079    
080                    request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
081            }
082    
083            public static void getMessage(PortletRequest portletRequest)
084                    throws Exception {
085    
086                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
087                            portletRequest);
088    
089                    getMessage(request);
090            }
091    
092            public static void getThreadMessage(HttpServletRequest request)
093                    throws Exception {
094    
095                    long threadId = ParamUtil.getLong(request, "threadId");
096    
097                    MBMessage message = null;
098    
099                    if (threadId > 0) {
100                            MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
101    
102                            message = MBMessageServiceUtil.getMessage(
103                                    thread.getRootMessageId());
104                    }
105    
106                    request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
107            }
108    
109            public static void getThreadMessage(PortletRequest portletRequest)
110                    throws Exception {
111    
112                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
113                            portletRequest);
114    
115                    getThreadMessage(request);
116            }
117    
118    }