in src/main/java/org/apache/sling/provisioning/model/ModelResolveUtility.java [113:196]
static void getProcessedConfiguration(
final Feature feature,
final Configuration newConfig,
final Configuration config,
final boolean replaceVariables,
final VariableResolver resolver) {
newConfig.setComment(config.getComment());
newConfig.setLocation(config.getLocation());
// check for raw configuration
String rawConfig = (String)config.getProperties().get(ModelConstants.CFG_UNPROCESSED);
if ( rawConfig != null ) {
if ( replaceVariables ) {
rawConfig = replace(feature, rawConfig, resolver);
}
if ( config.isSpecial() ) {
newConfig.getProperties().put(config.getPid(), rawConfig);
} else {
final String format = (String)config.getProperties().get(ModelConstants.CFG_UNPROCESSED_FORMAT);
if ( ModelConstants.CFG_FORMAT_PROPERTIES.equals(format) ) {
// properties
final Properties props = new Properties();
try {
props.load(new StringReader(rawConfig));
} catch ( final IOException ioe) {
throw new IllegalArgumentException("Unable to read configuration properties.", ioe);
}
final Enumeration<Object> i = props.keys();
while ( i.hasMoreElements() ) {
final String key = (String)i.nextElement();
newConfig.getProperties().put(key, props.get(key));
}
} else {
// Apache Felix CA format
// the raw format might have comments, we have to remove them first
final StringBuilder sb = new StringBuilder();
try {
final LineNumberReader lnr = new LineNumberReader(new StringReader(rawConfig));
String line = null;
while ((line = lnr.readLine()) != null ) {
line = line.trim();
if ( line.isEmpty() || line.startsWith("#")) {
continue;
}
sb.append(line);
sb.append('\n');
}
} catch ( final IOException ioe) {
throw new IllegalArgumentException("Unable to read configuration properties: " + config, ioe);
}
ByteArrayInputStream bais = null;
try {
bais = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
@SuppressWarnings("unchecked")
final Dictionary<String, Object> props = ConfigurationHandler.read(bais);
final Enumeration<String> i = props.keys();
while ( i.hasMoreElements() ) {
final String key = i.nextElement();
newConfig.getProperties().put(key, props.get(key));
}
} catch ( final IOException ioe) {
throw new IllegalArgumentException("Unable to read configuration properties: " + config, ioe);
} finally {
if ( bais != null ) {
try {
bais.close();
} catch ( final IOException ignore ) {
// ignore
}
}
}
}
}
} else {
// simply copy
final Enumeration<String> i = config.getProperties().keys();
while ( i.hasMoreElements() ) {
final String key = i.nextElement();
newConfig.getProperties().put(key, config.getProperties().get(key));
}
}
}