package com.chenyang.nse.bussiness.tools.msg;

import com.chenyang.nse.bussiness.tools.spring.SpringUtil;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MesUtil {
   public static String getMsg(String name, String[] str) {
      String result = "";
      String reg = "\\{\\w*}";
      Pattern pattern = Pattern.compile(reg);
      Map<String, String> msg_cn = (Map)SpringUtil.getBean("msg_cn");
      result = (String)msg_cn.get(name);
      if (str != null && str.length != 0) {
         Matcher matcher = pattern.matcher((CharSequence)msg_cn.get(name));

         int count;
         for(count = 0; matcher.find(); ++count) {
            if (str.length > count) {
               String group = matcher.group();
               result = result.replace(group, str[count]);
            } else {
               System.out.println("参数不正确");
            }
         }

         if (str.length != count) {
            System.out.println("参数不正确");
         }

         return result;
      } else {
         return result;
      }
   }

   public static String getContent(Map<String, String> params, String content) {
      String reg = "\\{\\w*}";
      Pattern pattern = Pattern.compile(reg);
      Matcher matcher = pattern.matcher(content);

      while(matcher.find()) {
         String group = matcher.group();
         String key = group.substring(1, group.length() - 1);
         if (params.containsKey(key)) {
            content = content.replace(group, (CharSequence)params.get(key));
         }
      }

      return content;
   }

   public static void main(String[] args) {
      String reg = "\\{\\w*}";
      Pattern pattern = Pattern.compile(reg);
      Matcher matcher = pattern.matcher("用户[{0}]对角色模块进行了列表查询操作。");
   }
}
