Class PropertyFileUtil

java.lang.Object
jp.ecuacion.lib.core.util.PropertyFileUtil

public class PropertyFileUtil extends Object
Provides utility methods to read *.properties files.

It has following functions added to ResourceBundle class packaged in JRE.

  1. To read all the ".properties" files in library modules and multiple modules in app projects
  2. To read multiple kinds of ".properties" (application, messages, enum_name, field_name)
  3. To use "default" message by putting the postfix of the message ID ".default"
  4. To Have the override function by java launch parameter (-D) or System.setProperty(...)
  5. To Have the default locale setting function by .properties file (application_for_property-file-util_base.properties)

1. To read all the ".properties" files in library modules and multiple modules in app projects

If we talk about messages[_xxx].properties, this class reads ones in ecuacion libraries, and ones in your apps.
In ecuacion libraries an app is assumed to devided to some modules (=usually called "projects" in IDE), which are base, core, web (or none), batch.

If the name of your app is sample-app, module names would be :
sample-app-base : messages_base.properties
sample-app-core : messages_core.properties
sample-app-web : messages.properties
sample-app-batch: messages.properties

PropertyFileUtil.getMsg(...) will read all the messages properties above.
Duplicated definition detectable. (causes throwing exception)

And of course you can use localized files like messages_core_ja.properties because This class uses ResourceBundle inside to read properties files.


2. To read multiple kinds of ".properties" (application, messages, enum_name, field_name)

PropertyFileUtil.getMsg(...) : messages[_xxx].properties}
PropertyFileUtil.getApp(...) : application[_xxx].properties}
PropertyFileUtil.getEnumName(...) : enum_names[_xxx].properties}
PropertyFileUtil.getFieldName(...) : fiels_names[_xxx].properties}

kinds of property files
kind data the file has
application system settings
messages messages
field_names names of the fields of items
enum_names names of the elements of enums

3. To use "default" message by putting the postfix of the message ID ".default"

4. To Have the override function by java launch parameter (-D) or System.setProperty(...)

5. To Have the default locale setting function by .properties file (application_for_property-file-util_base.properties)

Miscellaneous

messages[_xxx].properties, enum_names[_xxx].properties, fiels_names[_xxx].properties need to have default locale file (like messages.properties. This is the rule of the library.
It leads the conclusion that hasXxx(...) (like hasMsg(...)) doesn't need to have locale argument. (default locale used)

  • Method Details

    • getApp

      @Nonnull public static String getApp(@Nonnull String key)
      Returns the value in application_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      key - the key of the property
      Returns:
      the value of the property
    • hasApp

      public static boolean hasApp(@Nonnull String key)
      Returns the existence of the key in application_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      key - the key of the property
      Returns:
      boolean value that shows whether properties has the key
    • getMsg

      @Nonnull public static String getMsg(@Nonnull String key)
      Returns the value in application_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      key - the key of the property
      Returns:
      the message corresponding to the message ID
    • getMsg

      @Nonnull public static String getMsg(@Nullable Locale locale, @Nonnull String key)
      Returns the value in application_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      locale - locale, may be null which is treated as Locale.getDefault().
      key - the key of the property
      Returns:
      the message corresponding to the message ID
    • getMsg

      @Nonnull public static String getMsg(@Nonnull String key, @Nullable String... args)
      Returns the value in application_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      key - the key of the property
      args - message arguments, may be null which is treated as new String[] {}.
      Returns:
      the message corresponding to the message ID
    • getMsg

      @Nonnull public static String getMsg(@Nullable Locale locale, @Nonnull String key, @Nullable String... args)
      Returns the value in messages_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      locale - locale, may be null which is treated as Locale.getDefault().
      key - the key of the property
      args - message arguments, may be null which is treated as new String[] {}.
      Returns:
      the message corresponding to the message ID
    • hasMsg

      public static boolean hasMsg(@Nonnull String msgId)
      Returns the existence of the key in field_names_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      msgId - message ID
      Returns:
      boolean value that shows whether properties has the message ID
    • getFieldName

      @Nonnull public static String getFieldName(@Nonnull String key)
      Returns the field name of default locale in field_names_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      key - the key of the property
      Returns:
      the value of the property
    • getFieldName

      @Nonnull public static String getFieldName(@Nullable Locale locale, @Nonnull String key)
      Returns the localized field name in field_names_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      locale - locale, may be null which is treated as Locale.getDefault().
      key - the key of the property
      Returns:
      the value of the property
    • hasFieldName

      public static boolean hasFieldName(@Nonnull String key)
      Returns the existence of the key in field_names_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      key - the key of the property
      Returns:
      boolean value that shows whether properties has the key
    • getEnumName

      @Nonnull public static String getEnumName(@Nonnull String key)
      Returns the enum name of default locale in enum_names_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      key - the key of the property
      Returns:
      the value of the property
    • getEnumName

      @Nonnull public static String getEnumName(@Nullable Locale locale, @Nonnull String key)
      Returns the localized enum name in enum_names_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      locale - locale, may be null which is treated as Locale.getDefault().
      key - the key of the property
      Returns:
      the value of the property
    • hasEnumName

      public static boolean hasEnumName(@Nonnull String key)
      Returns the existence of the key in enam_names_xxx.properties.

      Names should exist but some function uses this to show message ID when the key does not exist in the file.

      Parameters:
      key - the key of the property
      Returns:
      boolean value that shows whether properties has the key