aspose file tools*
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
Author

Is this the correct way of doing this

ashish kulkarni
Ranch Hand

Joined: Aug 15, 2002
Posts: 130
Hi,
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.
package com.pfizer.maps.util;
import com.pfizer.maps.common.*;
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
org.apache.struts.util.MessageResource
* class</p>
*/
public class MapsMessageResource
{
private static MapsMessageResource instance = new
MapsMessageResource();
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 =
(Locale)session.getAttribute(Action.LOCALE_KEY);
if(locale== null)
{
locale = request.getLocale();
}
return getMessageFromBundle(locale, key,
getConfig(locale));
}
private String getMessageFromBundle(Locale locale,
String key, String config)
{
MessageResources bundle =getMessageResource(config);
return bundle.getMessage(locale, key);
}
private String getConfig(Locale locale)
{
return "com.pfizer.maps.maps";
}
private MessageResources getMessageResource(String
config)
{
return MessageResources.getMessageResources(config);
}
}


A$HI$H
 
 
subject: Is this the correct way of doing this