Class AppPropertiesService

java.lang.Object
fr.paris.lutece.portal.service.util.AppPropertiesService

public final class AppPropertiesService extends Object
this class provides management services for properties files
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<String>
    getKeys(String strPrefix)
    Returns a list of keys that match a given prefix.
    <T> Optional<T>
    getOptionalValue(String name, Class<T> aClass)
    Return the resolved property value with the specified type for the specified property name from the underlying configuration sources.
    static Properties
    Gets properties
    static Map<String,String>
    Gets all properties as a Map
    static String
    getProperty(String strProperty)
    Returns the value of a variable defined in the .properties file of the application as a String
    static String
    getProperty(String strProperty, String strDefault)
    Returns the value of a variable defined in the .properties file of the application as a String
    static boolean
    getPropertyBoolean(String strProperty, boolean bDefault)
    Returns the value of a variable defined in the .properties file of the application as a boolean
    static int
    getPropertyInt(String strProperty, int nDefault)
    Returns the value of a variable defined in the .properties file of the application as an int
    static long
    getPropertyLong(String strProperty, long lDefault)
    Returns the value of a variable defined in the .properties file of the application as an long
    static void
    init(String strConfPath)
    Initializes the service
    static boolean
    Tells whether a property is declared by one of the configuration sources, whatever its value.
    static void
    reload(String strFilename)
    Deprecated.
    static void
    Deprecated.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • init

      public static void init(String strConfPath)
      Initializes the service
      Parameters:
      strConfPath - The configuration path
    • getProperty

      public static String getProperty(String strProperty)
      Returns the value of a variable defined in the .properties file of the application as a String
      Parameters:
      strProperty - The variable name
      Returns:
      The variable value read in the properties file
    • getProperty

      public static String getProperty(String strProperty, String strDefault)
      Returns the value of a variable defined in the .properties file of the application as a String
      Parameters:
      strProperty - The variable name
      strDefault - The default value which is returned if no value is found for the variable in the .properties file.
      Returns:
      The variable value read in the properties file
    • getPropertyInt

      public static int getPropertyInt(String strProperty, int nDefault)
      Returns the value of a variable defined in the .properties file of the application as an int
      Parameters:
      strProperty - The variable name
      nDefault - The default value which is returned if no value is found for the variable in the le downloadFile .properties. .properties file.
      Returns:
      The variable value read in the properties file
    • getPropertyLong

      public static long getPropertyLong(String strProperty, long lDefault)
      Returns the value of a variable defined in the .properties file of the application as an long
      Parameters:
      strProperty - The variable name
      lDefault - The default value which is returned if no value is found for the variable in the le downloadFile .properties. .properties file.
      Returns:
      The variable value read in the properties file
    • getPropertyBoolean

      public static boolean getPropertyBoolean(String strProperty, boolean bDefault)
      Returns the value of a variable defined in the .properties file of the application as a boolean
      Parameters:
      strProperty - The variable name
      bDefault - The default value which is returned if no value is found for the variable in the le downloadFile .properties. .properties file.
      Returns:
      The variable value read in the properties file
    • getOptionalValue

      public <T> Optional<T> getOptionalValue(String name, Class<T> aClass)
      Return the resolved property value with the specified type for the specified property name from the underlying configuration sources.

      The configuration value is not guaranteed to be cached by the implementation, and may be expensive to compute; therefore, if the returned value is intended to be frequently used, callers should consider storing rather than recomputing it.

      If this method is used very often then consider to locally store the configured value.

      Type Parameters:
      T - The property type
      Parameters:
      propertyName - The configuration property name
      propertyType - The type into which the resolved property value should be converted
      Returns:
      The resolved property value as an Optional wrapping the requested type
      Throws:
      IllegalArgumentException - if the property cannot be converted to the specified type
    • reloadAll

      @Deprecated public static void reloadAll()
      Deprecated.
      Reloads all the properties files
    • reload

      @Deprecated public static void reload(String strFilename)
      Deprecated.
      Reloads a given properties file
      Parameters:
      strFilename - The file name
    • getProperties

      public static Properties getProperties()
      Gets properties
      Returns:
      All properties
      Since:
      version 3.0
    • getPropertiesAsMap

      public static Map<String,String> getPropertiesAsMap()
      Gets all properties as a Map
      Returns:
      a Map of all properties
      Since:
      version 5.0
    • getKeys

      public static List<String> getKeys(String strPrefix)
      Returns a list of keys that match a given prefix.
      Parameters:
      strPrefix - the str prefix
      Returns:
      A list of keys that match the prefix
      Since:
      version 3.0
    • isPropertyDeclared

      public static boolean isPropertyDeclared(String strProperty)
      Tells whether a property is declared by one of the configuration sources, whatever its value. getProperty(String) resolves a property declared with an empty value to null, exactly as it resolves a property that no source declares, so the resolved value alone cannot tell the two apart. The property names known to the configuration do include the keys declared with an empty value, which makes this the only way to distinguish an empty declaration from a missing one.
      Parameters:
      strProperty - the property key
      Returns:
      true if a configuration source declares the key, false otherwise
      Since:
      version 7.1.10