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

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

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

    gembin

    OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

    HBase, Hadoop, ZooKeeper, Cassandra

    Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

    There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

    About Me

     

    學(xué)習(xí)Eclipse NLS

    今天研究了1下Eclipse的NLS,覺(jué)得不錯(cuò),與大家分享....
    messages.properties
    key_1=hello world,here is NLS
    key_2=hello {0}, welcome to my blog
    key_3=hello {0}, please reply to{1} if you like this article
    其中的 {0} 代表MessageHelper.bind(MessageHelper.key_2, "gembin"); 里的第1個(gè)參數(shù),一次類(lèi)推
    public class MessageHelper extends NLS {
       //com.exmple.messages 中的點(diǎn)將會(huì)被轉(zhuǎn)換成"/"
      // 所以最終的路徑為:com/exmple/messages.properties
        private static final String BUNDLE_NAME = "com.exmple.messages"; //$NON-NLS-1$
        public static String key_1;
        public static String key_2;
        static{
            initializeMessages(BUNDLE_NAME, MessageHelper.class);
            
        }
     
        /**
         * Bind the given message's substitution locations with the given string value.
         *
         * @param message
         *            the message to be manipulated
         * @param binding
         *            the object to be inserted into the message
         * @return the manipulated String
         */
        public static String bind(String message, Object binding) {
            return NLS.bind(message, binding);
        }

        /**
         * Bind the given message's substitution locations with the given string values.
         *
         * @param message
         *            the message to be manipulated
         * @param binding1
         *            An object to be inserted into the message
         * @param binding2
         *            A second object to be inserted into the message
         * @return
         */
        public static String bind(String message, Object binding1, Object binding2) {
            return NLS.bind(message, binding1, binding2);
        }

        /**
         * Bind the given message's substitution locations with the given string values.
         *
         * @param message
         *            the message to be manipulated bindings
         * @param bindings
         *            An array of objects to be inserted into the message
         * @return the manipulated String
         */
        public static String bind(String message, Object[] bindings) {
            return NLS.bind(message, bindings);
        }

        /**
         * Initialize the given class with the values from the specified message bundle.
         *
         * @param bundleName -
         *            fully qualified path of the class name
         * @param clazz -
         *            the class where the constants will exist
         */
        @SuppressWarnings("unchecked")
        public static void initializeMessages(String bundleName, Class clazz) {
            NLS.initializeMessages(BUNDLE_NAME, MessageHelper.class);
        }
        
        public static void main(String sp[]){
      
              String s=MessageHelper.bind(MessageHelper.key_2, "hello");
              System.out.println(s);
        }

    }

    posted on 2008-01-23 18:50 gembin 閱讀(3699) 評(píng)論(4)  編輯  收藏

    評(píng)論

    # re: 學(xué)習(xí)Eclipse NLS 2008-01-24 20:35 guest

    什么是nls  回復(fù)  更多評(píng)論   

    # re: 學(xué)習(xí)Eclipse NLS 2008-01-26 15:31 gembin

    Eclipse SRC里的: No need Localized String 1
    可代替ResourceBundle,用來(lái)處理資源文件*.properties,效率更好,更方便,很好的擴(kuò)展性。
    當(dāng)有Key沒(méi)定義,會(huì)get a compile error.
    缺點(diǎn)是:必須維護(hù)2個(gè)文件1個(gè)Properties和1個(gè)Java文件,他們必須同步  回復(fù)  更多評(píng)論   

    # re: 學(xué)習(xí)Eclipse NLS 2008-03-04 21:52 jolly

    請(qǐng)問(wèn)綁定的類(lèi)只能是當(dāng)前類(lèi)嗎?而且不能用內(nèi)部類(lèi)作為綁定類(lèi)?  回復(fù)  更多評(píng)論   

    # re: 學(xué)習(xí)Eclipse NLS 2008-03-05 11:57 gembin

    是可以的。請(qǐng)看如下例子:
    message.properties
    ------------------
    key_1=Say {0} hello to {1} !!
    key_2=Say {0} hello to {1} !!
    key3=Say {0} hello to {1} !!
    key4=Say {0} hello to {1} !!

    TobeBindedMsg.java
    ---------------------
    public class TobeBindedMsg {
    public static String key3;

    static class InnerMsg{
    public static String key4;
    }
    }

    TestNLS.java
    ------------------
    import org.eclipse.osgi.util.NLS;
    public class TestNLS {
    private static final String BUNDLE_NAME = "com.meccala.blog.util.message"; //$NON-NLS-1$
    public static String key_2;
    static {
    NLS.initializeMessages(BUNDLE_NAME, TestNLS.class);
    NLS.initializeMessages(BUNDLE_NAME, Inner.class);
    NLS.initializeMessages(BUNDLE_NAME, TobeBindedMsg.class);
    NLS.initializeMessages(BUNDLE_NAME, TobeBindedMsg.InnerMsg.class);
    }

    static class Inner {
    public static String key_1;
    }

    public static void main(String ggg[]) {
    String s = NLS.bind(Inner.key_1, "1", "gembin");
    System.out.println(s);
    String s1 = NLS.bind(TestNLS.key_2, "2", "gembin");
    System.out.println(s1);
    String s2 = NLS.bind(TobeBindedMsg.key3, "3", "gembin");
    System.out.println(s2);
    String s3 = NLS.bind(TobeBindedMsg.InnerMsg.key4, "4", "gembin");
    System.out.println(s3);
    }
    }



    最后的輸出:
    Say 1 hello to gembin !!
    Say 2 hello to gembin !!
    Say 3 hello to gembin !!
    Say 4 hello to gembin !!
    NOTE:因?yàn)镵ey要求是public static 的所以Inner Class必需是static   回復(fù)  更多評(píng)論   


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(6)

    隨筆分類(lèi)(440)

    隨筆檔案(378)

    文章檔案(6)

    新聞檔案(1)

    相冊(cè)

    收藏夾(9)

    Adobe

    Android

    AS3

    Blog-Links

    Build

    Design Pattern

    Eclipse

    Favorite Links

    Flickr

    Game Dev

    HBase

    Identity Management

    IT resources

    JEE

    Language

    OpenID

    OSGi

    SOA

    Version Control

    最新隨筆

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    free counters
    主站蜘蛛池模板: 亚洲精品国产成人99久久| 日韩中文无码有码免费视频| 亚洲精品动漫人成3d在线 | 国产免费av片在线无码免费看| 亚洲va成无码人在线观看| 亚洲国产精品免费在线观看| 中文字幕亚洲综合久久2| 99久久免费中文字幕精品| 亚洲尹人九九大色香蕉网站| 久久99热精品免费观看动漫 | 亚洲精品影院久久久久久| 亚洲一区二区免费视频| 亚洲AV无码专区在线亚| 日韩在线免费播放| 免费无码国产V片在线观看| 久久精品国产精品亚洲人人| 三级黄色片免费看| 亚洲高清视频免费| 成人毛片免费观看视频大全| 亚洲A∨精品一区二区三区下载| 免费国产真实迷j在线观看| 大片免费观看92在线视频线视频| 国产亚洲一区区二区在线| 久久午夜夜伦鲁鲁片免费无码| 亚洲高清无在码在线无弹窗| 成年女人男人免费视频播放| 美女视频黄a视频全免费网站色 | 高清在线亚洲精品国产二区| 一级做a爰片久久免费| 亚洲AV无码久久精品成人| 国产免费AV片在线播放唯爱网| 色综合久久精品亚洲国产| 亚洲日韩小电影在线观看| 久久国产免费福利永久| 免费观看四虎精品成人| 婷婷亚洲综合五月天小说| 香蕉视频在线观看免费国产婷婷| 人妖系列免费网站观看| 亚洲欧洲在线播放| 亚洲Av无码乱码在线观看性色 | 桃子视频在线观看高清免费完整|