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

📄 roleauthmanageaction.java

📁 《JSP网站开发典型模块与实例精讲》一书光盘源码
💻 JAVA
字号:
package org.appfuse.webapp.action;

import java.util.List;

import org.apache.struts.actions.DispatchAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.appfuse.service.StaffManager;
import org.appfuse.model.Staff;
import org.appfuse.webapp.form.StaffForm;
import org.appfuse.util.ServiceFactory;
import org.appfuse.dao.hibernate.StaffDAOHibernate;
import java.util.ArrayList;
import org.appfuse.service.RoleManager;
import org.appfuse.model.Role;
import org.appfuse.model.*;
import org.appfuse.model.*;
import org.appfuse.service.StaffRoleManager;
import org.appfuse.webapp.form.StaffRoleForm;
import org.appfuse.webapp.form.RoleAuthForm;
import org.appfuse.service.RoleAuthManager;
import org.appfuse.service.ModuleManager;
import org.appfuse.service.AuthManager;

public class RoleAuthManageAction
    extends BaseAction {

    private static Log log = LogFactory.getLog(RoleAuthManageAction.class);

    public ActionForward createroleauth(ActionMapping mapping, ActionForm form,
                                        HttpServletRequest request,
                                        HttpServletResponse response) throws
        Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'createroleauth' method...");
        }
        RoleAuthManager roleAuthManager = null;
        RoleAuth roleAuth = new RoleAuth();
        RoleAuthForm roleAuthForm = (RoleAuthForm) form;
        roleAuth.setRoleid(roleAuthForm.getRoleid());
        try {
            AuthManager authMgr = (AuthManager) getBean("authManager");
            Auth auth = authMgr.getAuth(roleAuthForm.getModuleid(), roleAuthForm.getFunctionid());
            roleAuth.setAuthid(auth.getAuthid());
            roleAuthManager = (RoleAuthManager) getBean("roleAuthManager");
            roleAuthManager.saveRoleAuth(roleAuth);
        }
        catch (Exception es) {
            log.error("in createroleauth: ", es);
        }
        return roleauth(mapping, form, request, response);
    }

    public ActionForward removeroleauth(ActionMapping mapping, ActionForm form,
                                        HttpServletRequest request,
                                        HttpServletResponse response) throws
        Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'createroleauth' method...");
        }
        RoleAuthManager roleAuthManager = null;
        RoleAuth roleAuth = new RoleAuth();
        RoleAuthForm roleAuthForm = (RoleAuthForm) form;
        roleAuth.setRoleid(roleAuthForm.getRoleid());
        try {
            AuthManager authMgr = (AuthManager) getBean("authManager");
            Auth auth = authMgr.getAuth(roleAuthForm.getModuleid(), roleAuthForm.getFunctionid());
            roleAuth.setAuthid(auth.getAuthid());
            roleAuthManager = (RoleAuthManager) getBean("roleAuthManager");
            roleAuthManager.removeRoleAuth(roleAuth);
        }
        catch (Exception es) {
            log.error("in removeroleauth: ", es);
        }
        return roleauth(mapping, form, request, response);
    }

    public ActionForward roleauth(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering ' RoleAuthManager list' method...");
        }
        RoleManager roleMgr = (RoleManager) getBean("roleManager");
        ModuleManager moduleMgr = (ModuleManager) getBean("moduleManager");
        AuthManager authMgr = (AuthManager) getBean("authManager");
        RoleAuthForm userForm = (RoleAuthForm) form;
        List modules = null;
        List roleModules = null;
        List list = null;
        Role role = new Role();
        role.setRoleid(userForm.getRoleid());
        try {
            roleModules = roleMgr.getRoleAuth(role);
            modules = moduleMgr.getModules(new Module());
            list = new ArrayList(modules.size());
            for (int j = 0; j < modules.size(); j++) {
                Module first = (Module) modules.get(j);
                ModuleEx moduleEx = new ModuleEx();
                moduleEx.setModule(first);
                moduleEx.setFunctions(moduleMgr.getFunctions(moduleEx.getModuleid()));
                list.add(moduleEx);
            }
            for (int i = 0; i < roleModules.size(); i++) {
                RoleAuth first = (RoleAuth) roleModules.get(i);
                Auth auth = authMgr.getAuth(first.getAuthid());
                for (int j = 0; j < list.size(); j++) {
                    ModuleEx moduleEx = (ModuleEx) list.get(j);
                    if (auth.getModuleid() == moduleEx.getModuleid()) {
                        moduleEx.setAuth(auth.getFunctionid());
                    }
                }
            }
            role = roleMgr.getRole(userForm.getRoleid());
        }
        catch (Exception es) {
            log.error("in list: ", es);
        }
        request.setAttribute("modules", list);
        request.setAttribute("role", role);
        return mapping.findForward("list");
    }

    public ActionForward unspecified(ActionMapping mapping, ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
        Exception {
        return roleauth(mapping, form, request, response);
    }
}

⌨️ 快捷键说明

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