/** 初始化角色权限Map。 */
 private void initRoleRightsMap() {
   ApplicationContext ctx = Global._ctx;
   IRoleManager roleManager = (IRoleManager) ctx.getBean("roleManager");
   IModuleManager moduleManager = (IModuleManager) ctx.getBean("moduleManager");
   IFunctionManager functionManager = (IFunctionManager) ctx.getBean("functionManager");
   IMethodManager methodManager = (IMethodManager) ctx.getBean("methodManager");
   // 获得所有角色
   List allRolesList = roleManager.getRoles();
   Role rolePO = null;
   Module modulePO = null;
   List rights = null;
   for (int i = 0; i < allRolesList.size(); i++) {
     rolePO = (Role) allRolesList.get(i);
     rights = new ArrayList();
     // 获得角色对应的模块
     List modulesList = moduleManager.getModulesByRoleId(rolePO.getId());
     for (int j = 0; j < modulesList.size(); j++) {
       modulePO = (Module) modulesList.get(j);
       if (!modulePO.getActionUrl().equals("#")) {
         ModuleAndFunction maf = new ModuleAndFunction();
         maf.setModuleNameSpace(modulePO.getActionUrl());
         // 存放当前模块对应的所有方法并且也对应角色里的功能下的方法
         List methodArrayList = new ArrayList();
         List functionList =
             functionManager.getFunctionsByRoleIdAndModuleId(rolePO.getId(), modulePO.getId());
         for (Iterator iter = functionList.iterator(); iter.hasNext(); ) {
           Function function = (Function) iter.next();
           List methodList = methodManager.getMethodsByFunctionId(function.getId());
           for (int m = 0; m < methodList.size(); m++) {
             Method method = (Method) methodList.get(m);
             methodArrayList.add(method);
           }
         }
         maf.setMethodList(methodArrayList);
         rights.add(maf);
       }
     }
     RoleRightsMap.put(rolePO.getId(), rights);
   }
 }
  /*
   *
   * (non-Javadoc)
   *
   * @see com.opensymphony.xwork.ActionSupport#execute()
   */
  public String execute() {
    Function functionVO = new Function();
    Function oldfunctionVO = null;
    Module moduleVO = null;

    try {

      /** 验证请求的属性是否完整,防止知道URL非法请求----开始 */
      String moduleId = this.getRequest().getParameter("moduleId");
      String name = this.getRequest().getParameter("name");

      if (StringUtils.hasText(moduleId) && StringUtils.hasText(name)) {
        try {
          NumberUtils.parseNumber(moduleId, Integer.class);
        } catch (Exception e) {
          /** 记录日志 */
          LogsApplication appLog = new LogsApplication();
          appLog.setOperator(this.getUserSessionInfo().getName());
          appLog.setLogDate(new Date());
          appLog.setEventType("新增功能异常");
          appLog.setContent(
              "操作员["
                  + this.getUserSessionInfo().getName()
                  + "]"
                  + "新增功能出现异常,异常信息:["
                  + e.getMessage()
                  + "]!");
          appLog.setPriority(LogsApplication.EXCEPTION);
          appLog.setIpAddress(this.getUserSessionInfo().getIpAddress());
          this.appLogManager.saveOrUpdateAppLog(appLog);

          /** 输出错误信息 */
          logger.error(e.getMessage());
          e.printStackTrace();

          return INPUT;
        }
        /** 每个属性都有内容表示正常 */
      } else {
        /** 记录日志 */
        LogsApplication appLog = new LogsApplication();
        appLog.setOperator(this.getUserSessionInfo().getName());
        appLog.setLogDate(new Date());
        appLog.setEventType("新增功能异常");
        appLog.setContent(
            "操作员["
                + this.getUserSessionInfo().getName()
                + "]"
                + "新增功能出现异常,异常信息:["
                + "必填属性值有空值"
                + "]!");
        appLog.setPriority(LogsApplication.EXCEPTION);
        appLog.setIpAddress(this.getUserSessionInfo().getIpAddress());
        this.appLogManager.saveOrUpdateAppLog(appLog);

        /** 输出错误信息 */
        logger.error("必填属性值有空值");
        /** 有空值的属性,返回 */
        return INPUT;
      }

      /** 验证请求的属性是否完整----结束 */

      /** 验证请求的属性是否完整----结束 */

      /** 获取模块对象 */
      moduleVO =
          this.getModuleManager()
              .getModuleById(
                  NumberUtils.parseNumber(StringUtils.trimWhitespace(moduleId), Integer.class));
      if (moduleVO == null) {
        return "emptyModule";
      }

      /** 验证功能是否存在 */
      // oldfunctionVO = this
      // .getFunctionManager()
      // .getFunctionByFunctionName(StringUtils.trimWhitespace(name));
      // if (oldfunctionVO != null) {
      // this
      // .getRequest()
      // .setAttribute(
      // "actionName",
      // this.getWebApplitionUrl()
      // + "/webmanager/module/toAddFunction.action?moduleId="
      // + NumberUtils.parseNumber(moduleId,
      // Integer.class));
      // return "existFunction";
      // }
      /** 设置属性 */
      functionVO.setName(StringUtils.trimWhitespace(name));
      functionVO.setModule(moduleVO);

      this.functionManager.saveOrUpdateFunction(functionVO);

      /** 记录日志 */
      LogsApplication appLog = new LogsApplication();
      appLog.setOperator(this.getUserSessionInfo().getName());
      appLog.setLogDate(new Date());
      appLog.setEventType("新增功能");
      appLog.setContent(
          "操作员["
              + this.getUserSessionInfo().getName()
              + "]"
              + "新增功能,新增功能是["
              + functionVO.getName()
              + "]!");
      appLog.setPriority(LogsApplication.NORMAL);
      appLog.setIpAddress(this.getUserSessionInfo().getIpAddress());
      this.appLogManager.saveOrUpdateAppLog(appLog);

      this.getRequest()
          .setAttribute(
              "actionName",
              this.getWebApplitionUrl()
                  + "/webmanager/module/getModuleFunctions.action?moduleId="
                  + NumberUtils.parseNumber(moduleId, Integer.class));
      return SUCCESS;

    } catch (Exception e) {

      /** 记录日志 */
      LogsApplication appLog = new LogsApplication();
      appLog.setOperator(this.getUserSessionInfo().getName());
      appLog.setLogDate(new Date());
      appLog.setEventType("新增功能异常");
      appLog.setContent(
          "操作员["
              + this.getUserSessionInfo().getName()
              + "]"
              + "新增功能出现异常,异常信息:["
              + e.getMessage()
              + "]!");
      appLog.setPriority(LogsApplication.EXCEPTION);
      appLog.setIpAddress(this.getUserSessionInfo().getIpAddress());
      this.appLogManager.saveOrUpdateAppLog(appLog);

      /** 输出错误信息 */
      logger.error(e.getMessage());
      e.printStackTrace();

      return ERROR;
    }
  }