Solved

How to get messages from resource file based on locale in Apache Axis.

Posted on 2009-07-07
1
227 Views
Last Modified: 2012-05-07
How do I get locale-sensitive messages from a message resource file (.properties file) while inside Apache Axis? Java/Struts provide a way to do this very easily in Action classes like the function listed in the code section below.

The correct message is returned from the correct locale-sensitive .properties file. How can I do this inside Apache Axis?



protected String getMessageResource(HttpServletRequest request, String resourceKey, Object[] args) {

	Locale userLocale = getLocale(request);
 

	ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);

	MessageResourcesConfig[] mrc = moduleConfig.findMessageResourcesConfigs();

        

	// Look through all module's MessageResources

	for (int i = 0; i < mrc.length; i++) {

		MessageResources resources = this.getResources(request, mrc[i].getKey());
 

		String text = resources.getMessage(userLocale, resourceKey, args);

            

		if (text != null) {

			return text;

		}

	}

	return "";

}

Open in new window

0
Comment
Question by:brian-barnett
1 Comment
 

Accepted Solution

by:
brian-barnett earned 0 total points
ID: 24800129
Found a solution. Code snippet below.

My .properties files are in ../WEB-INF/classes/resources and are named like this:

messages_el_GR.properties
messages_es.properties
messages.properties

theLocale is a java.util.Locale object.
java.util.ResourceBundle bundle = org.apache.axis.i18n.Messages.getResourceBundle().getBundle("resources.messages", theLocale);

String text = bundle.getString("theKey");

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now