Use osgi. util. NLS to simplify resource File Access

Source: Internet
Author: User

Eclipse 3.1 provides a new way to access resource files through the osgi. util. NLS class. The specific method is to construct an NLS subclass, as follows:

Public   Class Mymessages Extends NLS {
  Private   Static   Final String bundle_name =   " Gr. schason. mymessages " ; // $ NON-NLS-1 $

 Public StaticString hello_world;
 Public StaticString hello_something;

 Static{
 //Initialize resource Bundles
NLS. initializemessages (bundle_name, mymessages.Class);
}
}

The content of the resource file is the same as before:

Hello_world = Hello World !
Hello_something = Hello { 0 } !

InProgramThe resource usage method is as follows:

System. Out. println (mymessages. hello_world );
System. Out. println (mymessages. BIND (mymessages. hello_something, " World " ));

In this wayCodeIt is a lot simpler, but the class generated by the externalize strings function provided by ECLIPSE jdt is still the previous method, rather than the NLS subclass.

Tip: Enter nls in the. Java file editor and then automatically complete (CTRL + space) to quickly generate the "// $ NON-NLS-N $" tag.

Original address (inaccessible, it seems to have been deleted)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.