[exo-jcr-commits] exo-jcr SVN: r1949 - in kernel/trunk/exo.kernel.container/src: main/java/org/exoplatform/container/xml and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Feb 24 05:56:39 EST 2010


Author: nfilotto
Date: 2010-02-24 05:56:38 -0500 (Wed, 24 Feb 2010)
New Revision: 1949

Modified:
   kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
   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/TestPropertyManagerConfigurator.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/portal/myPortal-pcdef/settings.properties
   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/property-configurator.properties
   kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/property-configurator.xml
Log:
EXOJCR-543: It was not possible anymore to create a variable thanks to another variables.
UnitTests have been added and bug has been fixed

Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java	2010-02-24 10:56:15 UTC (rev 1948)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java	2010-02-24 10:56:38 UTC (rev 1949)
@@ -242,12 +242,15 @@
             }
             if (props != null)
             {
+               // Those properties are used for variables resolution
+               final LinkedHashMap<String, String> currentProps = new LinkedHashMap<String,String>();
                for (Map.Entry<String, String> entry : props.entrySet())
                {
                   String propertyName = entry.getKey();
                   String propertyValue = entry.getValue();
-                  propertyValue = Deserializer.resolveString(propertyValue);
+                  propertyValue = Deserializer.resolveVariables(propertyValue, currentProps);
                   props.put(propertyName, propertyValue);
+                  currentProps.put(propertyName, propertyValue);
                }
             }
          }

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	2010-02-24 10:56:15 UTC (rev 1948)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/xml/Deserializer.java	2010-02-24 10:56:38 UTC (rev 1949)
@@ -23,6 +23,8 @@
 import org.exoplatform.container.PortalContainer;
 import org.exoplatform.container.RootContainer;
 
+import java.util.Map;
+
 /**
  * A deserializer used by JIBX that resolve system properties to allow runtime configuration.
  *
@@ -182,6 +184,18 @@
     */
    public static String resolveVariables(String input)
    {
+      return resolveVariables(input, null);
+   }
+   
+   /**
+    * Resolve the variables of type ${my.var} for the current context which is composed
+    * of the system properties, the portal container properties and the given properties
+    * @param input the input value
+    * @param props a set of properties to add for the variable resolution
+    * @return the resolve value
+    */
+   public static String resolveVariables(String input, Map<String, String> props)   
+   {
       final int NORMAL = 0;
       final int SEEN_DOLLAR = 1;
       final int IN_BRACKET = 2;
@@ -241,7 +255,17 @@
                }
                else
                {
-                  value = System.getProperty(key);
+                  if (props != null)
+                  {
+                     // Some properties have been given thus we need to check inside first
+                     value = props.get(key);
+                  }
+                  if (value == null)
+                  {
+                     // No value could be found so far, thus we try to get it from the 
+                     // system properties
+                     value = System.getProperty(key);                     
+                  }
                }
                if (value != null)
                {

Modified: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPropertyManagerConfigurator.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPropertyManagerConfigurator.java	2010-02-24 10:56:15 UTC (rev 1948)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPropertyManagerConfigurator.java	2010-02-24 10:56:38 UTC (rev 1949)
@@ -19,6 +19,7 @@
 package org.exoplatform.container;
 
 import junit.framework.TestCase;
+
 import org.exoplatform.commons.utils.PropertyManager;
 import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.container.configuration.ConfigurationManagerImpl;
@@ -111,6 +112,7 @@
       assertEquals("property_value_1", additions.get("property_1"));
       assertEquals("property_value_2", additions.get("property_2"));
       assertEquals("${property_3}", additions.get("property_3"));
+      assertEquals("property_value_1-property_value_2", additions.get("property_4"));
    }
 
    public void testFromPropertiesByParam() throws Exception
@@ -129,6 +131,7 @@
       assertEquals("property_value_1", additions.get("property_1"));
       assertEquals("property_value_2", additions.get("property_2"));
       assertEquals("${property_3}", additions.get("property_3"));
