Class PropertyManager

java.lang.Object
com.jalios.jcms.property.PropertyManager
All Implemented Interfaces:
PluginComponent, ReplicaMessageListener

public class PropertyManager extends Object implements ReplicaMessageListener
This class is a singleton to manage properties.
Since:
jcms-10.0.5
Author:
Olivier Dedieu
  • Method Details

    • getInstance

      public static PropertyManager getInstance()
    • prepare

      public void prepare(Channel channel, String customPropFilePath, String webappPropFilePath)
    • getJcmsLanguageList

      public ArrayList<String> getJcmsLanguageList()
    • reloadLanguageProperties

      public void reloadLanguageProperties() throws IOException
      Reload languages properties of JCMS (WEB-INF/jalios/languages/{lang}.prop) and its plugin.
      Throws:
      IOException - If an error occurs
    • reloadLanguageProperties

      public void reloadLanguageProperties(LangProperties properties) throws IOException
      Reload languages properties of JCMS (WEB-INF/jalios/languages/{lang}.prop) in the specified LangProperties instance
      Parameters:
      properties - the LangProperties instance in which language properties are to be loaded
      Throws:
      IOException - If an error occurs
      Since:
      jcms-10.0.3 - JCMS-6890
    • reloadProperties

      public void reloadProperties()
      Reload all properties and notify all JPropertiesListener.
      Since:
      jcms-9.0.0
    • loadProperties

      public void loadProperties() throws IOException
      FOR INTERNAL USE ONLY. Use reloadProperties()

      This method must only be used during Channel instanciation.
      It reload properties from scratch, but does not invoke any JPropertiesListener, thus using it after channel startup would not correctly initialize some manager.

      Throws:
      IOException - if file could not be read
    • getCustomPropFilePath

      public String getCustomPropFilePath()
      Returns the file path of the custom.prop file.
      Returns:
      the file path of the custom.prop file.
      Since:
      jcms-10.0.0
    • updateAndSaveProperties

      public void updateAndSaveProperties(JProperties prop)
      Updates and save specified properties.
      Parameters:
      prop - the properties to be updated/saved.
      See Also:
    • updateAndSaveProperties

      public void updateAndSaveProperties(JProperties prop, boolean notifyListener)
      Updates and saves specified properties.
      Parameters:
      prop - the properties to be updated/saved.
      notifyListener - if true notify the JPropertyListeners
      Since:
      JCMS-9.0.0
      See Also:
    • updateAndSaveProperties

      public void updateAndSaveProperties(JProperties props, boolean notifyListener, boolean sync)
      Updates and saves specified properties.
      Parameters:
      props - the properties to be updated/saved.
      notifyListener - if true notify the JPropertyListeners
      sync - if true sync this properties with the other replicas
      Since:
      JCMS-10.0.5
      See Also:
    • containsProperty

      public boolean containsProperty(String name)
      Tests if this JProperties contains the given property key/name.
      Parameters:
      name - the key/name of the property to check
      Returns:
      true if the specified object is a key in this hashtable; false otherwise.
      See Also:
    • getProperty

      public String getProperty(String name)
      Gets value of a property.
      Parameters:
      name - the key/name of the property to retrieve
      Returns:
      the property value
      See Also:
    • getProperty

      public String getProperty(String name, String defaultValue)
      Gets the value of a property given its key/name.
      Parameters:
      name - the key/name of the property to retrieve
      defaultValue - the default value to use if the existing value is null.
      Returns:
      the value of a property given its key/name.
      See Also:
    • getBooleanProperty

      public boolean getBooleanProperty(String name, boolean defaultValue)
      Gets the value of a property as a boolean given its key/name.
      Parameters:
      name - the key/name of the property to retrieve
      defaultValue - the default value to use if the existing value is null or is neither "false" nor "true" (case sensitive).
      Returns:
      the boolean value of the property
      See Also:
    • getIntegerProperty

      public int getIntegerProperty(String name, int defaultValue)
      Gets the value of a property as an int value given its key/name.
      Parameters:
      name - the key/name of the property to retrieve
      defaultValue - the default value to use if the existing value is null or if Integer.parseInt() throws exception during String to int conversion.
      Returns:
      the int value of the property
      See Also:
    • getLongProperty

      public long getLongProperty(String name, long defaultValue)
      Gets the value of a property as a long value given its key/name.
      Parameters:
      name - the key/name of the property to retrieve
      defaultValue - the default value to use if the existing value is null or if Long.parseLong() throws exception during String to long conversion.
      Returns:
      the long value of the property
      See Also:
    • getFloatProperty

      public float getFloatProperty(String name, float defaultValue)
      Gets the value of a property as a float value given its key/name.
      Parameters:
      name - the key/name of the property to retrieve
      defaultValue - the default value to use if the existing value is null or if Float.parseFloat() throws exception during String to float conversion.
      Returns:
      the float value of the property
      See Also:
    • getDoubleProperty

      public double getDoubleProperty(String name, double defaultValue)
      Gets the value of a property as a double value given its key/name.
      Parameters:
      name - the key/name of the property to retrieve
      defaultValue - the default value to use if the existing value is null or if Double.parseDouble() throws exception during String to double conversion.
      Returns:
      the double value of the property
      See Also:
    • getStringArrayProperty

      public String[] getStringArrayProperty(String name, String[] defaultValue)
      Gets the value of a property as a String array.

      The property value must be in one of the following forms:

      • "@{delim}value1{delim}value2...", where {delim} is one character delimiter of your choice.
      • "value1{delim}value2{delim}...", where {delim} is a character from \t\n\r\f.
      For example :
         String[] array = prop.getStringArrayProperty("missingexample", new String[] { "default", "value"});
         assertEquals(2, array.length);
         assertEquals("default", array[0]);
         assertEquals("value", array[1]);
         
         prop.setProperty("example1", "@|abc|def");
         String[] array1 = prop.getStringArrayProperty("example1", new String[] { });
         assertEquals(2, array1.length);
         assertEquals("abc", array1[0]);
         assertEquals("def", array1[1]);
        
         prop.setProperty("example2", "foo bar\tzig");
         String[] array2 = prop.getStringArrayProperty("example2", new String[] { });
         assertEquals(3, array2.length);
         assertEquals("foo", array2[0]);
         assertEquals("bar", array2[1]);
         assertEquals("zig", array2[2]);
       
      Parameters:
      name - the key/name of the property to retrieve
      defaultValue - the default value to use if the existing value is null or no values could be found in the conversion.
      Returns:
      a String array
      See Also:
    • getIntArrayProperty

      public int[] getIntArrayProperty(String name, int[] defaultValue)
      Gets the value of a property as a int array. Uses same format of getStringArrayProperty(String, String[]).
      Parameters:
      name - the key/name of the property to retrieve
      defaultValue - the default value to use if the existing value is null or no values could be found in the conversion.
      Returns:
      an int array
      See Also:
    • getChannelProperties

      public JProperties getChannelProperties()
      Returns the internal properties used by channel.
      As of version 5.5 those properties are the same as getLanguageProperties() but may differ in a future revision. Do not change any JCMS property at runtime, behaviour of JCMS maybe incorrect if you do so, use the user interface for such task. However you can modify any of your own properties.
      Returns:
      the internal LangProperties of this channel.
    • getLanguageProperties

      public LangProperties getLanguageProperties()
      Gets the internal language properties used by channel.
      As of version 5.5 those properties are the same as getChannelProperties() but may differ in a future revision. Do not change any JCMS property at runtime, behaviour of JCMS maybe incorrect if you do so, use the user interface for such task. However you can modify any of your own properties.
      Returns:
      the internal LangProperties of this channel.
      Since:
      jcms-5.5.0
    • getProperties

      public LangProperties getProperties(String prefix)
      Gets a new LangProperties instance containg all the properties whose name starts with the given prefix.
      Parameters:
      prefix - the prefix
      Returns:
      a new instance of LangProperties containing found properties
      See Also:
    • getSortedProperties

      public Map<String,String> getSortedProperties(String prefix)
      Returns a Map containing all the properties whose name starts with the given prefix sorted by key.
      Parameters:
      prefix - the prefix
      Returns:
      a new instance of Map containing found properties sorted by key
      See Also:
    • getSortedProperties

      public Map<String,String> getSortedProperties(String prefix, boolean trim)
      Returns a Map containing all the properties whose name starts with the given prefix sorted by key. If boolean trim is set to true then remove prefix from key before sorting.
      Parameters:
      prefix - the prefix
      trim - boolean true to remove prefix from key
      Returns:
      a new instance of Map containing found properties with truncated key
      See Also:
    • getSubProperties

      public Map<String,Object> getSubProperties(String prefix)
      Parameters:
      prefix - the prefix
      Returns:
      a map with string as the key and either String or JProperties as the value.
      See Also:
    • setProperty

      public void setProperty(String name, String value)
      Modify an internal property with the given value.
      Do not change any JCMS property at runtime, behaviour of JCMS maybe incorrect if you do so, use the user interface for such task. However you can modify any of your own properties.
      Parameters:
      name - the name/key of the property to change
      value - the new value of this propert
      See Also:
    • addPropertiesListener

      public void addPropertiesListener(JPropertiesListener listener)
      Adds a properties listener.
      Parameters:
      listener - the properties listener
      Since:
      jcms-6.0.0
    • removePropertiesListener

      public void removePropertiesListener(JPropertiesListener listener)
      Removes a properties listener.
      Parameters:
      listener - the properties listener
      Since:
      jcms-6.0.0
    • initReplicaMessageListener

      public void initReplicaMessageListener()
    • processMessage

      public void processMessage(ReplicaMessage msg)
      Description copied from interface: ReplicaMessageListener
      Process the given ReplicaMessage.
      Specified by:
      processMessage in interface ReplicaMessageListener
      Parameters:
      msg - the ReplicaMessage to process