Package com.onwbp.base.text
Class UserMessage
java.lang.Object
com.onwbp.base.text.UserMessage
- Direct Known Subclasses:
UserMessageLocalized
,UserMessageRef
,UserMessageString
Common abstract class for holding a text message. This text can be defined in several languages.
A message instance has the following features:
- It is displayed according to a given locale (see method
formatMessage(Locale)
). As each instance is able to hold a specific raw string for various locales, the raw string to be used for display is looked up according to the closestLocale
match. - A message instance may hold parameters. If this is the case, the display uses a limited
MessageFormat
mechanism to substitute the parameters encoded in the localized raw string. Syntax limitation rules:- Format type and style are not managed.
- Escapes single quote (
'
) using a second one. - Escapes entering curly brackets (
{
) using quote characters ('{'
). - Reverses escape for (
'{'[0-9]}
) by removing quotes.
- A message instance may hold a
Throwable
. In this case, the display of the message usually concatenates the throwable stack trace. - A message instance may also hold a severity. The severity is usually used to categorize the message in the context of a validation.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic UserMessageString
createError
(String message) Shortcut for creating a simple error message.static UserMessageString
createError
(String message, Throwable anException) Shortcut for creating a simple error message, with theThrowable
specified.static UserMessageString
createFatal
(String message) Shortcut for creating a simple fatal error message.static UserMessageString
createFatal
(String message, Throwable anException) Shortcut for creating a simple error message, with theThrowable
specified.static UserMessageString
createInfo
(String message) Shortcut for creating a simple information message.static UserMessageString
createWarning
(String message) Shortcut for creating a simple warning message.formatMessage
(Locale aLocale) Formats this message for the specified locale.abstract String
Returns a specific identifier for logging and technical auditing.Returns theThrowable
which is associated to this message, ornull
if none exists.boolean
isError()
Returnstrue
if this message is an error.boolean
isFatal()
Returnstrue
if this message is a fatal error.boolean
isInfo()
Returnstrue
if this message is an information message.boolean
Returnstrue
if this message is a warning.void
setSeverity
(Severity severity) Sets the severity of this message.void
setSeverity
(String aLabel) Sets the severity using the specified severity label.
-
Method Details
-
createFatal
Shortcut for creating a simple fatal error message. -
createFatal
Shortcut for creating a simple error message, with theThrowable
specified. -
createError
Shortcut for creating a simple error message. -
createError
Shortcut for creating a simple error message, with theThrowable
specified. -
createInfo
Shortcut for creating a simple information message. -
createWarning
Shortcut for creating a simple warning message. -
formatMessage
Formats this message for the specified locale. -
getInternalId
Returns a specific identifier for logging and technical auditing. Returnsnull
if this message has no identifier (this is the case for aUserMessageString
). -
isError
public boolean isError()Returnstrue
if this message is an error. -
isFatal
public boolean isFatal()Returnstrue
if this message is a fatal error. -
isInfo
public boolean isInfo()Returnstrue
if this message is an information message. -
isWarning
public boolean isWarning()Returnstrue
if this message is a warning. -
getSeverity
- See Also:
-
setSeverity
Sets the severity of this message.Default severity is
Severity.INFO
. -
setSeverity
Sets the severity using the specified severity label.- See Also:
-
getThrowable
Returns theThrowable
which is associated to this message, ornull
if none exists.
-