+      assertEquals("property_value_1-property_value_2", additions.get("property_4"));
    }
 
    public void testFromProperties() throws Exception
@@ -146,6 +149,7 @@
       assertEquals("property_value_1", additions.get("property_1"));
       assertEquals("property_value_2", additions.get("property_2"));
       assertEquals("${property_3}", additions.get("property_3"));
+      assertEquals("property_value_1-property_value_2", additions.get("property_4"));
    }
 
    public void testFromXML() throws Exception
@@ -163,5 +167,6 @@
       assertEquals("property_value_1", additions.get("property_1"));
       assertEquals("property_value_2", additions.get("property_2"));
       assertEquals("${property_3}", additions.get("property_3"));
+      assertEquals("property_value_1-property_value_2", additions.get("property_4"));
    }
 }

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	2010-02-24 10:56:15 UTC (rev 1948)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java	2010-02-24 10:56:38 UTC (rev 1949)
@@ -278,6 +278,7 @@
       assertEquals("20", config.getSetting("myPortal-pcdef", "long"));
       assertEquals("20", config.getSetting("myPortal-pcdef", "double"));
       assertEquals("false", config.getSetting("myPortal-pcdef", "boolean"));
+      assertEquals("value-new value", config.getSetting("myPortal-pcdef", "complex-value"));
       assertNull(config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
       assertNull(config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
       assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef",
@@ -310,6 +311,7 @@
          assertEquals("22", config.getSetting("myPortal-pcdef", "long"));
          assertEquals("22", config.getSetting("myPortal-pcdef", "double"));
          assertEquals("true", config.getSetting("myPortal-pcdef", "boolean"));
+         assertEquals("value 2-new value 2", config.getSetting("myPortal-pcdef", "complex-value"));
          assertNull(config.getSetting("foo", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
          assertNull(config.getSetting("myPortal", PortalContainerConfig.PORTAL_CONTAINER_SETTING_NAME));
          assertEquals("myPortal-pcdef", config.getSetting("myPortal-pcdef",

Modified: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal/myPortal-pcdef/settings.properties
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal/myPortal-pcdef/settings.properties	2010-02-24 10:56:15 UTC (rev 1948)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/portal/myPortal-pcdef/settings.properties	2010-02-24 10:56:38 UTC (rev 1949)
@@ -3,4 +3,5 @@
 int=22
 long=22
 double=22
-boolean=true
\ No newline at end of file
+boolean=true
+complex-value=${foo2}-${string}
\ No newline at end of file

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	2010-02-24 10:56:15 UTC (rev 1948)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/definition/settings.properties	2010-02-24 10:56:38 UTC (rev 1949)
@@ -3,4 +3,5 @@
 int=20
 long=20
 double=20
-boolean=false
\ No newline at end of file
+boolean=false
+complex-value=${foo2}-${string}
\ No newline at end of file

Modified: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/property-configurator.properties
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/property-configurator.properties	2010-02-24 10:56:15 UTC (rev 1948)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/property-configurator.properties	2010-02-24 10:56:38 UTC (rev 1949)
@@ -1,3 +1,4 @@
 property_1=property_value_1
 property_2=${property_2}
-property_3=${property_3}
\ No newline at end of file
+property_3=${property_3}
+property_4=${property_1}-${property_2}
\ No newline at end of file

Modified: kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/property-configurator.xml
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/property-configurator.xml	2010-02-24 10:56:15 UTC (rev 1948)
+++ kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/property-configurator.xml	2010-02-24 10:56:38 UTC (rev 1949)
@@ -4,4 +4,5 @@
 <entry key="property_1">property_value_1</entry>
 <entry key="property_2">${property_2}</entry>
 <entry key="property_3">${property_3}</entry>
+<entry key="property_4">${property_1}-${property_2}</entry>
 </properties>
\ No newline at end of file



More information about the exo-jcr-commits mailing list