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