Package com.jalios.jcms.property
Class PropertyManager
java.lang.Object
com.jalios.jcms.property.PropertyManager
- All Implemented Interfaces:
PluginComponent,ReplicaMessageListener
This class is a singleton to manage properties.
- Since:
- jcms-10.0.5
- Author:
- Olivier Dedieu
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPropertiesListener(JPropertiesListener listener) Adds a properties listener.booleancontainsProperty(String name) Tests if this JProperties contains the given property key/name.booleangetBooleanProperty(String name, boolean defaultValue) Gets the value of a property as a boolean given its key/name.Returns the internal properties used by channel.Returns the file path of the custom.prop file.doublegetDoubleProperty(String name, double defaultValue) Gets the value of a property as a double value given its key/name.floatgetFloatProperty(String name, float defaultValue) Gets the value of a property as a float value given its key/name.static PropertyManagerint[]getIntArrayProperty(String name, int[] defaultValue) Gets the value of a property as a int array.intgetIntegerProperty(String name, int defaultValue) Gets the value of a property as an int value given its key/name.Gets the internal language properties used by channel.
As of version 5.5 those properties are the same asgetChannelProperties()but may differ in a future revision.longgetLongProperty(String name, long defaultValue) Gets the value of a property as a long value given its key/name.getProperties(String prefix) Gets a new LangProperties instance containg all the properties whose name starts with the given prefix.getProperty(String name) Gets value of a property.getProperty(String name, String defaultValue) Gets the value of a property given its key/name.getSortedProperties(String prefix) Returns a Map containing all the properties whose name starts with the given prefix sorted by key.getSortedProperties(String prefix, boolean trim) Returns a Map containing all the properties whose name starts with the given prefix sorted by key.String[]getStringArrayProperty(String name, String[] defaultValue) Gets the value of a property as a String array.getSubProperties(String prefix) voidvoidFOR INTERNAL USE ONLY.voidvoidProcess the given ReplicaMessage.voidReload languages properties of JCMS (WEB-INF/jalios/languages/{lang}.prop) and its plugin.voidreloadLanguageProperties(LangProperties properties) Reload languages properties of JCMS (WEB-INF/jalios/languages/{lang}.prop) in the specified LangProperties instancevoidReload all properties and notify all JPropertiesListener.voidremovePropertiesListener(JPropertiesListener listener) Removes a properties listener.voidsetProperty(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.voidUpdates and save specified properties.voidupdateAndSaveProperties(JProperties prop, boolean notifyListener) Updates and saves specified properties.voidupdateAndSaveProperties(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, waitMethods inherited from interface com.jalios.jcms.plugin.PluginComponent
init
-
Method Details
-
getInstance
-
prepare
-
getJcmsLanguageList
-
reloadLanguageProperties
Reload languages properties of JCMS (WEB-INF/jalios/languages/{lang}.prop) and its plugin.- Throws:
IOException- If an error occurs
-
reloadLanguageProperties
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
FOR INTERNAL USE ONLY. UsereloadProperties()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
Returns the file path of the custom.prop file.- Returns:
- the file path of the custom.prop file.
- Since:
- jcms-10.0.0
-
updateAndSaveProperties
Updates and save specified properties.- Parameters:
prop- the properties to be updated/saved.- See Also:
-
updateAndSaveProperties
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
Updates and saves specified properties.- Parameters:
props- the properties to be updated/saved.notifyListener- if true notify the JPropertyListenerssync- if true sync this properties with the other replicas- Since:
- JCMS-10.0.5
- See Also:
-
containsProperty
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
Gets value of a property.- Parameters:
name- the key/name of the property to retrieve- Returns:
- the property value
- See Also:
-
getProperty
Gets the value of a property given its key/name.- Parameters:
name- the key/name of the property to retrievedefaultValue- the default value to use if the existing value is null.- Returns:
- the value of a property given its key/name.
- See Also:
-
getBooleanProperty
Gets the value of a property as a boolean given its key/name.- Parameters:
name- the key/name of the property to retrievedefaultValue- 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
Gets the value of a property as an int value given its key/name.- Parameters:
name- the key/name of the property to retrievedefaultValue- 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
Gets the value of a property as a long value given its key/name.- Parameters:
name- the key/name of the property to retrievedefaultValue- 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
Gets the value of a property as a float value given its key/name.- Parameters:
name- the key/name of the property to retrievedefaultValue- 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
Gets the value of a property as a double value given its key/name.- Parameters:
name- the key/name of the property to retrievedefaultValue- 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
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.
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 retrievedefaultValue- 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:
- "@{delim}value1{delim}value2...", where
-
getIntArrayProperty
Gets the value of a property as a int array. Uses same format ofgetStringArrayProperty(String, String[]).- Parameters:
name- the key/name of the property to retrievedefaultValue- 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
Returns the internal properties used by channel.
As of version 5.5 those properties are the same asgetLanguageProperties()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
Gets the internal language properties used by channel.
As of version 5.5 those properties are the same asgetChannelProperties()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
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
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
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 prefixtrim- boolean true to remove prefix from key- Returns:
- a new instance of Map containing found properties with truncated key
- See Also:
-
getSubProperties
- Parameters:
prefix- the prefix- Returns:
- a map with string as the key and either String or JProperties as the value.
- See Also:
-
setProperty
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 changevalue- the new value of this propert- See Also:
-
addPropertiesListener
Adds a properties listener.- Parameters:
listener- the properties listener- Since:
- jcms-6.0.0
-
removePropertiesListener
Removes a properties listener.- Parameters:
listener- the properties listener- Since:
- jcms-6.0.0
-
initReplicaMessageListener
public void initReplicaMessageListener() -
processMessage
Description copied from interface:ReplicaMessageListenerProcess the given ReplicaMessage.- Specified by:
processMessagein interfaceReplicaMessageListener- Parameters:
msg- the ReplicaMessage to process
-