Class JKMessage

java.lang.Object
com.jk.core.locale.JKMessage

public class JKMessage extends Object
This class provides methods needed to interact and get the labels and their properties of the JKMessage objects.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Represents The default path of the labels properties file.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    This method constructs a new JKMessage with default configurations.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addLables(JKLocale locale, String fileName)
    This method adds labels according to the locale specified and the file name provided.
    void
    addLables(JKLocale locale, Properties lables)
    This method adds the labels using the provided locale and properties.
    void
    addLables(Properties readPropertiesFile)
    This method adds the labels using the default locale as well as the provided properties.
    void
    This method clears the labels map, the map will be empty after this call.
    This method fixes the label value to a custom format.
    static String
    get(String key, Object... params)
    This method retrieves a localized label by its key, with optional parameter formatting.
    static JKMessage
    This method gets the instance of JKMessage.
    getLabel(JKLocale locale, String key, Object... params)
    This method retrieves a localized label or message by its key, with optional parameter formatting.
    getLabel(String caption, boolean captizliseFirstLetter)
    This method returns the label associated with the provided caption, and edit it by capitalizing the first letter of the label if needed.
    getLabel(String key, Object... params)
    This method gets the label associated with the provided key.
    This method gets the label property value that is linked with the specified locale in the labels map.
    protected void
    This method loads up the default configuration to the JKMessage objects.
    protected void
    setProperty(JKLocale locale, String propName, String value)
    This method replaces the value linked with the specified properties key in the labels map to the provided value, while considering the provided locale.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_LABLES_FILE_NAME

      public static final String DEFAULT_LABLES_FILE_NAME
      Represents The default path of the labels properties file.
      See Also:
  • Constructor Details

    • JKMessage

      protected JKMessage()
      This method constructs a new JKMessage with default configurations.
      See Also:
  • Method Details

    • loadDefaultConfigurations

      protected void loadDefaultConfigurations()
      This method loads up the default configuration to the JKMessage objects.
    • addLables

      public void addLables(Properties readPropertiesFile)
      This method adds the labels using the default locale as well as the provided properties.
      Parameters:
      readPropertiesFile - Specifies the labels properties.
    • getInstance

      public static JKMessage getInstance()
      This method gets the instance of JKMessage.
      Returns:
      the instance of JKMessage.
    • get

      public static String get(String key, Object... params)
      This method retrieves a localized label by its key, with optional parameter formatting.
      Parameters:
      key - Specifies the unique identifier for the localized label.
      params - Specifies the optional parameters used for formatting the label.
      Returns:
      the localized label as a formatted string.
    • addLables

      public void addLables(JKLocale locale, Properties lables)
      This method adds the labels using the provided locale and properties.
      Parameters:
      locale - Specifies the labels locale.
      lables - Specifies the labels properties.
    • setProperty

      protected void setProperty(JKLocale locale, String propName, String value)
      This method replaces the value linked with the specified properties key in the labels map to the provided value, while considering the provided locale.
      Parameters:
      locale - Specifies the label locale.
      propName - Specifies the property to change key.
      value - Specifies the new value of the property.
    • getLables

      public Properties getLables(JKLocale locale)
      This method gets the label property value that is linked with the specified locale in the labels map.
      Parameters:
      locale - Specifies the label locale whose property is requested.
      Returns:
      the label property.
    • fixValue

      public String fixValue(String value)
      This method fixes the label value to a custom format.
      Parameters:
      value - Specifies the current label value.
      Returns:
      the new value after fixing.
    • clear

      public void clear()
      This method clears the labels map, the map will be empty after this call.
      See Also:
    • getLabel

      public String getLabel(String caption, boolean captizliseFirstLetter)
      This method returns the label associated with the provided caption, and edit it by capitalizing the first letter of the label if needed.
      Parameters:
      caption - Specifies the label key in the labels map.
      captizliseFirstLetter - Specifies whether to capitalize the first letter of the label or not.
      Returns:
      the requested label.
    • getLabel

      public String getLabel(String key, Object... params)
      This method gets the label associated with the provided key.
      Parameters:
      key - Specifies the key associated with the label to get.
      params - Specifies optional parameters used for formatting the label.
      Returns:
      the label associated with the provided key.
    • getLabel

      public String getLabel(JKLocale locale, String key, Object... params)
      This method retrieves a localized label or message by its key, with optional parameter formatting.
      Parameters:
      locale - Specifies the label locale.
      key - Specifies the key associated with the label.
      params - Specifies optional parameters used for formating the label.
      Returns:
      the localized label as a formatted string or empty
    • addLables

      public void addLables(JKLocale locale, String fileName)
      This method adds labels according to the locale specified and the file name provided.
      Parameters:
      locale - Specifies the label locale.
      fileName - Specifies the file name for the label properties file.