01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * 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: */package com.liferay.portlet.messageboards.action;
22:
23: import com.liferay.portal.kernel.util.Constants;
24: import com.liferay.portal.kernel.util.ParamUtil;
25: import com.liferay.portal.model.Layout;
26: import com.liferay.portal.security.auth.PrincipalException;
27: import com.liferay.portal.struts.PortletAction;
28: import com.liferay.portal.util.WebKeys;
29: import com.liferay.portlet.messageboards.service.MBBanServiceUtil;
30: import com.liferay.util.servlet.SessionErrors;
31:
32: import javax.portlet.ActionRequest;
33: import javax.portlet.ActionResponse;
34: import javax.portlet.PortletConfig;
35:
36: import org.apache.struts.action.ActionForm;
37: import org.apache.struts.action.ActionMapping;
38:
39: /**
40: * <a href="BanUserAction.java.html"><b><i>View Source</i></b></a>
41: *
42: * @author Michael Young
43: *
44: */
45: public class BanUserAction extends PortletAction {
46:
47: public void processAction(ActionMapping mapping, ActionForm form,
48: PortletConfig config, ActionRequest req, ActionResponse res)
49: throws Exception {
50:
51: String cmd = ParamUtil.getString(req, Constants.CMD);
52:
53: try {
54: if (cmd.equals("ban")) {
55: banUser(req);
56: } else if (cmd.equals("unban")) {
57: unbanUser(req);
58: }
59:
60: sendRedirect(req, res);
61: } catch (Exception e) {
62: if (e instanceof PrincipalException) {
63: SessionErrors.add(req, e.getClass().getName());
64:
65: setForward(req, "portlet.message_boards.error");
66: } else {
67: throw e;
68: }
69: }
70: }
71:
72: protected void banUser(ActionRequest req) throws Exception {
73: Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT);
74:
75: long banUserId = ParamUtil.getLong(req, "banUserId");
76:
77: MBBanServiceUtil.addBan(layout.getPlid(), banUserId);
78: }
79:
80: protected void unbanUser(ActionRequest req) throws Exception {
81: Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT);
82:
83: long banUserId = ParamUtil.getLong(req, "banUserId");
84:
85: MBBanServiceUtil.deleteBan(layout.getPlid(), banUserId);
86: }
87:
88: }
|