jp.terasoluna.fw.web.struts.util
Class SpringMessageResources

java.lang.Object
  extended by org.apache.struts.util.MessageResources
      extended by jp.terasoluna.fw.web.struts.util.SpringMessageResources
All Implemented Interfaces:
java.io.Serializable

public class SpringMessageResources
extends org.apache.struts.util.MessageResources

MessageResources implementation class that uses MessageSource of Spring through Struts.

Set SpringMessageResourcesFactory in "factory" attribute of "message-resources" element in struts-config.xml.

struts-config.xml configuration example(*when parameter is omitted)

 <message-resources parameter=""
   factory="jp.terasoluna.fw.web.struts.util.SpringMessageResourcesFactory"/>
 

struts-config.xml configuration example(*When parameter is omitted)

 <message-resources parameter="hogeMessageSource"
   factory="jp.terasoluna.fw.web.struts.util.SpringMessageResourcesFactory"/>
 

Bean definition file configuration example When ResourceBundleMessageSource is used, specify message property file in basenames property.

 <bean id="messageSource"
       class="org.springframework.context.support.ResourceBundleMessageSource">
   <property name="basenames" value="MessageResources"/>
 </bean>
 
When DataSourceMessageSource is used, DB messages can be used.

 <bean id="messageSource"
       class="jp.terasoluna.fw.message.DataSourceMessageSource">
   <property name="dbMessageResourceDAO" ref="dbMessageResourceDAO"/>
 </bean>
 

Configuration example of Bean definition file when second message resource is defined

 <bean id="messageSource"
       class="jp.terasoluna.fw.message.DataSourceMessageSource">
   <property name="dbMessageResourceDAO" ref="dbMessageResourceDAO"/>    
   <property name="parentMessageSource" ref="parentSource"/>
 </bean>
 
 <bean id="parentSource"
       class="org.springframework.context.support.ResourceBundleMessageSource">
   <property name="basenames" value="MessageResources"/>
 </bean>
 

See Also:
SpringMessageResourcesFactory, ResourceBundleMessageSource, jp.terasoluna.fw.message.DataSourceMessageSource, Serialized Form

Field Summary
private  org.springframework.web.context.WebApplicationContext context
          Application context
private static java.lang.String ERR_BEAN_EXCEPTION
          Error message key
private static org.apache.commons.logging.Log log
          Log instance
private  org.springframework.context.MessageSource messageSource
          Message source of Spring
private static long serialVersionUID
          Serial version ID
 
Fields inherited from class org.apache.struts.util.MessageResources
config, defaultFactory, defaultLocale, factory, formats, returnNull
 
Constructor Summary
SpringMessageResources(org.apache.struts.util.MessageResourcesFactory factory, java.lang.String config)
          Generates SpringMessageResources by using the specified parameter.
SpringMessageResources(org.apache.struts.util.MessageResourcesFactory factory, java.lang.String config, boolean returnNull)
          Generates SpringMessageResources by using the specified parameter.
 
Method Summary
 java.lang.String getMessage(java.util.Locale locale, java.lang.String key)
          Fetches the message statement based on the specified key and locale.
private  void initMessageSource()
          Initializes MessageSource.
 
Methods inherited from class org.apache.struts.util.MessageResources
escape, getConfig, getFactory, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessage, getMessageResources, getReturnNull, isEscape, isPresent, isPresent, localeKey, log, log, messageKey, messageKey, setEscape, setReturnNull
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serial version ID

See Also:
Constant Field Values

log

private static org.apache.commons.logging.Log log
Log instance


ERR_BEAN_EXCEPTION

private static final java.lang.String ERR_BEAN_EXCEPTION
Error message key

See Also:
Constant Field Values

context

private org.springframework.web.context.WebApplicationContext context
Application context


messageSource

private org.springframework.context.MessageSource messageSource
Message source of Spring

Constructor Detail

SpringMessageResources

public SpringMessageResources(org.apache.struts.util.MessageResourcesFactory factory,
                              java.lang.String config)
Generates SpringMessageResources by using the specified parameter

Parameters:
factory - Message resource factory
config - Bean name of MessageSource fetched from container (Default"messageSource" when it is omitted, )

SpringMessageResources

public SpringMessageResources(org.apache.struts.util.MessageResourcesFactory factory,
                              java.lang.String config,
                              boolean returnNull)
Generates SpringMessageResources by using the specified parameter.

Parameters:
factory - Message resource factory
config - Bean name of MessageSource fetched from the container (Default "messageSource" when it is omitted)
returnNull - returnNull of org.apache.struts.util.MessageResources class. When false is specified and the message corresponding to the key does not exist, returns the message in Locale.key format.
Method Detail

initMessageSource

private void initMessageSource()
Initializes MessageSource.


getMessage

public java.lang.String getMessage(java.util.Locale locale,
                                   java.lang.String key)
Fetches message statement based on the specified key and locale.

Specified by:
getMessage in class org.apache.struts.util.MessageResources
See Also:
MessageResources.getMessage(java.util.Locale, java.lang.String)