com.waveset.msgcat
Class CustomCatalog

java.lang.Object
  extended bycom.waveset.util.AbstractXmlObject
      extended bycom.waveset.msgcat.CustomCatalog
All Implemented Interfaces:
javax.naming.Referenceable, XmlObject

public class CustomCatalog
extends AbstractXmlObject

An object containing localized messages. Similar to com.waveset.msgcat.Catalog but:
a) can store the messages in the repository rather than on the file system
b) can be modified at run-time
Represents a single custom catalog that consists of a set of locales, each having a set of message-id to translation mappings.


Field Summary
static java.lang.String ATT_ENABLED
           
static java.lang.String ATT_ID
           
static java.lang.String code_id
           
static java.lang.String DEFAULT_ID
           
static java.lang.String ELEMENT
           
static java.lang.String SEP
           
 
Fields inherited from class com.waveset.util.AbstractXmlObject
_trace
 
Constructor Summary
CustomCatalog(org.w3c.dom.Element e)
          Constructs this catalog from an XML element.
CustomCatalog(java.lang.String id)
          Constructor that allows the specification of an id.
 
Method Summary
 void disable()
          Flags this catalog as "disabled".
 void enable()
          Flags this catalog as "enabled".
 java.lang.String getElementName()
          Gets the XML element name for this object.
 java.lang.String getId()
          Gets the id for this catalog.
 java.util.ArrayList getLocales()
          Gets a list of locales currently in the catalog.
 java.lang.String getMessage(java.lang.String id, java.util.Locale locale)
          Gets the message for the given locale.
 java.util.Set getMessageIds(java.util.Locale locale)
          Gets a list of ids for the all the messages in the given locale's message set.
 boolean isEnabled()
          Indicates whether or not this catalog is "enabled".
 java.lang.String localize(java.lang.String id, java.lang.Object[] vals, java.util.Locale locale)
          Return a formatted, localized message with arguments filled in and full locale resolution (i.e.
 void parseXml(org.w3c.dom.Element e)
          Uses the given XML element to fill in the data for this object.
 void putMessage(java.lang.String id, java.lang.String text, java.util.Locale locale)
          Add/set a message id mapping to the catalog for the given locale.
 void removeMessage(java.lang.String id, java.util.Locale locale)
          Remove the given message from the given locale.
 void setDefaultLocale(java.util.Locale locale)
          Set the default locale.
 void toXml(java.lang.StringBuffer b, int indent)
          Serializes this object as XML to the given string buffer.
 
Methods inherited from class com.waveset.util.AbstractXmlObject
addXmlHeader, cloneObject, dump, dumpFile, getReference, println, setTrace, toIdentityString, toVerboseString, toVerboseString, toXml, toXml, toXml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

DEFAULT_ID

public static final java.lang.String DEFAULT_ID
See Also:
Constant Field Values

ELEMENT

public static final java.lang.String ELEMENT
See Also:
Constant Field Values

ATT_ID

public static final java.lang.String ATT_ID
See Also:
Constant Field Values

ATT_ENABLED

public static final java.lang.String ATT_ENABLED
See Also:
Constant Field Values

SEP

public static final java.lang.String SEP
See Also:
Constant Field Values
Constructor Detail

CustomCatalog

public CustomCatalog(java.lang.String id)
Constructor that allows the specification of an id.

Parameters:
id - The id for this catalog.

CustomCatalog

public CustomCatalog(org.w3c.dom.Element e)
              throws WavesetException
Constructs this catalog from an XML element.

Parameters:
e - The XML element to construct this catalog with.
Method Detail

enable

public void enable()
Flags this catalog as "enabled".


disable

public void disable()
Flags this catalog as "disabled".


isEnabled

public boolean isEnabled()
Indicates whether or not this catalog is "enabled".


getId

public java.lang.String getId()
Gets the id for this catalog.

Returns:
The id for this catalog.

setDefaultLocale

public void setDefaultLocale(java.util.Locale locale)
Set the default locale. Will be ignored if the given locale isn't already in the existing set of locales.

Parameters:
locale - The locale to set as default.

putMessage

public void putMessage(java.lang.String id,
                       java.lang.String text,
                       java.util.Locale locale)
Add/set a message id mapping to the catalog for the given locale. Will replace the current entry for the given id if one already exists. Will create the locale if it doesn't already exist.

Parameters:
id - The id for the message.
text - The translated text.
locale - The locale to set this message for.

getLocales

public java.util.ArrayList getLocales()
Gets a list of locales currently in the catalog.

Returns:
List of Locale objects.

getMessageIds

public java.util.Set getMessageIds(java.util.Locale locale)
Gets a list of ids for the all the messages in the given locale's message set.

Parameters:
locale - The locale.
Returns:
If the locale exists for this catalog, then a list of message ids (String's). Otherwise null.

getMessage

public java.lang.String getMessage(java.lang.String id,
                                   java.util.Locale locale)
Gets the message for the given locale. The returned message will not have any arguments filled in. Resolution of the message is strictly for the given locale (will not try the "fr" locale if "fr_CA" is given). Use localize() function to fill in any arguments and to perform full resolution.

Parameters:
id - Id of the message to get.
locale - The locale.
Returns:
If the locale and id exist in the cataloge, the localized version of the message. Otherwise, null.

removeMessage

public void removeMessage(java.lang.String id,
                          java.util.Locale locale)
Remove the given message from the given locale.

Parameters:
id - Id of the message to remove.
locale - The locale.

localize

public java.lang.String localize(java.lang.String id,
                                 java.lang.Object[] vals,
                                 java.util.Locale locale)
Return a formatted, localized message with arguments filled in and full locale resolution (i.e. if the locale "fr_CA_xxx" doesn't contain the id, then locales "fr_CA" will be tried, then "fr", then the default locale). If the message does not exist in the given or default locales, null is returned.

Parameters:
id - The id to use for lookup.
vals - The to pass to the message during formatting.
locale - The locale to localize to.
Returns:
If the id exists in either the given or default locale, then a formatted string. Otherwise, null.

getElementName

public java.lang.String getElementName()
Gets the XML element name for this object.

Specified by:
getElementName in interface XmlObject
Specified by:
getElementName in class AbstractXmlObject

parseXml

public void parseXml(org.w3c.dom.Element e)
              throws WavesetException
Uses the given XML element to fill in the data for this object.

Parameters:
e - The XML element to parse.
Throws:
WavesetException

toXml

public void toXml(java.lang.StringBuffer b,
                  int indent)
Serializes this object as XML to the given string buffer.

Specified by:
toXml in interface XmlObject
Specified by:
toXml in class AbstractXmlObject
Parameters:
b - The string buffer to write to.
indent - Indicates how many spaces to indent, for formatting purposes.