Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Cover Story: A Practical Solution to Internationalization of a J2EE Web App

Making Web Applications Multilingual

The Solution
When the challenges were completely understood, it was decided that a custom Locale and a custom Resource bundle should be used while providing a solution. The custom Resource bundle will be more like a property resource bundle, in which case a key will be used to retrieve a corresponding value based on the custom Locale. Since this custom resource bundle was expected to be CMA database-centric, essentially the key will be an index into the content in the CMA database supplemented by a custom locale.

The foremost thing we ensured was that the underlying CMA database schema supported retrieval of content based on a content key and a custom locale. The existing CMA database schema did not fully support what we were looking for in terms of a content key. We had to come up with extensions without disturbing other parts of the schema so that localized content could be retrieved by using a unique content key. Based on these extensions, the CMA UI interface was also modified to provide the ability to create content with a unique content key in multiple different languages and the ability to target the content to a particular locale. Figure 6 is a simplified view of the extensions made to the schema with the existing design constraints in place.

The custom implementation of the database-centric Resource bundle was pretty straightforward. The custom Resource bundle class "DynaResourceBundle" was created by extending java.util.ResourceBundle and by overriding the "handleGetObject" method. The "handleGetObject" method is called internally when either the "getString" or the "getObject" method of the Resource bundle is invoked. An instance of this class will be created by passing the custom locale and a String array containing resource names. A constant resource name "CMAX" was used to indicate to the bundle to pull content from the underlying CMA database. All other resource names were considered as non-CMA resources. For all non-CMA resources, the usual ResourceBundle.getBundle method was first used to load the bundle using the resource name and the current locale, and then the content value was retrieved using the key. The resources are tried out in the order they are found in the array while retrieving the content. If the current resource in the array returns null, then the next resource is used to retrieve the content. This is a simple failover approach in case content is not found in one resource. Listing 1 shows the concrete implementation of this method.

Please note that "Label" is a data object representing a label entry in the CMA database. The "handleGetObject" method internally uses a "ContentBO" instance while retrieving content from CMA. The "ContentBO" is a content retrieval business helper object that actually interacts with the data access objects to retrieve content from CMA. The "ContentBO" provides a "getLabel" method that looks up a "DAOFactory" class to get a reference to the DAO implementation for labels and invokes the "getContent" method on the DAO by passing the content key and the locale. The "ContentBO" also has a static method - "getFallBackLocales" - that implements the business requirement for the content look-up fallback logic approach as described earlier. It turns out that this requirement translates into the fallback of custom locales in our design and fits well with the approach we took. So ultimately our choice of the custom locale with "site name" as a variant paid rich dividends. Listing 2 is a code snippet for the "getLabel" method in the ContentBO object.

The "LabelDAO" class is extended out of an abstract DAO class and provides the concrete implementation for retrieving the content from the database. This class implements the "getContent" method; the content key and the custom locale are the arguments to this method.

