|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.ResourceBundle
com.xerceo.text.Messages
public class Messages
Supports the localization of Java programs by providing convenience methods to format and log text messages derived from an XML message bundle. This class supports three common ways to store localized messages in an XML file: one XML file per project, one XML file per package, and one XML file per class. However, the code to retrieve a Messages for a given class insulates the calling program from knowing how the underlying XML documents are arranged in the project. This allows you to migrate from a one per project approach to a one per package or class approach as the project grows in the number of messages. See the XML DTD xmsg_1_0.dtd for more details. The primary design goals were to provide an interface that behaves like a standard ResourceBundle, but adds the following features:
| Field Summary |
|---|
| Fields inherited from class java.util.ResourceBundle |
|---|
parent |
| Method Summary | |
|---|---|
void |
debug(java.lang.String message)
Writes a debug message to the log if Level.FINEST is
enabled on the Log4J Logger. |
void |
debug(java.lang.String template,
java.lang.Object param1)
Writes a debug message to the log if Level.FINEST is
enabled on the Log4J Logger. |
void |
debug(java.lang.String template,
java.lang.Object[] params)
Writes a debug message to the log if Level.DEBUG is
enabled on the Log4J Logger. |
void |
debug(java.lang.String template,
java.lang.Object[] params,
java.lang.Throwable thrown)
Writes a debug message to the log if Level.DEBUG is
enabled on the Log4J Logger. |
boolean |
equals(java.lang.Object obj)
Determines if obj is equivalent to this. |
static Messages |
forClass(java.lang.Class cls)
Find or create a Messages for the specified class for
the current default Locale. |
static Messages |
forClass(java.lang.Class cls,
java.util.Locale locale)
Find or create a Messages for the specified class for
the specified Locale. |
java.lang.String |
format(java.lang.String id)
Returns a formatted, localized message. |
java.lang.String |
format(java.lang.String id,
java.lang.Object param1)
Returns a formatted, localized message. |
java.lang.String |
format(java.lang.String id,
java.lang.Object[] params)
Returns a formatted, localized message. |
java.util.Enumeration |
getKeys()
Returns an enumeration of the keys in this message bundle. |
java.util.Locale |
getLocale()
Returns the actual locale the messages in this message bundle are translated to. |
org.apache.log4j.Logger |
getLogger()
Provides access to the Log4J Logger instance this message bundle uses to log messages to. |
java.lang.String |
getName()
Returns the name of this message bundle. |
protected java.lang.Object |
handleGetObject(java.lang.String objKey)
Gets an object for the given key from this resource bundle. |
int |
hashCode()
Returns a code based on the key of the message bundle. |
boolean |
isDebugEnabled()
Quick check to see if debugging is enabled for this logger. |
boolean |
isLoggable(java.lang.String id)
Determines if a message identified by id would be sent to
the underlying logger based on its configured severity level. |
java.lang.String |
log(java.lang.String id)
Formats, logs, and returns a localized message to the underlying Log4J Logger. |
java.lang.String |
log(java.lang.String id,
java.lang.Object param1)
Formats, logs, and returns a localized message to the underlying Log4J Logger. |
java.lang.String |
log(java.lang.String id,
java.lang.Object[] params)
Formats, logs, and returns a localized message to the underlying Log4J Logger. |
java.lang.String |
log(java.lang.String id,
java.lang.Object[] params,
java.lang.Throwable thrown)
Formats, logs, and returns a localized message to the underlying Log4J Logger with an exception. |
java.lang.String |
log(java.lang.String id,
java.lang.Object param1,
java.lang.Throwable thrown)
Formats, logs, and returns a localized message to the underlying Log4J Logger. |
java.lang.String |
log(java.lang.String id,
java.lang.Throwable thrown)
Formats, logs, and returns a localized message to the underlying Log4J Logger with an exception. |
java.lang.String |
toString()
Provides a String representation of the underlying state of this object suitable for debugging purposes. |
| Methods inherited from class java.util.ResourceBundle |
|---|
getBundle, getBundle, getBundle, getObject, getString, getStringArray, setParent |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public static final Messages forClass(java.lang.Class cls)
Messages for the specified class for
the current default Locale. If a bundle has already been created for
this class for the current default locale, it is returned directly.
Otherwise, a new Messages is created by locating the
underlying XML document containing the localized messages for
cls. The search algorithm behaves like the standard Java
ResourceBundle.getBundle(...) search algorithm.
Specifically, the search algorithm search for an appropriate XML message
bundle document in the following order:
Messages mb =
Messages.forClass(jmx.User.class, Locale.US);
class-level bundles
- jmx/User_xmsg_en_US.xml
- jmx/User_xmsg_en.xml
- jmx/User_xmsg.xml
package-level bundles
- jmx/xmsg_en_US.xml
- jmx/xmsg_en.xml
- jmx/xmsg.xml
project-level bundles
- xmsg_en_US.xml
- xmsg_en.xml
- xmsg.xml
cls - The class that needs localized messages.
java.util.ResourceBundle, the provided
Messages may be for a fallback locale.
public static final Messages forClass(java.lang.Class cls,
java.util.Locale locale)
Messages for the specified class for
the specified Locale. If a bundle has already been created for
this class for the specified locale, it is returned directly.
Otherwise, a new Messages is created by locating the
underlying XML document containing the localized messages for
cls.
cls - The class that needs localized messages.locale - The desired locale.
java.util.ResourceBundle, the provided
Messages may be for a fallback locale.public java.util.Enumeration getKeys()
getKeys in class java.util.ResourceBundleprotected java.lang.Object handleGetObject(java.lang.String objKey)
handleGetObject in class java.util.ResourceBundleobjKey - The identifier of the message to retrieve.
public org.apache.log4j.Logger getLogger()
public java.lang.String getName()
public java.util.Locale getLocale()
getLocale in class java.util.ResourceBundlepublic java.lang.String format(java.lang.String id)
id - The identifier of the message in the message bundle.
public java.lang.String format(java.lang.String id,
java.lang.Object param1)
id - The identifier of the message in the message bundle.param1 - A parameter to be applied to the message during
formatting.
public java.lang.String format(java.lang.String id,
java.lang.Object[] params)
id - The identifier of the message in the message bundle.params - An array of parameters to be applied to the message
during formatting.
public boolean isLoggable(java.lang.String id)
id would be sent to
the underlying logger based on its configured severity level. This
method is useful if constructing the parameters for formatting the
message requires expensive work that should only be undertaken if it will
actually be logged and the message is not needed after it is logged.
id - The identifier of the message.
id would be
logged; false otherwise.
public java.lang.String log(java.lang.String id)
throws MessagesRuntimeException
id - The message id, used to look up a localized message
from the underlying message bundle.
MessagesRuntimeException - if no message is mapped to
the specified id.
public java.lang.String log(java.lang.String id,
java.lang.Throwable thrown)
throws MessagesRuntimeException
id - The message id, used to look up a localized message
from the underlying message bundle.thrown - An exception that needs to be logged.
MessagesRuntimeException - if no message is mapped to
the specified id.
public java.lang.String log(java.lang.String id,
java.lang.Object param1)
throws MessagesRuntimeException
id - The message id, used to look up a message template
from the underlying message bundle and then apply the replace-able
parameter to generate the localized message.param1 - A replace-able parameter to be applied
to the MessageFormat for the given message.
MessagesRuntimeException - if no message is mapped to
the specified id.
public java.lang.String log(java.lang.String id,
java.lang.Object param1,
java.lang.Throwable thrown)
throws MessagesRuntimeException
id - The message id, used to look up a message template
from the underlying message bundle and then apply the replace-able
parameter to generate the localized message.param1 - A replace-able parameter to be applied
to the MessageFormat for the given message.thrown - An exception that needs to be logged.
MessagesRuntimeException - if no message is mapped to
the specified id.
public java.lang.String log(java.lang.String id,
java.lang.Object[] params)
throws MessagesRuntimeException
id - The message id, used to look up a message template
from the underlying message bundle and then apply the replace-able
parameters to generate the localized message.params - An array of replace-able parameters to be applied
to the MessageFormat for the given message.
MessagesRuntimeException - if no message is mapped to
the specified id.
public java.lang.String log(java.lang.String id,
java.lang.Object[] params,
java.lang.Throwable thrown)
throws MessagesRuntimeException
id - The message id, used to look up a message template
from the underlying message bundle and then apply the replace-able
parameters to generate the localized message.params - An array of replace-able parameters to be applied
to the MessageFormat for the given message.thrown - An exception that needs to be logged.
MessagesRuntimeException - if no message is mapped to
the specified id.public boolean isDebugEnabled()
public void debug(java.lang.String message)
Level.FINEST is
enabled on the Log4J Logger.
message - A debug message that does not require any runtime
formatting.
public void debug(java.lang.String template,
java.lang.Object param1)
Level.FINEST is
enabled on the Log4J Logger.
template - A java.text.MessageFormat style message
template to format param1 into a debug message.param1 - A parameter to be applied to the message
as a replaceable parameter during runtime formatting.
public void debug(java.lang.String template,
java.lang.Object[] params)
Level.DEBUG is
enabled on the Log4J Logger.
template - A java.text.MessageFormat style message
template to format params into a debug message.params - An array of parameters to be applied to the message
as replaceable parameters; should not be null but if it is, this method
just logs template as the message.
public void debug(java.lang.String template,
java.lang.Object[] params,
java.lang.Throwable thrown)
Level.DEBUG is
enabled on the Log4J Logger.
template - A java.text.MessageFormat style message
template to format params into a debug message.params - An array of parameters to be applied to the message
as replaceable parameters; should not be null but if it is, this method
just logs template as the message.thrown - An exception related to this debug message.public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
obj is equivalent to this.
equals in class java.lang.Objectobj - The object to compare this to; must be an instance
of Messages.
obj is a Messages and
its key is equivalent to this'; false otherwisepublic java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||