⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupswebhandler.java

📁 easy to use, easy to setup bulletin board (forum)
💻 JAVA
字号:
/*
 * Copyright (C) 2002 by MyVietnam.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum
 * must remain intact in the scripts and in the outputted HTML
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the footer of the pages MUST
 * remain visible when the pages are viewed on the internet or intranet.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 */
package net.myvietnam.mvnplugin.mvnforum.admin;

import javax.servlet.http.*;
import java.sql.*;
import java.util.Collection;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.ParamUtil;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvnplugin.mvnforum.MyUtil;
import net.myvietnam.mvnplugin.mvnforum.db.GroupsBean;
import net.myvietnam.mvnplugin.mvnforum.auth.*;
import net.myvietnam.mvnplugin.mvnforum.MVNForumConstant;

class GroupsWebHandler {

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    GroupsWebHandler() {
    }

    void processAdd(HttpServletRequest request)
        throws BadInputException, CreateException, DatabaseException, DuplicateKeyException,
        ForeignKeyNotFoundException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        String groupName        = ParamUtil.getParameterSafe(request, "GroupName", true);
        String groupDesc        = ParamUtil.getParameterSafe(request, "GroupDesc", false);
        int groupOption         = 0;//ParamUtil.getParameterInt(request, "GroupOption");

        GroupsWebHelper.createGroups(""/*groupOwnerName*/, groupName, groupDesc,
                               groupOption, now/*groupCreationDate*/, now/*groupModifiedDate*/);

        //now add owner to group if there is owner for this group
        String groupOwnerName   = ParamUtil.getParameterSafe(request, "GroupOwnerName", false);
        if (groupOwnerName.length() > 0) {
            int groupID     = GroupsWebHelper.getGroupIDFromGroupName(groupName);
            int privilege   = 0;//xem lai, should be GroupAdmin
            try {
                GroupsWebHelper.updateGroupOwner(groupID, // primary key
                                       groupOwnerName, now/*groupModifiedDate*/);
                MemberGroupWebHelper.createMemberGroup(groupID, groupOwnerName, privilege, now, now);
            } catch (ForeignKeyNotFoundException ex) {
                // what should do when member not found ???
                // now, I just do nothing
            } catch (DuplicateKeyException ex) {
                // do nothing, it is not an error (member already in this group)
            }
        }
    }

    public void processUpdate(HttpServletRequest request)
        throws BadInputException, DatabaseException, DuplicateKeyException,
        AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        // primary key column(s)
        int groupID                 = ParamUtil.getParameterInt(request, "group");

        // column(s) to update
        String groupName            = ParamUtil.getParameterSafe(request, "GroupName", true);
        String groupDesc            = ParamUtil.getParameterSafe(request, "GroupDesc", true);

        GroupsWebHelper.updateGroups(groupID, // primary key
                               groupName, groupDesc, now/*groupModifiedDate*/);
    }

    public void processUpdateGroupOwner(HttpServletRequest request)
        throws BadInputException, DatabaseException, ForeignKeyNotFoundException,
        CreateException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        // primary key column(s)
        int groupID             = ParamUtil.getParameterInt(request, "group");

        // check the group
        if (groupID == MVNForumConstant.GROUP_ID_OF_GUEST) {
            throw new AssertionException("Cannot update group owner for virtual group Guest.");
        }
        if (groupID == MVNForumConstant.GROUP_ID_OF_MEMBER) {
            // actually it could be ok to list member in this group
            throw new AssertionException("Cannot update group owner for virtual group Member.");
        }

        // column(s) to update
        String groupOwnerName   = ParamUtil.getParameterSafe(request, "GroupOwnerName", false);

        GroupsWebHelper.updateGroupOwner(groupID, // primary key
                               groupOwnerName, now/*groupModifiedDate*/);

        /*
         * now add owner to group if there is owner for this group
         * if member already in the group, we dont throw Exception (DuplicateKeyException)
         */
        if (groupOwnerName.length() > 0) {
            int privilege   = 0;//xem lai
            try {
                MemberGroupWebHelper.createMemberGroup(groupID, groupOwnerName, privilege, now, now);
            } catch (DuplicateKeyException ex) {
                // do nothing, it is not an error (member already in this group)
            }
        }
    }

    public void prepareView(HttpServletRequest request)
        throws BadInputException, DatabaseException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        // primary key column(s)
        int groupID = ParamUtil.getParameterInt(request, "group");

        GroupsBean bean = GroupsWebHelper.getGroup(groupID);

        request.setAttribute("GroupsBean", bean);
    }

    public void prepareList(HttpServletRequest request)
        throws DatabaseException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAdminSystem();

        Collection beans = GroupsWebHelper.getGroups();

        request.setAttribute("GroupsBeans", beans);
    }
    /*
    public void prepareList_limit(HttpServletRequest request)
        throws BadInputException, DatabaseException, AssertionException, AuthenticationException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        //permission.ensureCan();

        int offset = 0;
        int rows = 10;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException ex) {}
        try {
            rows = ParamUtil.getParameterInt(request, "rows");
        } catch (BadInputException ex) {}

        int totalGroups = GroupsWebHelper.getNumberOfGroups();
        if (offset > totalGroups) {
            throw new BadInputException("The offset is not allowed to be greater than total groups.");
        }

        Collection beans = GroupsWebHelper.getGroups_limit(offset, rows);
        MyUtil.prepareNavigate(request, offset, beans.size(), totalGroups, rows);

        request.setAttribute("GroupsBeans", beans);
        request.setAttribute("TotalGroups", new Integer(totalGroups));
        request.setAttribute("offset", new Integer(offset));
    }*/


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -