Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this the correct way of doing this

ashish kulkarni
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get messages from my properties file, in my
java code, so i have written a class as below,
i have used singleton pattern so there is only one
instance of this class, and then i have a method
called getMessage which returns the message from
properties file..
I need to put some code for internatinalization
messages, any suggestions.
import javax.servlet.http.*;
import java.util.*;
import org.apache.struts.util.*;
import org.apache.struts.action.*;
* <p>Title:MapsMessageResource </p>
* <p>Description: This class gets the message text
fromt he resource file,
* it basically uses
* class</p>
public class MapsMessageResource
private static MapsMessageResource instance = new
private MapsMessageResource()
public static MapsMessageResource getInstance()
if (instance == null)
instance = new MapsMessageResource();
return instance;

public String getMessage(String key,
HttpServletRequest request, HttpSession session)
Locale locale =
if(locale== null)
locale = request.getLocale();
return getMessageFromBundle(locale, key,
private String getMessageFromBundle(Locale locale,
String key, String config)
MessageResources bundle =getMessageResource(config);
return bundle.getMessage(locale, key);
private String getConfig(Locale locale)
return "";
private MessageResources getMessageResource(String
return MessageResources.getMessageResources(config);
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic