You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/04/22 05:13:41 UTC

svn commit: r767353 - /servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/RepositoryImpl.java

Author: ffang
Date: Wed Apr 22 03:13:40 2009
New Revision: 767353

URL: http://svn.apache.org/viewvc?rev=767353&view=rev
Log:
[SMX4KNL-261]Missing system property replacement in feature configurations

Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/RepositoryImpl.java

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/RepositoryImpl.java?rev=767353&r1=767352&r2=767353&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/RepositoryImpl.java (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-features/src/main/java/org/apache/servicemix/kernel/gshell/features/internal/RepositoryImpl.java Wed Apr 22 03:13:40 2009
@@ -21,10 +21,13 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -119,6 +122,7 @@
                         String data = c.getTextContent();
                         Properties properties = new Properties();
                         properties.load(new ByteArrayInputStream(data.getBytes()));
+                        interpolation(properties);
                         Map<String, String> hashtable = new Hashtable<String, String>();
                         for (Object key : properties.keySet()) {
                             String n = key.toString();
@@ -145,4 +149,20 @@
         }
     }
 
+    protected void interpolation(Properties properties) {
+        for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) {
+            String key = (String)e.nextElement();
+            String val = properties.getProperty(key);
+            Matcher matcher = Pattern.compile("\\$\\{([^}]+)\\}").matcher(val);
+            while (matcher.find()) {
+                String rep = System.getProperty(matcher.group(1));
+                if (rep != null) {
+                    val = val.replace(matcher.group(0), rep);
+                    matcher.reset(val);
+                }
+            }
+            properties.put(key, val);
+        }
+    }
+
 }