Author: nfilotto
Date: 2011-03-03 07:51:45 -0500 (Thu, 03 Mar 2011)
New Revision: 4048
Added:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestImportWithProperties.java
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/import-with-parameter-configuration.xml
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/resources/binding.xml
Log:
EXOJCR-1220: Allow to use variables to define any values in the configuration file
Now we can use variables everywhere in the configuration files
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-03
10:04:47 UTC (rev 4047)
+++
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/kernel/container-configuration.xml 2011-03-03
12:51:45 UTC (rev 4048)
@@ -30,19 +30,37 @@
<title>Kernel configuration namespace</title>
<para>To be effective, the namespace URI
- <
uri>http://www.exoplaform.org/xml/ns/kernel_1_1.xsd</uri> must be
target
+ <
uri>http://www.exoplaform.org/xml/ns/kernel_1_2.xsd</uri> must be
target
namespace of the XML configuration file.</para>
- <programlisting><xsd:schema
-
targetNamespace="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
-
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified"
- attributeFormDefault="unqualified"
- version="1.0">
+ <programlisting><configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_2.xsd
http://www.exoplaform.org/xml/ns/kernel_1_2.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_2.xsd">
+
...
-</xsd:schema></programlisting>
+</configuration></programlisting>
+
+ <note>
+ <para>Any values in the configuration files can be created thanks to
+ variables since the eXo kernel resolves them, for example the following
+ configuration will be well interpreted:</para>
+
+ <programlisting><configuration
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_2.xsd
http://www.exoplaform.org/xml/ns/kernel_1_2.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_2.xsd">
+
+ <import>${db.configuration.path}/db.xml</import>
+ <import>${java.io.tmpdir}/bindfile.xml</import>
+ <import>simple.xml</import>
+
+</configuration></programlisting>
+
+ <para>The variables that are supported, are System properties and
+ variables that are specific to your portal container, see next chapters
+ for more details.</para>
+ </note>
</section>
<section>
Modified: kernel/trunk/exo.kernel.container/src/main/resources/binding.xml
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/resources/binding.xml 2011-03-03 10:04:47
UTC (rev 4047)
+++ kernel/trunk/exo.kernel.container/src/main/resources/binding.xml 2011-03-03 12:51:45
UTC (rev 4048)
@@ -20,7 +20,7 @@
-->
<binding>
<!-- the default deserializer to use for String -->
- <format type="java.lang.String"
deserializer="org.exoplatform.container.xml.Deserializer.cleanString"/>
+ <format type="java.lang.String"
deserializer="org.exoplatform.container.xml.Deserializer.resolveString"/>
<!-- xml object mapping -->
<mapping class="org.exoplatform.xml.object.XMLBaseObject"
abstract="true" label="base-object">
Added:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestImportWithProperties.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestImportWithProperties.java
(rev 0)
+++
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/configuration/TestImportWithProperties.java 2011-03-03
12:51:45 UTC (rev 4048)
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.container.configuration;
+
+import org.exoplatform.container.xml.Configuration;
+
+/**
+ * Test usage of system properties in import configuration declaration
+ */
+public class TestImportWithProperties extends AbstractProfileTest
+{
+ private String oldValue;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ oldValue = System.getProperty("db.configuration.path");
+ System.clearProperty("db.configuration.path");
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception
+ {
+ if (oldValue == null)
+ {
+ System.clearProperty("db.configuration.path");
+ }
+ else
+ {
+ System.setProperty("db.configuration.path", oldValue);
+ }
+ super.tearDown();
+ }
+
+ /**
+ * Test if used system property not defined. String ${db.configuration.path}
+ * should not be replaced.
+ *
+ * @throws Exception
+ */
+ public void testWithNoPropertyDefined() throws Exception
+ {
+ assertNull(System.getProperty("db.configuration.path"));
+ Configuration config =
getConfiguration("import-with-parameter-configuration.xml");
+ assertEquals(3, config.getImports().size());
+ assertEquals("${db.configuration.path}/db.xml",
config.getImports().get(0));
+ assertEquals(System.getProperty("java.io.tmpdir") +
"/bindfile.xml", config.getImports().get(1));
+ assertEquals("simple.xml", config.getImports().get(2));
+
+ }
+
+ /**
+ * Test if system property t defined. String ${db.configuration.path} should
+ * be replaced with property value.
+ *
+ * @throws Exception
+ */
+ public void testWithPropertyDefined() throws Exception
+ {
+ System.setProperty("db.configuration.path", "/home/admin/db");
+ assertNotNull(System.getProperty("db.configuration.path"));
+ Configuration config =
getConfiguration("import-with-parameter-configuration.xml");
+ assertEquals(3, config.getImports().size());
+ assertEquals("/home/admin/db/db.xml", config.getImports().get(0));
+ assertEquals(System.getProperty("java.io.tmpdir") +
"/bindfile.xml", config.getImports().get(1));
+ assertEquals("simple.xml", config.getImports().get(2));
+
+ }
+}
Added:
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/import-with-parameter-configuration.xml
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/import-with-parameter-configuration.xml
(rev 0)
+++
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/configuration/import-with-parameter-configuration.xml 2011-03-03
12:51:45 UTC (rev 4048)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+<configuration
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <import>${db.configuration.path}/db.xml</import>
+ <import>${java.io.tmpdir}/bindfile.xml</import>
+ <import>simple.xml</import>
+
+
+</configuration>
\ No newline at end of file