cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1195994 - /cocoon/cocoon3/trunk/cocoon-cli/src/main/java/org/apache/cocoon/cli/PipelineDescriptorParser.java
Date Tue, 01 Nov 2011 13:45:44 GMT
Author: simonetripodi
Date: Tue Nov  1 13:45:44 2011
New Revision: 1195994

URL: http://svn.apache.org/viewvc?rev=1195994&view=rev
Log:
allowed system properties and environment variables replacement inside the pipeline descriptor

Modified:
    cocoon/cocoon3/trunk/cocoon-cli/src/main/java/org/apache/cocoon/cli/PipelineDescriptorParser.java

Modified: cocoon/cocoon3/trunk/cocoon-cli/src/main/java/org/apache/cocoon/cli/PipelineDescriptorParser.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-cli/src/main/java/org/apache/cocoon/cli/PipelineDescriptorParser.java?rev=1195994&r1=1195993&r2=1195994&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-cli/src/main/java/org/apache/cocoon/cli/PipelineDescriptorParser.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-cli/src/main/java/org/apache/cocoon/cli/PipelineDescriptorParser.java
Tue Nov  1 13:45:44 2011
@@ -24,10 +24,15 @@ import static org.apache.commons.digeste
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.xml.validation.Schema;
 
 import org.apache.commons.digester3.binder.DigesterLoader;
+import org.apache.commons.digester3.substitution.MultiVariableExpander;
+import org.apache.commons.digester3.substitution.VariableSubstitutor;
 import org.xml.sax.SAXException;
 
 final class PipelineDescriptorParser
@@ -57,7 +62,20 @@ final class PipelineDescriptorParser
             digesterLoader = newLoader( new PipelineDescriptorModule() );
         }
 
-        digesterLoader.setSchema( schema );
+        // copy all environment variables first
+        Map<String, Object> variables = new HashMap<String, Object>( System.getenv()
);
+
+        // copy all system properties
+        for ( Entry<Object, Object> property : System.getProperties().entrySet() )
+        {
+            variables.put( String.valueOf( property.getKey() ), property.getValue() );
+        }
+
+        MultiVariableExpander expander = new MultiVariableExpander();
+        expander.addSource( "$", variables );
+
+        // XML parser validates against a schema and replace ${} variables
+        digesterLoader.setSchema( schema ).setSubstitutor( new VariableSubstitutor( expander
) );
     }
 
     public PipelinesRegistry parse( File pipelineDescriptorFile )



Mime
View raw message