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.servlet.SessionErrors;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.security.auth.PrincipalException;
020    import com.liferay.portal.struts.PortletAction;
021    import com.liferay.portlet.messageboards.service.MBThreadServiceUtil;
022    
023    import javax.portlet.ActionRequest;
024    import javax.portlet.ActionResponse;
025    import javax.portlet.PortletConfig;
026    
027    import org.apache.struts.action.ActionForm;
028    import org.apache.struts.action.ActionMapping;
029    
030    /**
031     * @author Deepak Gothe
032     */
033    public class DeleteThreadAction extends PortletAction {
034    
035            public void processAction(
036                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
037                            ActionRequest actionRequest, ActionResponse actionResponse)
038                    throws Exception {
039    
040                    try {
041                            deleteThread(actionRequest, actionResponse);
042    
043                            sendRedirect(actionRequest, actionResponse);
044                    }
045                    catch (Exception e) {
046                            if (e instanceof PrincipalException) {
047                                    SessionErrors.add(actionRequest, e.getClass().getName());
048    
049                                    setForward(actionRequest, "portlet.message_boards.error");
050                            }
051                            else {
052                                    throw e;
053                            }
054                    }
055            }
056    
057            protected void deleteThread(
058                            ActionRequest actionRequest, ActionResponse actionResponse)
059                    throws Exception {
060    
061                    long threadId = ParamUtil.getLong(actionRequest, "threadId");
062    
063                    MBThreadServiceUtil.deleteThread(threadId);
064            }
065    
066    }