public class SimpleMessage extends java.lang.Object implements Message
A simple non-error message that uses the String supplied to it as the message (i.e. it does not look up the message in a resource bundle).
Messages may contain one or more "replacement parameters". To use replacement parameters a message must contain the replacement token {#} where # is the numeric index of the replacement parameter.
For example, to construct a message with two replacement parameters you might supply a message like:
Welcome back {0}, your last login was on {1,date,short}.
At runtime this might get replaced out to result in a message for the user that looks like "Welcome back Johnnie, your last login was on 01/01/2006".
MessageFormat
is used to merge the parameters in to the message and as
a result the parameters can themselves receive formatting through the various java.text.*
formatters.
MessageFormat
,
Serialized FormModifier | Constructor and Description |
---|---|
protected |
SimpleMessage(java.lang.Object... parameters)
Helper constructor to allow subclasses to provide and manipulate replacement
parameters without having to supply a message String.
|
|
SimpleMessage(java.lang.String message,
java.lang.Object... parameters)
Constructs a message with the supplied message string and zero or more parameters
to be merged into the message.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o)
Checks equality by ensuring that the current instance and the 'other' instance are
instances of the same class (though not necessarily SimpleMessage!) and that the
message String and replacement parameters provided are the same.
|
java.lang.String |
getMessage()
Returns the exact message that was supplied in the constructor.
|
java.lang.String |
getMessage(java.util.Locale locale)
Uses the String message passed in as the message template and combines it with any
replacement parameters provided to construct a message for display to the user.
|
protected java.lang.String |
getMessageTemplate(java.util.Locale locale)
Simply returns the message passed in at Construction time.
|
java.lang.Object[] |
getReplacementParameters()
Allows subclasses to access the replacement parameters for this message.
|
int |
hashCode()
Generated hash code method.
|
public SimpleMessage(java.lang.String message, java.lang.Object... parameters)
message
- the String message to display to the user, optionally with placeholders
for replacement parametersparameters
- protected SimpleMessage(java.lang.Object... parameters)
parameters
- zero or more parameters for replacement into the messagepublic java.lang.String getMessage(java.util.Locale locale)
getMessage
in interface Message
locale
- the locale of the current requestprotected java.lang.String getMessageTemplate(java.util.Locale locale)
locale
- the Locale of the message template desiredpublic java.lang.String getMessage()
public java.lang.Object[] getReplacementParameters()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- another object that is a SimpleMessage or subclass thereofpublic int hashCode()
hashCode
in class java.lang.Object
? Copyright 2005-2006, Stripes Development Team.