Package com.onwbp.base.text
Class UserMessage
- java.lang.Object
-
- com.onwbp.base.text.UserMessage
-
- Direct Known Subclasses:
UserMessageLocalized
,UserMessageRef
,UserMessageString
public abstract class UserMessage extends Object
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:
MessageFormat
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static 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.String
formatMessage(Locale aLocale)
Formats this message for the specified locale.abstract String
getInternalId()
Returns a specific identifier for logging and technical auditing.Severity
getSeverity()
Throwable
getThrowable()
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
isWarning()
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 Detail
-
createFatal
public static UserMessageString createFatal(String message)
Shortcut for creating a simple fatal error message.
-
createFatal
public static UserMessageString createFatal(String message, Throwable anException)
Shortcut for creating a simple error message, with theThrowable
specified.
-
createError
public static UserMessageString createError(String message)
Shortcut for creating a simple error message.
-
createError
public static UserMessageString createError(String message, Throwable anException)
Shortcut for creating a simple error message, with theThrowable
specified.
-
createInfo
public static UserMessageString createInfo(String message)
Shortcut for creating a simple information message.
-
createWarning
public static UserMessageString createWarning(String message)
Shortcut for creating a simple warning message.
-
formatMessage
public String formatMessage(Locale aLocale)
Formats this message for the specified locale.
-
getInternalId
public abstract String 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
public Severity getSeverity()
- See Also:
setSeverity(Severity)
-
setSeverity
public void setSeverity(Severity severity)
Sets the severity of this message.Default severity is
Severity.INFO
.
-
setSeverity
public void setSeverity(String aLabel)
Sets the severity using the specified severity label.- See Also:
Severity.parseLabel(String)
-
getThrowable
public Throwable getThrowable()
Returns theThrowable
which is associated to this message, ornull
if none exists.
-
-