Class PropertyManager

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPropertiesListener​(JPropertiesListener listener)
      Adds a properties listener.
      boolean containsProperty​(java.lang.String name)
      Tests if this JProperties contains the given property key/name.
      boolean getBooleanProperty​(java.lang.String name, boolean defaultValue)
      Gets the value of a property as a boolean given its key/name.
      JProperties getChannelProperties()
      Returns the internal properties used by channel.
      java.lang.String getCustomPropFilePath()
      Returns the file path of the custom.prop file.
      double getDoubleProperty​(java.lang.String name, double defaultValue)
      Gets the value of a property as a double value given its key/name.
      float getFloatProperty​(java.lang.String name, float defaultValue)
      Gets the value of a property as a float value given its key/name.
      static PropertyManager getInstance()  
      int[] getIntArrayProperty​(java.lang.String name, int[] defaultValue)
      Gets the value of a property as a int array.
      int getIntegerProperty​(java.lang.String name, int defaultValue)
      Gets the value of a property as an int value given its key/name.
      java.util.List<java.lang.String> getJcmsLanguageList()
      Retrieves all the languages in which JCMS is localized.
      java.util.List<java.lang.String> getLanguageList()
      Retrieve all the languages of this channel with the main language as the first one of the list.
      java.util.List<java.lang.String> getLanguageListOrdered()
      Retrieve all the languages of this channel in the exact ordered in which they were specified in the properties.
      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.
      java.util.List<java.lang.String> getLocalizedLanguageList()
      Retrieves all the languages specified in the properties in which JCMS is localized.
      long getLongProperty​(java.lang.String name, long defaultValue)
      Gets the value of a property as a long value given its key/name.
      java.util.List<java.lang.String> getOtherLanguageList()
      Retrieve all the languages of this channel excepted the main language.
      LangProperties getProperties​(java.lang.String prefix)
      Gets a new LangProperties instance containg all the properties whose name starts with the given prefix.
      java.lang.String getProperty​(java.lang.String name)
      Gets value of a property.
      java.lang.String getProperty​(java.lang.String name, java.lang.String defaultValue)
      Gets the value of a property given its key/name.
      java.util.Map<java.lang.String,​java.lang.String> getSortedProperties​(java.lang.String prefix)
      Returns a Map containing all the properties whose name starts with the given prefix sorted by key.
      java.util.Map<java.lang.String,​java.lang.String> getSortedProperties​(java.lang.String prefix, boolean trim)
      Returns a Map containing all the properties whose name starts with the given prefix sorted by key.
      java.lang.String[] getStringArrayProperty​(java.lang.String name, java.lang.String[] defaultValue)
      Gets the value of a property as a String array.
      java.util.Map<java.lang.String,​java.lang.Object> getSubProperties​(java.lang.String prefix)  
      void initReplicaMessageListener()  
      void loadProperties()  
      void prepare​(Channel channel, java.lang.String customPropFilePath, java.lang.String webappPropFilePath)  
      void processMessage​(ReplicaMessage msg)
      Process the given ReplicaMessage.
      void reloadLanguageProperties()
      Reload languages properties of JCMS (WEB-INF/jalios/languages/{lang}.prop) and its plugin.
      void reloadLanguageProperties​(LangProperties properties)
      Reload languages properties of JCMS (WEB-INF/jalios/languages/{lang}.prop) in the specified LangProperties instance
      void reloadProperties()
      Reload all properties and notify all JPropertiesListener.
      void removePropertiesListener​(JPropertiesListener listener)
      Removes a properties listener.
      void resetLanguageList()  
      void setProperty​(java.lang.String name, java.lang.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.
      void updateAndSaveProperties​(JProperties prop)
      Updates and save specified properties.
      void updateAndSaveProperties​(JProperties prop, boolean notifyListener)
      Updates and saves specified properties.
      void updateAndSaveProperties​(JProperties props, boolean notifyListener, boolean sync)
      Updates and saves specified properties.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • prepare

        public void prepare​(Channel channel,
                            java.lang.String customPropFilePath,
                            java.lang.String webappPropFilePath)
      • reloadLanguageProperties

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

        public void reloadLanguageProperties​(LangProperties properties)
                                      throws java.io.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:
        java.io.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 java.io.IOException
        Throws:
        java.io.IOException
      • getCustomPropFilePath

        public java.lang.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,
                                            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:
        JProperties.updateAndSave(java.io.File)
      • 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:
        JProperties.updateAndSave(java.io.File)
      • containsProperty

        public boolean containsProperty​(java.lang.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:
        JProperties.containsProperty(java.lang.String)
      • getProperty

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

        public java.lang.String getProperty​(java.lang.String name,
                                            java.lang.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:
        JProperties.getProperty(java.lang.String, java.lang.String)
      • getBooleanProperty

        public boolean getBooleanProperty​(java.lang.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:
        JProperties.getBooleanProperty(java.lang.String, boolean)
      • getIntegerProperty

        public int getIntegerProperty​(java.lang.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:
        JProperties.getIntegerProperty(java.lang.String, int)
      • getLongProperty

        public long getLongProperty​(java.lang.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:
        JProperties.getLongProperty(java.lang.String, long)
      • getFloatProperty

        public float getFloatProperty​(java.lang.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:
        JProperties.getFloatProperty(java.lang.String, float)
      • getDoubleProperty

        public double getDoubleProperty​(java.lang.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:
        JProperties.getDoubleProperty(java.lang.String, double)
      • getStringArrayProperty

        public java.lang.String[] getStringArrayProperty​(java.lang.String name,
                                                         java.lang.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:
        JProperties.getStringArrayProperty(java.lang.String,java.lang.String[])
      • getIntArrayProperty

        public int[] getIntArrayProperty​(java.lang.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:
        JProperties.getIntArrayProperty(java.lang.String,int[])
      • 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​(java.lang.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:
        LangProperties.getProperties(java.lang.String)
      • getSortedProperties

        public java.util.Map<java.lang.String,​java.lang.String> getSortedProperties​(java.lang.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:
        LangProperties.getProperties(java.lang.String)
      • getSortedProperties

        public java.util.Map<java.lang.String,​java.lang.String> getSortedProperties​(java.lang.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:
        getSortedProperties(java.lang.String)
      • getSubProperties

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

        public void setProperty​(java.lang.String name,
                                java.lang.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:
        JProperties.setProperty(String, String)
      • 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
      • getLanguageList

        public java.util.List<java.lang.String> getLanguageList()
        Retrieve all the languages of this channel with the main language as the first one of the list.
        Returns:
        all the ISO-639 language code available for this channel, as defined with "channel.languages" property, the default language will be first in the list.
        Since:
        jcms-4.0
      • getLanguageListOrdered

        public java.util.List<java.lang.String> getLanguageListOrdered()
        Retrieve all the languages of this channel in the exact ordered in which they were specified in the properties.
        Returns:
        all the ISO-639 language code available for this channel, as defined with "channel.languages" property, the list will keep order in which they are specified in the property.
        Since:
        jcms-5.5.0
      • getOtherLanguageList

        public java.util.List<java.lang.String> getOtherLanguageList()
        Retrieve all the languages of this channel excepted the main language.
        Returns:
        all ISO-639 language code of this channel, minus the default language (i.e. getLanguageList() - getLanguage())
        Since:
        jcms-4.0
      • getLocalizedLanguageList

        public java.util.List<java.lang.String> getLocalizedLanguageList()
        Retrieves all the languages specified in the properties in which JCMS is localized.
        Returns:
        a List of ISO-639 language code.
      • getJcmsLanguageList

        public java.util.List<java.lang.String> getJcmsLanguageList()
        Retrieves all the languages in which JCMS is localized.
        Returns:
        a List of ISO-639 language code.
      • resetLanguageList

        public void resetLanguageList()
      • initReplicaMessageListener

        public void initReplicaMessageListener()