Author: gnodet
Date: Fri Jul 25 07:55:49 2008
New Revision: 679824

URL: http://svn.apache.org/viewvc?rev=679824&view=rev
Log:
SMX4KNL-66: When the file monitor loads configuration for the config admin, 
allow the use of system properties using 

Modified:
    
servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java

Modified: 
servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java
URL: 
http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java?rev=679824&r1=679823&r2=679824&view=diff
==============================================================================
--- 
servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java
 (original)
+++ 
servicemix/smx4/kernel/trunk/filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java
 Fri Jul 25 07:55:49 2008
@@ -32,6 +32,9 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.Enumeration;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.jar.Attributes;
@@ -430,6 +433,7 @@
             InputStream in = new FileInputStream(file);
             try {
                 properties.load(in);
+                interpolation(properties);
                 closeQuietly(in);
                 String[] pid = parsePid(file);
                 Hashtable<Object, Object> hashtable = new Hashtable<Object, 
Object>();
@@ -450,6 +454,22 @@
         }
     }
 
+    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);
+        }
+    }
+
     protected void deleteConfiguration(File file) throws IOException, 
InvalidSyntaxException {
         String[] pid = parsePid(file);
         Configuration config = getConfiguration(pid[0], pid[1]);


Reply via email to