File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Is this the correct way of doing this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Is this the correct way of doing this" Watch "Is this the correct way of doing this" New topic

Is this the correct way of doing this

ashish kulkarni
Ranch Hand

Joined: Aug 15, 2002
Posts: 131
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);

I agree. Here's the link:
subject: Is this the correct way of doing this
It's not a secret anymore!