Class MessageService

java.lang.Object
com.luchersol.core.util.MessageService

public class MessageService extends Object
Message provides utility methods for retrieving and formatting localized messages from a properties file. It supports colored output using Jansi and handles missing format arguments gracefully.
  • Method Details

    • getProperty

      public static String getProperty(String key)
      Retrieves the message text for the given key using the default locale.

      If the key is not found in the resource bundle, a default colored warning message is returned.

      Parameters:
      key - the key of the message to retrieve
      Returns:
      the message string for the given key, or a default colored message if not found
    • getProperty

      public static String getProperty(String key, Locale locale)
      Retrieves the message text for the given key using the specified locale.

      If the key is not found in the resource bundle for the given locale, a default colored warning message is returned.

      Parameters:
      key - the key of the message to retrieve
      locale - the locale to use for message retrieval
      Returns:
      the message string for the given key and locale, or a default colored message if not found
    • sendMessage

      public static Message sendMessage(String init, String function)
      Sends a formatted message for the given initial key and function, with no arguments.
      Parameters:
      init - the initial part of the message key
      function - the function or message type
      Returns:
      the formatted message string
    • sendMessage

      public static Message sendMessage(String init, String function, Object... args)
      Sends a formatted message for the given initial key, function, and arguments. Handles missing format arguments gracefully with a colored error message.
      Parameters:
      init - the initial part of the message key
      function - the function or message type
      args - the arguments to format the message
      Returns:
      the formatted message string, or a colored error message if formatting fails