Browse DevX
Sign up for e-mail newsletters from DevX


Building Internationalized J2EE Web Applications for Disparate Clients : Page 5

Learn an extensible architecture for building internationalized Web applications with J2EE that support not only browsers, but also WAP, IMODE, and other client devices.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Using ResourceBundles
The sample application uses resource bundles to provide I18N support. The resource bundles files, such as the ArticlesGUI_ja_JP.properties file mentioned earlier, contain specific values for the response based on the client's language and the requesting user agent.For example, the initial Options page of the application displays different titles based on the user agent, one each for Web, WAP, and iMode clients. Therefore, the options page ResourceBundle file contains three different "_Options_Page_Heading" properties—one each for the Web, WAP and iMode user agents. Here's an excerpt from the ArticlesGUI_ja_JP.properties file.

Author Note: The symbol "\u65e5\u672c\" in the following code is the Unicode value of the two Japanese characters used in the sample application.

// Options Page Web_Options_Page_Heading=\u65e5\u672c\Rahul's Demo Wap_Options_Page_Heading=\u65e5\u672c\Demo WAP IMode_Options_Page_Heading=\u65e5\u672c\Demo -- iMode

The following code segment fetches the appropriate page heading for the given user agent by adding a prefix to the value of the pageType variable defined in the JSP file. Remember that the JSP page set the pageType variable to a value of "Wap", ":Web" or "iMode", and passed the variable to the XML generator class.


This scheme lets you generate XML pages containing values appropriate for the targeted user agent. The resulting XML document, which is generic, and common to all requests, is subsequently translated into user agent specific format during the XSL transform. Separating the page generation logic in this manner gives you the flexibility to provide different values for different user agents.

Adding Support for Additional User Agents and Languages
As you can see, the architecture makes it relatively easy to add support for other user agents and languages anytime. Here are the steps you would need to take to extend the application to support an additional language or user agent..

Adding support for additional user agents

  • Modify the JSP file to check for the new user agent
  • Create a new value for the pageType variable that identifies the new user agent, and set that value in the JSP file. For example, if you wanted to add support for VoiceXML browsers, then the value of pageType variable might be "VOICE".
  • Create a new XSL stylesheet that corresponds to the new user agent.
  • Add new key value entries in the Resource bundles files that correspond to the new user agent.
Adding support additional support for additional languages

  • Create a new resource bundle file corresponding to the targeted language and country. For example, to provide support for the Korean language and country, you would create a file named ArticlesGUI_ko_KO.properties and write the corresponding entries in Unicode format for all keys. The starting URL for accessing this application in the Korean language will would be:

http://<machine name>:<port>/Options.jsp?language=ko&country=KO

Dealing with Images and Dates
You can even use Resource Bundles to provide language and user agent-specific images. For example:

// Locating user agent specific images using resource bundles Web_Welcome_Image=web.gif Wap_Welcome_Image=wap.wbmp Imode_Welcome_Image=imode.jpg

Note that you use the same pageType variable and locale objects to fetch the appropriate image. For internationalized Date, Numbers and Currency use the java.text package. The following code demonstrates how to retrieve a locale-specific date.

// For Japanese language and Japan Country date

Locale locale = new Locale("ja","JP");

Date today = new Date();

DateFormat dateFormatter;


Creating date as per locale


dateFormatter = DateFormat.getDateInstance(DateFormat.FULL,locale);


You've seen some powerful techniques for handling and displaying internationalized, platform-agnostic content Using these techniques, you can design applications using J2EE, XML and XLST that support any number of client types and languages, and make your applications not only truly global, but also extensible and adaptable for as-yet-unknown client types. You could further improve the design of this application by moving the process to add support for additional user agents and languages from JSP to a Java class. You could even write an intelligent java class to handle the showPage() method processing. The possibilities are endless!

See the sidebar: Products Used to Test and Develop the Sample Application for a complete list of the technology used to create the sample code for this article.

Credits: Many thanks to Mr. Saurabh Bhatnagar for his valuable contributions as technical reviewer for this article.

Rahul Kumar Gupta is a postgraduate in Computer Applications and holds a graduate degree in business management. He has many certifications including Sun's Certification for Java 2 Programmers. He has several years of software development and R&D experience in the IT industry and currently works for the Netcentric division of HCL Technologies Limited, NOIDA (INDIA). He also writes technical articles and is a technical reviewer for some Wrox Java/ECommerce books. You can reach Rahul at rahgup@mailcity.com
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date