<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ivaneeo's blog

    自由的力量,自由的生活。

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
    package net.sourceforge.jtds.jdbc;

    import java.text.MessageFormat;
    import java.util.Enumeration;
    import java.util.Map;
    import java.util.ResourceBundle;

    public final class Messages {
      private static final String DEFAULT_RESOURCE = "net.sourceforge.jtds.jdbc.Messages";  //默認得資源
      private static ResourceBundle defaultResource;  //和locale的綁定

      private Messages() {
        }

        public static String get(String key) {
            return get(key, null);
        }

        public static String get(String key, Object param1) {
            Object args[] = {param1};
            return get(key, args);
        }

        static String get(String key, Object param1, Object param2) {
            Object args[] = {param1, param2};
            return get(key, args);
        }

        private static String get(String key, Object[] arguments) {
          try {
                ResourceBundle bundle = loadResourceBundle();
                String formatString = bundle.getString(key);
                // No need for any formatting if no parameters are specified
                if (arguments == null || arguments.length == 0) {
                    return formatString;
                } else {
                    MessageFormat formatter = new MessageFormat(formatString);
                    return formatter.format(arguments);
                }
            } catch (java.util.MissingResourceException mre) {
                throw new RuntimeException("No message resource found for message property " + key);
            }
        }

        private static ResourceBundle loadResourceBundle() {
            if (defaultResource == null) {
                defaultResource = ResourceBundle.getBundle(DEFAULT_RESOURCE);
            }
            return defaultResource;
        }

        static void loadDriverProperties(Map propertyMap, Map descriptionMap) {
            final ResourceBundle bundle = loadResourceBundle();
            final Enumeration keys = bundle.getKeys();
            while (keys.hasMoreElements()) {
                final String key = (String) keys.nextElement();
                final String descriptionPrefix = "prop.desc.";
                final String propertyPrefix = "prop.";
                if (key.startsWith(descriptionPrefix)) {
                    descriptionMap.put(key.substring(descriptionPrefix.length()), bundle.getString(key));
                }
                else if (key.startsWith(propertyPrefix)) {
                    propertyMap.put(key.substring(propertyPrefix.length()), bundle.getString(key));
                }
            }
        }
    }

    上面代碼中默認得綁定名為:"net.sourceforge.jtds.jdbc.Messages".其實就是以工程為根目錄,尋找文件Messages.properties.這里查找的方式和類是一樣的.比如:"net.sourceforge.jtds.jdbc.Messages",就是工程根目錄下的net/sourceforge/jtds/jdbc/下的Messages.properties文件.
    這個文件定義很多的屬性,要得到只要用get方法.

      注意這里的defaultResource = ResourceBundle.getBundle(DEFAULT_RESOURCE);沒有設定Locale值,所以文件名為Messages.properties.如果設置了Locale值的話,例如:defaultResource = ResourceBundle.getBundle(DEFAULT_RESOURCE, Locale.ENGLISH);那么它就會去查找文件Messages_en.properties.其他類似加后綴(Locale.CHINA是Messages_zh.properties).

      關于java.text.MessageFormat類,下面通過一個例子就可以說明:
        MessageFormat mf = new MessageFormat("You have {0} messages.");
        Object[] arguments = {"no"};
        System.out.println(mf.format(arguments));  //"You have no messages."

      關于String.startsWith(String prex)是測試字符串是否以prex開頭.
    posted on 2005-08-04 14:43 ivaneeo 閱讀(411) 評論(0)  編輯  收藏 所屬分類: java魔力
    主站蜘蛛池模板: h在线观看视频免费网站| 黄色一级免费网站| 日韩精品人妻系列无码专区免费| 日本一道在线日本一道高清不卡免费| 亚洲婷婷在线视频| 曰曰鲁夜夜免费播放视频| 亚洲熟妇无码爱v在线观看| 9420免费高清在线视频| 777亚洲精品乱码久久久久久 | 美女裸体无遮挡免费视频网站| 成人一a毛片免费视频| 亚洲精品美女久久7777777 | 亚洲精品高清一二区久久| 全部一级一级毛片免费看| 亚洲国产成人精品91久久久| 午夜免费国产体验区免费的| 久久久久亚洲AV无码专区桃色| 在线看片免费人成视频久网下载 | 国产亚洲自拍一区| 国产激情免费视频在线观看| 亚洲激情在线视频| 国产精品视频免费| 亚洲精品无码人妻无码| 亚洲欧洲日产国码高潮αv| 99在线热播精品免费99热| 久久亚洲精品成人av无码网站| 在线观看永久免费| 亚洲AV无码一区二区三区牲色| 亚洲国产人成精品| 国产精品免费无遮挡无码永久视频 | 国产亚洲成人在线播放va| 日日麻批免费40分钟无码| 亚洲人成电影网站色| 中文字幕亚洲无线码| 114级毛片免费观看| 精品亚洲国产成人av| 国产亚洲婷婷香蕉久久精品| 和日本免费不卡在线v| 日日狠狠久久偷偷色综合免费| 亚洲va在线va天堂va不卡下载| 好爽…又高潮了毛片免费看|