1 16 package org.apache.cocoon.transformation.helpers; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.avalon.framework.configuration.Configuration; 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer; 24 import org.apache.avalon.framework.parameters.Parameters; 25 import org.xml.sax.SAXException ; 26 27 34 public class VariableConfiguration { 35 public static final String UNSET_VAR="unset"; 36 private Configuration conf; 37 private Map vars = new HashMap (); 38 39 43 public VariableConfiguration(Configuration conf) { 44 this.conf = conf; 45 } 46 47 49 public void addVariable(String name, String value) { 50 vars.put(name, value); 51 } 52 53 55 public void addVariables(Parameters params) { 56 String [] names = params.getNames(); 57 for (int i=0; i<names.length; i++) { 58 String paramVal = params.getParameter(names[i], null); 59 if (paramVal != null) { 60 vars.put(names[i], paramVal); 61 } 62 } 63 } 64 65 71 public Configuration getConfiguration() throws SAXException , ConfigurationException { 72 73 if (this.conf == null) return null; 74 InterpolatingConfigurationHandler handler = new InterpolatingConfigurationHandler(this.vars, this.conf.getLocation()); 75 DefaultConfigurationSerializer ser = new DefaultConfigurationSerializer(); 76 ser.serialize(handler, this.conf); 77 return handler.getConfiguration(); 78 } 79 80 } 81 | Popular Tags |