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 closestLocalematch. - A message instance may hold parameters. If this is the case, the display uses a limited
MessageFormatmechanism 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 UserMessageStringcreateError(String message)Shortcut for creating a simple error message.static UserMessageStringcreateError(String message, Throwable anException)Shortcut for creating a simple error message, with theThrowablespecified.static UserMessageStringcreateFatal(String message)Shortcut for creating a simple fatal error message.static UserMessageStringcreateFatal(String message, Throwable anException)Shortcut for creating a simple error message, with theThrowablespecified.static UserMessageStringcreateInfo(String message)Shortcut for creating a simple information message.static UserMessageStringcreateWarning(String message)Shortcut for creating a simple warning message.StringformatMessage(Locale aLocale)Formats this message for the specified locale.abstract StringgetInternalId()Returns a specific identifier for logging and technical auditing.SeveritygetSeverity()ThrowablegetThrowable()Returns theThrowablewhich is associated to this message, ornullif none exists.booleanisError()Returnstrueif this message is an error.booleanisFatal()Returnstrueif this message is a fatal error.booleanisInfo()Returnstrueif this message is an information message.booleanisWarning()Returnstrueif this message is a warning.voidsetSeverity(Severity severity)Sets the severity of this message.voidsetSeverity(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 theThrowablespecified.
-
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 theThrowablespecified.
-
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. Returnsnullif this message has no identifier (this is the case for aUserMessageString).
-
isError
public boolean isError()
Returnstrueif this message is an error.
-
isFatal
public boolean isFatal()
Returnstrueif this message is a fatal error.
-
isInfo
public boolean isInfo()
Returnstrueif this message is an information message.
-
isWarning
public boolean isWarning()
Returnstrueif 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 theThrowablewhich is associated to this message, ornullif none exists.
-
-