class LabelDAO extends AbstractDAO {
public CMAObject getContent( String contentKey, Locale locale ) throws SQLException{

Note that this class has package-level access in the package "com.ual.i18n.content.dao" since an instance of this class is actually created by the DAOFactory that is part of the same package. The method "getContent" simply retrieves the language, country, and site name from the locale object, builds the SQL using the content key, and executes the SQL to retrieve the label from the CMA database. Listing 3 shows a code snippet from the method "getContent."

Once the text of the label is retrieved from the database, this method invokes the inherited method "getEncodedText" by passing the retrieved text and "UTF-8" as the character set encoding. The following code snippet is for the "getEncodedText" method defined in the "AbstractDAO" class:

public String getEncodedText
( String text, String encoding ) throws UnsupportedEncodingException {
if( text == null ){
return null;

String encodedText = new String( text.getBytes( "8859_1" ), encoding );

return encodedText;
The "getEncodedText" method converts the text String retrieved from the database to a String encoded with UTF-8 charset. This conversion is required because by default a String is constructed from a sequence of bytes by using the underlying platform's default character encoding. The specification of "8859_1" as a transit encoding to retrieve a byte array from the text String is only a precautionary measure, because a String object's default "getBytes()" method encodes text into a sequence of bytes using the platform's default charset. The behavior of this method when the String cannot be encoded in the default charset is unspecified.

Figure 7 summarizes the method calls required to retrieve a localized label from the "DynaResourceBundle" class while retrieving the content from a CMA database.

Internationalization with Struts
As expected, Struts internationalization support is based on use of Locale class and Resource bundles. However, Struts slightly differs in terms of handling resource bundles. Struts uses the "MessageResources" class and its sub class "PropertyMessageResources" in the "org.apache.struts.util" package to represent resource bundles. Even though Struts web application developers normally do not directly work with an instance of "MessageResources," it provides an API to retrieve localized messages. Struts uses this API internally to provide appropriate messages to the framework clients. One of the reasons why Struts uses message resources to represent resource bundles is because Java's resource bundles are not serializable and Struts wanted to create its own serializable representations. Struts requires that any object it manages internally be serializable because a Struts-based Web application can be deployed in a clustered server environment where session data replication could be enabled.

The big question at that point was how to make our own custom resource bundle "DynaResourceBundle" work with Struts in a way that is transparent to the rest of the application. After much research, we could not find a direct way of incorporating "DynaResourceBundle" in Struts. We had to look into other options. Typically, Struts looks up the following configuration in the struts-config.xml to load an instance of the "MessageResources" class representing an "application.properties" file and retains it in memory for the life of the application.

<message-resources parameter="application" null="false" />

The promise of Struts has always been to enable the incorporation of custom "MessageResources" implementations that retrieve data from other sources such as a database. With this promise in mind, we moved forward with the idea of extending the "MessageResources" class in such a way that we could glue our custom resource bundle to the Struts framework. We created a custom class - "DynaMessageResources" - by extending "MessageResources" as shown in Listing 4.

The main methods that are overridden are the "getMessage" methods. The method that is internally called by the Struts framework is the overloaded "getMessage" method that takes locale, key, and an array of objects. The array of objects is typically passed to this method to replace indexed parameters in the actual messages. The indexed parameters ({0}, {1}) are placeholders in a message that can be replaced at run time with certain values.

The MessageResources class internally uses the "java.text.MessageFormat" class to format messages with run-time values. The MessageResources class provides a default implementation for the "getMessage" method with three arguments; however, one word of caution about this method: it caches the message format objects for each message in a local HashMap for the life of the application. This may prove to be undesirable if the custom message resources class is not supposed to cache because either there is no requirement to cache any messages or caching could be done outside of this class with much more control to refresh the cache on demand. This was the main reason why we had to override that method by eliminating the need to cache the message format objects in a local HashMap. However, the core function of the method was not taken away in the sense that it still performed formatting of the messages using the MessageFormat objects but without caching them. Note that this method internally calls the other overloaded method "getMessage" that takes two arguments: locale and the message key.

More Stories By Murali Kashaboina

Murali Kashaboina leads Enterprise Architecture at United Airlines, Inc. He has 15+ years of enterprise software development experience utilizing a broad range of technologies, including JEE, CORBA, Tuxedo, and Web services. Murali previously published articles in WLDJ and SilverStream Developer Center. He has master’s degree in mechanical engineering from the University of Dayton, Ohio.

More Stories By Bin Liu

Bin Liu is a lead software engineer at United Airlines. Bin has more than seven years of experience developing distributed applications using J2EE technologies, WebLogic, Tuxedo, C++, and Web services. Bin has previously published articles in WLDJ.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
Raj Kumar Kundu 06/04/08 10:52:33 PM EDT

This content is very useful for all those people who are thinking about internationalization of J2EE/ Web Based applications. It explains and points out the areas which should be rather can be considered for this activity. This can help people start thinking in right direction.
But this can be made extremely useful by providing some example files (Resource Bundle related AppResource files and the java files which are using those property files) or snaps of the java codes.

Henry 10/23/07 08:34:21 PM EDT

Is database-centric internationalization with JSF similar with this article?

@ThingsExpo Stories
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
"Digital transformation - what we knew about it in the past has been redefined. Automation is going to play such a huge role in that because the culture, the technology, and the business operations are being shifted now," stated Brian Boeggeman, VP of Alliances & Partnerships at Ayehu, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...