KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > MemberPermissionWebHandler


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/MemberPermissionWebHandler.java,v 1.15 2006/04/14 17:05:25 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.15 $
5  * $Date: 2006/04/14 17:05:25 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  * @author: Mai Nguyen
40  */

41 package com.mvnforum.admin;
42
43 import java.util.ArrayList JavaDoc;
44 import java.util.Locale JavaDoc;
45
46 import com.mvnforum.MVNForumResourceBundle;
47 import com.mvnforum.MyUtil;
48 import com.mvnforum.auth.*;
49 import com.mvnforum.db.*;
50 import net.myvietnam.mvncore.exception.*;
51 import net.myvietnam.mvncore.util.GenericParamUtil;
52 import net.myvietnam.mvncore.util.I18nUtil;
53 import net.myvietnam.mvncore.web.GenericRequest;
54 import org.apache.commons.logging.Log;
55 import org.apache.commons.logging.LogFactory;
56
57 public class MemberPermissionWebHandler
58 {
59     private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
60
61     private static Log log = LogFactory.getLog(MemberPermissionWebHandler.class);
62
63     public MemberPermissionWebHandler() {
64     }
65
66     public void prepareListPermission(GenericRequest request)
67         throws DatabaseException, BadInputException, ObjectNotFoundException,
68         AuthenticationException, AssertionException {
69
70         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
71         MVNForumPermission permission = onlineUser.getPermission();
72         permission.ensureCanAdminSystem();
73
74         int memberID = GenericParamUtil.getParameterInt(request, "memberid");
75
76         MemberBean memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
77         ArrayList JavaDoc memberPermissionBeans = (ArrayList JavaDoc)DAOFactory.getMemberPermissionDAO().getBeans_inMember(memberID);
78
79         int currentSize = memberPermissionBeans.size();
80         int[] currentPermissions = new int[currentSize];
81
82         for (int i = 0; i < currentSize; i++) {
83             MemberPermissionBean memberPermissionBean = (MemberPermissionBean) memberPermissionBeans.get(i);
84             currentPermissions[i] = memberPermissionBean.getPermission();
85         }
86
87         request.setAttribute("MemberBean", memberBean);
88         request.setAttribute("CurrentPermissions", currentPermissions);
89     }
90
91     public void processUpdate(GenericRequest request)
92         throws CreateException, ObjectNotFoundException, BadInputException, DatabaseException,
93         DuplicateKeyException, ForeignKeyNotFoundException, AuthenticationException, AssertionException {
94
95         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
96         MVNForumPermission permission = onlineUser.getPermission();
97         permission.ensureCanAdminSystem();
98
99         Locale JavaDoc locale = I18nUtil.getLocaleInRequest(request);
100
101         String JavaDoc btnAdd = request.getParameter("btnAdd");
102         String JavaDoc btnRemove = request.getParameter("btnRemove");
103         boolean addAction = false;
104         if ((btnAdd != null) && btnAdd.equals("Add")) {
105             addAction = true;
106         } else if ((btnRemove != null) && btnRemove.equals("Remove")) {
107             addAction = false;
108         } else {
109             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_process.no_add_or_remove_is_specified");
110             throw new BadInputException(localizedMessage);
111             //throw new BadInputException("No Add or Remove has been specified. Cannot process!");
112
}
113
114         int memberID = GenericParamUtil.getParameterInt(request, "memberid");
115
116         if (addAction) {
117             log.debug("Add List:" + btnAdd);
118             String JavaDoc[] addList = request.getParameterValues("add");
119             for (int i = 0; (addList != null) && (i < addList.length); i++) {
120                 int perm = Integer.parseInt(addList[i]);
121                 log.debug("perm = " + perm);
122                 DAOFactory.getMemberPermissionDAO().create(memberID, perm);
123             }
124         } else {
125             log.debug("Remove List:" + btnRemove);
126             String JavaDoc[] removeList = request.getParameterValues("remove");
127             for (int i = 0; (removeList != null) && (i < removeList.length); i++) {
128                 int perm = Integer.parseInt(removeList[i]);
129                 log.debug("perm = " + removeList[i]);
130                 if ( (MyUtil.isRootAdminID(memberID)) && (perm == MVNForumPermission.PERMISSION_SYSTEM_ADMIN) ) {
131                     // We dont remove the SystemAdmin permission from the administator with id = 1
132
} else {
133                     DAOFactory.getMemberPermissionDAO().delete(memberID, perm);
134                 }
135             }
136         } //else
137
}
138
139 }
140
Popular Tags