1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.messageboards.action;
16  
17  import com.liferay.portal.kernel.servlet.SessionErrors;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.security.auth.PrincipalException;
20  import com.liferay.portal.struts.PortletAction;
21  import com.liferay.portlet.messageboards.service.MBThreadServiceUtil;
22  
23  import javax.portlet.ActionRequest;
24  import javax.portlet.ActionResponse;
25  import javax.portlet.PortletConfig;
26  
27  import org.apache.struts.action.ActionForm;
28  import org.apache.struts.action.ActionMapping;
29  
30  /**
31   * <a href="DeleteThreadAction.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Deepak Gothe
34   */
35  public class DeleteThreadAction extends PortletAction {
36  
37      public void processAction(
38              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
39              ActionRequest actionRequest, ActionResponse actionResponse)
40          throws Exception {
41  
42          try {
43              deleteThread(actionRequest, actionResponse);
44  
45              sendRedirect(actionRequest, actionResponse);
46          }
47          catch (Exception e) {
48              if (e instanceof PrincipalException) {
49                  SessionErrors.add(actionRequest, e.getClass().getName());
50  
51                  setForward(actionRequest, "portlet.message_boards.error");
52              }
53              else {
54                  throw e;
55              }
56          }
57      }
58  
59      protected void deleteThread(
60              ActionRequest actionRequest, ActionResponse actionResponse)
61          throws Exception {
62  
63          long threadId = ParamUtil.getLong(actionRequest, "threadId");
64  
65          MBThreadServiceUtil.deleteThread(threadId);
66      }
67  
68  }