jp.terasoluna.fw.web.struts.action
Class GlobalMessageResources

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

public final class GlobalMessageResources
extends org.apache.struts.util.MessageResources

Class that generates application message resources and system message resources.

As per the Struts specifications, message resource definition is independent for each module Hence, the message resources common to all modules cannot be uniquely defined.
TERASOLUNA provides the method of using the application messages and system messages that are common to all modules.
This class retains system (framework) message resources and application message resources. This class can be referred by using any of the message resource class provided by TERASOLUNA framework.

Constraints
  1. All the system message resources and application message resources provided by TERASOLUNA framework should be fetched from this class.
  2. Fetched message resources does not support internationalization.
Configuration of application message resources

Application message resources are by default fetched from application message resource definition file. The default file name of application message resource definition file is set to the application-messages.properties. For changing the file name, do the following settings in system settings property file (system.properties) with the following key.


 application.messages=sample1-messages
 
.properties extension should always be removed from the file name which is set in application.messages. .properties should always be removed.

Method of using the application message resource definition file
Application message resources can be added by specifying the external file in the file which is defined in application message resource definition file (application-messages.properties) or system settings property file (system.properties)by using the keys(add.message.file.x)mentioned below.
 add.message.file.1=app1-message
 add.message.file.2=app2-message
 
Since the suffix of the property key is a serial number starting with "1", if the serial number is broken in between, read operation of the external file is terminated.
Configuration of system message resources
In GlobalMessageResources, system-message.properties are loaded by default and the system messages are fetched. File name of this system message resource definition cannot be changed.

See Also:
DBMessageResourcesFactory, DBMessageResources, PropertyMessageResourcesExFactory, PropertyMessageResourcesEx, Serialized Form

Field Summary
private static java.lang.String ADD_MESSAGES_FILE
          External message file which is specified in the root message file and which is used for adding the message resources.
private static java.lang.String APPLICATION_CONFIG_KEY
          Application message resource name which is specified in system.properties.
private static java.lang.String DEFAULT_APPLICATION_MESSAGE
          Default application message resource name.
private  java.util.Map<java.lang.String,java.lang.String> fwMessages
          Retains messages of the framework.
private static GlobalMessageResources globalMessageResources
          Singleton object.
private  java.util.Map<java.lang.String,java.lang.String> globalMessages
          Retains the messages that are unique to the system.
private static org.apache.commons.logging.Log log
          Log class.
private static long serialVersionUID
          Serial version ID
private static java.lang.String SYSTEM_MESSAGE
          Framework message resource name.
 
Fields inherited from class org.apache.struts.util.MessageResources
config, defaultFactory, defaultLocale, factory, formats, returnNull
 
Constructor Summary
private GlobalMessageResources(org.apache.struts.util.MessageResourcesFactory factory, java.lang.String config)
          Generates GlobalMessageResourcesas per the specified parameter.
 
Method Summary
private  void applicationInit()
          Loads application message resource file and fetches message resources.
private  java.util.Map<java.lang.String,java.lang.String> getAddApplicationMap(java.util.Properties prop, java.lang.String rootProperty)
          Fetches the list of external message resource file from the application root message and fetches the actual messages. Returns empty map even if the external file does not exist. When the name of root file and name of file to be loaded matches, it escapes from infinite loop and skips the read operation.
static GlobalMessageResources getInstance()
          Returns singleton instance of this class.
 java.lang.String getMessage(java.util.Locale locale, java.lang.String key)
          Returns messages. The priority sequence for fetching the messages, is as follows. Application message resources and System message resources
private  java.util.Map<java.lang.String,java.lang.String> getRootApplicationMap(java.util.Properties prop)
          Returns the message list map which is specified in root message file of application. Returns empty map even if the message list does not exist.
private  void globalInit()
          Refills the map by reading the property file.
 
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 class.


fwMessages

private java.util.Map<java.lang.String,java.lang.String> fwMessages
Retains the messages of framework.


globalMessages

private java.util.Map<java.lang.String,java.lang.String> globalMessages
Retains the messages that are unique to the system.


SYSTEM_MESSAGE

private static final java.lang.String SYSTEM_MESSAGE
Frameowrk message resource name.

See Also:
Constant Field Values

DEFAULT_APPLICATION_MESSAGE

private static final java.lang.String DEFAULT_APPLICATION_MESSAGE
Default application message resource name.

See Also:
Constant Field Values

APPLICATION_CONFIG_KEY

private static final java.lang.String APPLICATION_CONFIG_KEY
Application message resource name which is specified in system.properties.

See Also:
Constant Field Values

ADD_MESSAGES_FILE

private static final java.lang.String ADD_MESSAGES_FILE
External message file which is specified in the root message file and which is used for adding the message resources

See Also:
Constant Field Values

globalMessageResources

private static GlobalMessageResources globalMessageResources
Singleton object.

Constructor Detail

GlobalMessageResources

private GlobalMessageResources(org.apache.struts.util.MessageResourcesFactory factory,
                               java.lang.String config)
Generates GlobalMessageResources as per the specified parameter.

Parameters:
factory - Message resource factory
config - Paaremeter set in this MessageResource
Method Detail

getInstance

public static GlobalMessageResources getInstance()
Returns singleton instance of this class

Returns:
GlobalMessageResources Singleton instance of this class

globalInit

private void globalInit()
Refills the map by reading the property file.


applicationInit

private void applicationInit()
Loads the application message resource file and fetches the message resources.


getRootApplicationMap

private java.util.Map<java.lang.String,java.lang.String> getRootApplicationMap(java.util.Properties prop)
Returns the message list map which is specified in the root message file of the application. Returns empty map even if the message list does not exist.

Parameters:
prop - Root property file
Returns:
Messages specified in the root property file

getAddApplicationMap

private java.util.Map<java.lang.String,java.lang.String> getAddApplicationMap(java.util.Properties prop,
                                                                              java.lang.String rootProperty)
Fetches the list of external message resource file from the application root message. Fetches the messages. Returns empty map even if the external file does not exist. When the name of root file and name of file to be loaded match, escapes from infinite loop and skips the read operation.
Parameters:
prop - Root property file
rootProperty - Root property file name
Returns:
External message map

getMessage

public java.lang.String getMessage(java.util.Locale locale,
                                   java.lang.String key)
Returns the message. The priority sequence to fetch the messages is as follows
  1. Application message resources
  2. System message resources

Specified by:
getMessage in class org.apache.struts.util.MessageResources
Parameters:
locale - Locale object
key - Message resource key
Returns:
Message