1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.messageboards.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.theme.ThemeDisplay;
27  import com.liferay.portal.util.PortalUtil;
28  import com.liferay.portal.util.WebKeys;
29  import com.liferay.portlet.messageboards.model.MBCategory;
30  import com.liferay.portlet.messageboards.model.MBMessage;
31  import com.liferay.portlet.messageboards.model.MBThread;
32  import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
33  import com.liferay.portlet.messageboards.service.MBBanLocalServiceUtil;
34  import com.liferay.portlet.messageboards.service.MBCategoryServiceUtil;
35  import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
36  import com.liferay.portlet.messageboards.service.MBThreadLocalServiceUtil;
37  
38  import javax.portlet.ActionRequest;
39  import javax.portlet.RenderRequest;
40  
41  import javax.servlet.http.HttpServletRequest;
42  
43  /**
44   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   *
48   */
49  public class ActionUtil {
50  
51      public static void getCategory(ActionRequest actionRequest)
52          throws Exception {
53  
54          HttpServletRequest request = PortalUtil.getHttpServletRequest(
55              actionRequest);
56  
57          getCategory(request);
58      }
59  
60      public static void getCategory(RenderRequest renderRequest)
61          throws Exception {
62  
63          HttpServletRequest request = PortalUtil.getHttpServletRequest(
64              renderRequest);
65  
66          getCategory(request);
67      }
68  
69      public static void getCategory(HttpServletRequest request)
70          throws Exception {
71  
72          // Add redundant check here because the JSP does not check permissions
73          // on the initial search container
74  
75          ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
76              WebKeys.THEME_DISPLAY);
77  
78          MBBanLocalServiceUtil.checkBan(
79              themeDisplay.getScopeGroupId(), themeDisplay.getUserId());
80  
81          long categoryId = ParamUtil.getLong(request, "categoryId");
82  
83          MBCategory category = null;
84  
85          if ((categoryId > 0) &&
86              (categoryId != MBCategoryImpl.DEFAULT_PARENT_CATEGORY_ID)) {
87  
88              category = MBCategoryServiceUtil.getCategory(categoryId);
89          }
90  
91          request.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category);
92      }
93  
94      public static void getMessage(ActionRequest actionRequest)
95          throws Exception {
96  
97          HttpServletRequest request = PortalUtil.getHttpServletRequest(
98              actionRequest);
99  
100         getMessage(request);
101     }
102 
103     public static void getMessage(RenderRequest renderRequest)
104         throws Exception {
105 
106         HttpServletRequest request = PortalUtil.getHttpServletRequest(
107             renderRequest);
108 
109         getMessage(request);
110     }
111 
112     public static void getMessage(HttpServletRequest request) throws Exception {
113         long messageId = ParamUtil.getLong(request, "messageId");
114 
115         MBMessage message = null;
116 
117         if (messageId > 0) {
118             message = MBMessageServiceUtil.getMessage(messageId);
119         }
120 
121         request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
122     }
123 
124     public static void getThreadMessage(ActionRequest actionRequest)
125         throws Exception {
126 
127         HttpServletRequest request = PortalUtil.getHttpServletRequest(
128             actionRequest);
129 
130         getThreadMessage(request);
131     }
132 
133     public static void getThreadMessage(RenderRequest renderRequest)
134         throws Exception {
135 
136         HttpServletRequest request = PortalUtil.getHttpServletRequest(
137             renderRequest);
138 
139         getThreadMessage(request);
140     }
141 
142     public static void getThreadMessage(HttpServletRequest request)
143         throws Exception {
144 
145         long threadId = ParamUtil.getLong(request, "threadId");
146 
147         MBMessage message = null;
148 
149         if (threadId > 0) {
150             MBThread thread = MBThreadLocalServiceUtil.getThread(threadId);
151 
152             message = MBMessageServiceUtil.getMessage(
153                 thread.getRootMessageId());
154         }
155 
156         request.setAttribute(WebKeys.MESSAGE_BOARDS_MESSAGE, message);
157     }
158 
159 }