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.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.MBCategoryConstants;
023    import com.liferay.portlet.messageboards.model.MBMessage;
024    import com.liferay.portlet.messageboards.model.MBThread;
025    import com.liferay.portlet.messageboards.service.MBBanLocalServiceUtil;
026    import com.liferay.portlet.messageboards.service.MBCategoryServiceUtil;
027    import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
028    import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
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) &&
056                            (categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)) {
057    
058                            category = MBCategoryServiceUtil.getCategory(categoryId);
059                    }
060    
061                    request.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category);
062            }
063    
064            public static void getCategory(PortletRequest portletRequest)
065                    throws Exception {
066    
067                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
068                            portletRequest);
069    
070                    getCategory(request);
071            }
072    
073            public static void getMessage(HttpServletRequest request) throws Exception {
074                    long messageId = ParamUtil.getLong(request, "messageId");
075    
076                    MBMessage message = null;
077    
078                    if (messageId > 0) {
079                            message = MBMessageServiceUtil.getMessage(messageId);
080                    }
081    
082                    request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
083            }
084    
085            public static void getMessage(PortletRequest portletRequest)
086                    throws Exception {
087    
088                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
089                            portletRequest);
090    
091                    getMessage(request);
092            }
093    
094            public static void getThreadMessage(HttpServletRequest request)
095                    throws Exception {
096    
097                    long threadId = ParamUtil.getLong(request, "threadId");
098    
099                    MBMessage message = null;
100    
101                    if (threadId > 0) {
102                            MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
103    
104                            message = MBMessageServiceUtil.getMessage(
105                                    thread.getRootMessageId());
106                    }
107    
108                    request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
109            }
110    
111            public static void getThreadMessage(PortletRequest portletRequest)
112                    throws Exception {
113    
114                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
115                            portletRequest);
116    
117                    getThreadMessage(request);
118            }
119    
120    }