Solved

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

Posted on 2009-07-07
1
230 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql import cannot be resolved jsp 3 74
Cisco ASA: Java web start no go, asdm launcher no go 3 57
wild fly 8 startup error 2 37
How to log java errors in tomcat 8 24
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

762 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