KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/GroupPermissionWebHandler.java,v 1.13 2006/04/14 17:05:25 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.13 $
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.auth.*;
48 import com.mvnforum.db.*;
49 import net.myvietnam.mvncore.exception.*;
50 import net.myvietnam.mvncore.util.GenericParamUtil;
51 import net.myvietnam.mvncore.util.I18nUtil;
52 import net.myvietnam.mvncore.web.GenericRequest;
53 import org.apache.commons.logging.Log;
54 import org.apache.commons.logging.LogFactory;
55
56 public class GroupPermissionWebHandler {
57
58     private static Log log = LogFactory.getLog(GroupPermissionWebHandler.class);
59
60     private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
61
62     public GroupPermissionWebHandler() {
63     }
64
65     public void prepareList(GenericRequest request)
66         throws DatabaseException, BadInputException, ObjectNotFoundException, AuthenticationException, AssertionException {
67
68         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
69         MVNForumPermission permission = onlineUser.getPermission();
70         permission.ensureCanAdminSystem();
71
72         int groupID = GenericParamUtil.getParameterInt(request, "group");
73
74         GroupsBean groupsBean = DAOFactory.getGroupsDAO().getGroup(groupID);
75
76         ArrayList JavaDoc groupPermissionBeans = (ArrayList JavaDoc)DAOFactory.getGroupPermissionDAO().getBeans_inGroup(groupID);
77         int currentSize = groupPermissionBeans.size();
78         int[] currentPermissions = new int[currentSize];
79         for (int i = 0; i < currentSize; i++) {
80             GroupPermissionBean groupPermissionBean = (GroupPermissionBean)groupPermissionBeans.get(i);
81             currentPermissions[i] = groupPermissionBean.getPermission();
82         }
83
84         request.setAttribute("GroupsBean", groupsBean);
85         request.setAttribute("CurrentPermissions", currentPermissions);
86     }
87
88     public void processUpdate(GenericRequest request)
89         throws CreateException, ObjectNotFoundException, BadInputException, DatabaseException, DuplicateKeyException,
90         ForeignKeyNotFoundException, AuthenticationException, AssertionException {
91
92         OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
93         MVNForumPermission permission = onlineUser.getPermission();
94         permission.ensureCanAdminSystem();
95
96         Locale JavaDoc locale = I18nUtil.getLocaleInRequest(request);
97
98         String JavaDoc btnAdd = request.getParameter("btnAdd");
99         String JavaDoc btnRemove = request.getParameter("btnRemove");
100
101         boolean addAction = false;
102         if ((btnAdd != null) && btnAdd.equals("Add")) {
103             addAction = true;
104         } else if ((btnRemove != null) && btnRemove.equals("Remove")) {
105             addAction = false;
106         } else {
107             String JavaDoc localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_process.no_add_or_remove_is_specified");
108             throw new BadInputException(localizedMessage);
109             //throw new BadInputException("No Add or Remove has been specified. Cannot process!");
110
}
111
112         int groupID = GenericParamUtil.getParameterInt(request, "group");
113
114         if (addAction) {
115             log.debug("Add List:" + btnAdd);
116             String JavaDoc[] addList = request.getParameterValues("add");
117             for (int i = 0; (addList != null) && (i < addList.length); i++) {
118                 int perm = Integer.parseInt(addList[i]);
119                 log.debug("perm = " + perm);
120                 DAOFactory.getGroupPermissionDAO().create(groupID, perm);
121             }
122         } else {
123             log.debug("Remove List:" + btnRemove);
124             String JavaDoc[] removeList = request.getParameterValues("remove");
125             for (int i = 0; (removeList != null) && (i < removeList.length); i++) {
126                 int perm = Integer.parseInt(removeList[i]);
127                 log.debug("perm = " + removeList[i]);
128                 DAOFactory.getGroupPermissionDAO().delete(groupID, perm);
129             }
130         }//else
131
}
132
133 }
134
Popular Tags