001
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.kernel.util.StringUtil;
020 import com.liferay.portal.security.auth.PrincipalException;
021 import com.liferay.portal.struts.PortletAction;
022 import com.liferay.portlet.messageboards.LockedThreadException;
023 import com.liferay.portlet.messageboards.service.MBThreadServiceUtil;
024
025 import javax.portlet.ActionRequest;
026 import javax.portlet.ActionResponse;
027 import javax.portlet.PortletConfig;
028
029 import org.apache.struts.action.ActionForm;
030 import org.apache.struts.action.ActionMapping;
031
032
036 public class DeleteThreadAction extends PortletAction {
037
038 @Override
039 public void processAction(
040 ActionMapping actionMapping, ActionForm actionForm,
041 PortletConfig portletConfig, ActionRequest actionRequest,
042 ActionResponse actionResponse)
043 throws Exception {
044
045 try {
046 deleteThreads(actionRequest, actionResponse);
047
048 sendRedirect(actionRequest, actionResponse);
049 }
050 catch (Exception e) {
051 if (e instanceof LockedThreadException ||
052 e instanceof PrincipalException) {
053
054 SessionErrors.add(actionRequest, e.getClass());
055
056 setForward(actionRequest, "portlet.message_boards.error");
057 }
058 else {
059 throw e;
060 }
061 }
062 }
063
064 protected void deleteThreads(
065 ActionRequest actionRequest, ActionResponse actionResponse)
066 throws Exception {
067
068 long threadId = ParamUtil.getLong(actionRequest, "threadId");
069
070 if (threadId > 0) {
071 MBThreadServiceUtil.deleteThread(threadId);
072 }
073 else {
074 long[] deleteThreadIds = StringUtil.split(
075 ParamUtil.getString(actionRequest, "threadIds"), 0L);
076
077 for (int i = 0; i < deleteThreadIds.length; i++) {
078 MBThreadServiceUtil.deleteThread(deleteThreadIds[i]);
079 }
080 }
081 }
082
083 }