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 closest Locale 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 Details

    • 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 the Throwable 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 the Throwable 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. Returns null if this message has no identifier (this is the case for a UserMessageString).
    • isError

      public boolean isError()
      Returns true if this message is an error.
    • isFatal

      public boolean isFatal()
      Returns true if this message is a fatal error.
    • isInfo

      public boolean isInfo()
      Returns true if this message is an information message.
    • isWarning

      public boolean isWarning()
      Returns true if this message is a warning.
    • getSeverity

      public Severity getSeverity()
      See Also:
    • 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:
    • getThrowable

      public Throwable getThrowable()
      Returns the Throwable which is associated to this message, or null if none exists.