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

📄 categorywebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/CategoryWebHandler.java,v 1.23 2006/04/14 17:05:25 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.23 $
 * $Date: 2006/04/14 17:05:25 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2006 by MyVietnam.net
 *
 * 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 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.
 *
 * 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 at MyVietnam net
 *
 * @author: Minh Nguyen  
 * @author: Mai  Nguyen  
 */
package com.mvnforum.admin;

import java.sql.Timestamp;
import java.util.Collection;
import java.util.Locale;

import com.mvnforum.MVNForumResourceBundle;
import com.mvnforum.MyUtil;
import com.mvnforum.auth.*;
import com.mvnforum.db.CategoryBean;
import com.mvnforum.db.CategoryCache;
import com.mvnforum.db.DAOFactory;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import net.myvietnam.mvncore.util.*;
import net.myvietnam.mvncore.web.GenericRequest;
import net.myvietnam.mvncore.web.GenericResponse;

public class CategoryWebHandler {

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    public CategoryWebHandler() {
    }

    /*
     * @todo: check permission
     */
    public void processAdd(GenericRequest request, GenericResponse response)
        throws BadInputException, CreateException, DatabaseException, DuplicateKeyException,
        ForeignKeyNotFoundException, AuthenticationException, AssertionException {

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

        MyUtil.saveVNTyperMode(request, response);

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        int parentCategoryID            = 0;
        String categoryName             = GenericParamUtil.getParameterSafe(request, "CategoryName", true);
        categoryName = DisableHtmlTagFilter.filter(categoryName);
        String categoryDesc             = GenericParamUtil.getParameterSafe(request, "CategoryDesc", false);
        categoryDesc = DisableHtmlTagFilter.filter(categoryDesc);
        int categoryOption              = 0;//@todo review and support it later
        int categoryStatus              = 0;//@todo review and support it later

        DAOFactory.getCategoryDAO().create(parentCategoryID, categoryName, categoryDesc,
                                 now/*categoryCreationDate*/, now/*categoryModifiedDate*/, 0/*categoryOrder*/,
                                 categoryOption, categoryStatus);

        // Now clear the cache
        CategoryCache.getInstance().clear();
        
        request.setAttribute("CategoryName", categoryName);
    }

    public void prepareDelete(GenericRequest request)
        throws ObjectNotFoundException, BadInputException, DatabaseException, AuthenticationException, AssertionException {

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

        // primary key column(s)
        int categoryID = GenericParamUtil.getParameterInt(request, "category");

        Locale locale = I18nUtil.getLocaleInRequest(request);

        Collection forumsInCategory = DAOFactory.getForumDAO().getForums_inCategory(categoryID);
        if (forumsInCategory.isEmpty() == false) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_not_empty_category");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot delete a not-empty category. Please delete all forums in this category first.");
        }

        CategoryBean categoryBean = DAOFactory.getCategoryDAO().getCategory(categoryID);

        request.setAttribute("CategoryBean", categoryBean);
    }

    public void processDelete(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {

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

        // user must have been authenticated before he can delete
        permission.ensureIsAuthenticated();

        permission.ensureCanDeleteCategory();

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // primary key column(s)
        int categoryID = GenericParamUtil.getParameterInt(request, "category");

        Collection forumsInCategory = DAOFactory.getForumDAO().getForums_inCategory(categoryID);
        if (forumsInCategory.isEmpty() == false) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_not_empty_category");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot delete a not-empty category. Please delete all forums in this category first.");
        }

        // now check the password
        MyUtil.ensureCorrectCurrentPassword(request);

        /*
        try {
            // NOTE: implement it when we add table GroupCategory
            GroupCategoryWebHelper.deleteGroupCategory_inCategory(categoryID);
        } catch (ObjectNotFoundException ex) {}
        */
        DAOFactory.getWatchDAO().delete_inCategory(categoryID);

        DAOFactory.getCategoryDAO().delete(categoryID);

        // Now clear the cache
        CategoryCache.getInstance().clear();
    }

    /*
     * @todo: check permission
     */
    public void prepareEdit(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {

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

        // primary key column(s)
        int categoryID  = GenericParamUtil.getParameterInt(request, "category");

        CategoryBean categoryBean = DAOFactory.getCategoryDAO().getCategory(categoryID);

        request.setAttribute("CategoryBean", categoryBean);
    }

    /*
     * @todo: check permission
     */
    public void processUpdate(GenericRequest request, GenericResponse response)
        throws BadInputException, DatabaseException, DuplicateKeyException,
        ObjectNotFoundException, AuthenticationException, AssertionException {

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

        MyUtil.saveVNTyperMode(request, response);

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        // primary key column(s)
        int categoryID                  = GenericParamUtil.getParameterInt(request, "CategoryID");

        // column(s) to update
        String categoryName             = GenericParamUtil.getParameterSafe(request, "CategoryName", true);
        categoryName = DisableHtmlTagFilter.filter(categoryName);
        String categoryDesc             = GenericParamUtil.getParameterSafe(request, "CategoryDesc", false);
        categoryDesc = DisableHtmlTagFilter.filter(categoryDesc);
        int categoryOrder               = GenericParamUtil.getParameterUnsignedInt(request, "CategoryOrder");
        int categoryOption              = 0;// @todo review and support it later
        int categoryStatus              = 0;// @todo review and support it later

        DAOFactory.getCategoryDAO().update(categoryID, // primary key
                                 categoryName, categoryDesc, now/*categoryModifiedDate*/,
                                 categoryOrder, categoryOption, categoryStatus);

        // Now clear the cache
        CategoryCache.getInstance().clear();
    }

    /*
     * @todo: check permission
     */
    public void processUpdateCategoryOrder(GenericRequest request)
        throws BadInputException, DatabaseException,
        ObjectNotFoundException, AuthenticationException, AssertionException {

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

        Locale locale = I18nUtil.getLocaleInRequest(request);

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        // primary key column(s)
        int categoryID = GenericParamUtil.getParameterInt(request, "category");

        String action  = GenericParamUtil.getParameterSafe(request, "action", true);
        if (action.equals("up")) {
            DAOFactory.getCategoryDAO().decreaseCategoryOrder(categoryID, now);
        } else if (action.equals("down")) {
            DAOFactory.getCategoryDAO().increaseCategoryOrder(categoryID, now);
        } else {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_update_category.unknown_action", new Object[] {action});
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot update CategoryOrder: unknown action: " + action);
        }

        // Now clear the cache
        CategoryCache.getInstance().clear();
    }
}

⌨️ 快捷键说明

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