Author: nfilotto
Date: 2011-03-25 07:36:59 -0400 (Fri, 25 Mar 2011)
New Revision: 4175
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/kernel/container-configuration.xml
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/default-settings.properties
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal-container-config-with-default-values-and-with-both-settings-with-default-portal-def.xml
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties
Log:
EXOJCR-1269: Allow to set a default value when we use variables in configuration files.
The syntax ${variable-name:default-value} is now supported.
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/kernel/container-configuration.xml
===================================================================
---
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/kernel/container-configuration.xml 2011-03-25
10:18:03 UTC (rev 4174)
+++
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/kernel/container-configuration.xml 2011-03-25
11:36:59 UTC (rev 4175)
@@ -1720,6 +1720,20 @@
</section>
<section>
+ <title>Variable Syntaxes</title>
+
+ <para>All the variables that we described in the previous chapters can be
+ defined thanks to 2 possible syntaxes which are
+ <emphasis>${variable-name}</emphasis> or
+ <emphasis>${variable-name:default-value}</emphasis>. The first syntax
+ doesn't define any default value so if the variable has not be set the
+ value will be <emphasis>${variable-name}</emphasis> to indicate that it
+ could not be resolved. The second syntax allows you to define the default
+ value after the semi colon so if the variable has not be set the value
+ will be the given default value.</para>
+ </section>
+
+ <section>
<title>Runtime configuration profiles</title>
<para>The kernel configuration is able to handle configuration profiles at
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java 2011-03-25
10:18:03 UTC (rev 4174)
+++
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java 2011-03-25
11:36:59 UTC (rev 4175)
@@ -203,7 +203,7 @@
if (input == null)
return input;
char[] chars = input.toCharArray();
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
boolean properties = false;
int state = NORMAL;
int start = 0;
@@ -230,6 +230,13 @@
{
String value = null;
String key = input.substring(start + 2, i);
+ String defaultValue = null;
+ int index = key.indexOf(':');
+ if (index > -1)
+ {
+ defaultValue = key.substring(index + 1);
+ key = key.substring(0, index);
+ }
if (key.equals(Deserializer.EXO_CONTAINER_PROP_NAME))
{
// The requested key is the name of current container
@@ -269,6 +276,10 @@
value = PrivilegedSystemHelper.getProperty(key);
}
}
+ if (value == null && defaultValue != null)
+ {
+ value = defaultValue;
+ }
if (value != null)
{
properties = true;
Modified:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2011-03-25
10:18:03 UTC (rev 4174)
+++
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2011-03-25
11:36:59 UTC (rev 4175)
@@ -1626,6 +1626,22 @@
assertEquals("-property_value_1-", config.getSetting("foo",
"complex-value9"));
assertEquals("-property_value_1-",
config.getSetting("myPortal", "complex-value9"));
assertEquals("-property_value_1-",
config.getSetting("myPortal-pcdef", "complex-value9"));
+ assertNull(config.getSetting("foo", "complex-value10"));
+ assertNull(config.getSetting("myPortal",
"complex-value10"));
+ assertEquals("--value--",
config.getSetting("myPortal-pcdef", "complex-value10"));
+ assertNull(config.getSetting("foo", "complex-value11"));
+ assertNull(config.getSetting("myPortal",
"complex-value11"));
+ assertEquals("-default-",
config.getSetting("myPortal-pcdef", "complex-value11"));
+ assertEquals("-default-", config.getSetting("foo",
"complex-value12"));
+ assertEquals("-default-", config.getSetting("myPortal",
"complex-value12"));
+ assertEquals("-value-", config.getSetting("myPortal-pcdef",
"complex-value12"));
+ assertEquals("-property_value_1-", config.getSetting("foo",
"complex-value13"));
+ assertEquals("-property_value_1-",
config.getSetting("myPortal", "complex-value13"));
+ assertEquals("-property_value_1-",
config.getSetting("myPortal-pcdef", "complex-value13"));
+ assertEquals("-default-", config.getSetting("foo",
"complex-value14"));
+ assertEquals("-default-", config.getSetting("myPortal",
"complex-value14"));
+ assertEquals("-default-",
config.getSetting("myPortal-pcdef", "complex-value14"));
+
assertEquals("-system value-", config.getSetting("foo",
"cpv1"));
assertEquals("-system value-", config.getSetting("myPortal",
"cpv1"));
assertEquals("-system value-",
config.getSetting("myPortal-pcdef", "cpv1"));
@@ -1635,6 +1651,12 @@
assertEquals("-property_value_1-", config.getSetting("foo",
"cpv3"));
assertEquals("-property_value_1-",
config.getSetting("myPortal", "cpv3"));
assertEquals("-property_value_1-",
config.getSetting("myPortal-pcdef", "cpv3"));
+ assertEquals("-value-", config.getSetting("foo",
"cpv4"));
+ assertEquals("-value-", config.getSetting("myPortal",
"cpv4"));
+ assertEquals("-value-", config.getSetting("myPortal-pcdef",
"cpv4"));
+ assertEquals("-system value-", config.getSetting("foo",
"cpv5"));
+ assertEquals("-system value-", config.getSetting("myPortal",
"cpv5"));
+ assertEquals("-system value-",
config.getSetting("myPortal-pcdef", "cpv5"));
assertEquals("new value0", config.getSetting("foo",
"string"));
assertEquals(new Integer(200), config.getSetting("foo",
"int"));
assertEquals(new Integer(60), config.getSetting("foo",
"int2"));
Modified:
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/default-settings.properties
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/default-settings.properties 2011-03-25
10:18:03 UTC (rev 4174)
+++
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/default-settings.properties 2011-03-25
11:36:59 UTC (rev 4175)
@@ -10,4 +10,7 @@
complex-value3=-${foo3}-
complex-value5=-${foo5}-
complex-value8=-${foo6}-
-complex-value9=-${property_String}-
\ No newline at end of file
+complex-value9=-${property_String}-
+complex-value12=-${foo6:default}-
+complex-value13=-${property_String:default}-
+complex-value14=-${complex-value-unknown:default}-
Modified:
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal-container-config-with-default-values-and-with-both-settings-with-default-portal-def.xml
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal-container-config-with-default-values-and-with-both-settings-with-default-portal-def.xml 2011-03-25
10:18:03 UTC (rev 4174)
+++
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal-container-config-with-default-values-and-with-both-settings-with-default-portal-def.xml 2011-03-25
11:36:59 UTC (rev 4175)
@@ -62,6 +62,22 @@
</entry>
<entry>
<key>
+ <string>cpv4</string>
+ </key>
+ <value>
+ <string>-${property2_String:value}-</string>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <string>cpv5</string>
+ </key>
+ <value>
+ <string>-${TestPortalContainerConfig-string:value}-</string>
+ </value>
+ </entry>
+ <entry>
+ <key>
<string>foo2</string>
</key>
<value>
Modified:
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties 2011-03-25
10:18:03 UTC (rev 4174)
+++
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties 2011-03-25
11:36:59 UTC (rev 4175)
@@ -8,4 +8,6 @@
complex-value=${name}-${rest}-${realm}-${foo2}-${string}
complex-value4=-${foo4}-
complex-value6=-${foo6}-
-complex-value7=-${foo5}-
\ No newline at end of file
+complex-value7=-${foo5}-
+complex-value10=-${complex-value7:default}-
+complex-value11=-${complex-value-unknown:default}-
\ No newline at end of file