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

__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to