String templateSource = pSource;
RegExpMatch[] allconfs = iConfRegExp.matchAll( templateSource );
int numConfs = allconfs.length;
if( 0 == numConfs && pConfRequired ) {
throw new TemplateException( TemplateException.CODE_no_conf, new ValueSet( ValueCode.TEMPLATE, iPath ) );
}
else {
PropertySet ps = new PropertySet();
boolean foundConf = false;
RegExpMatch conf = null;
String props = null;
PropertySet propSet = null;
for( int confI = 0; confI < numConfs; confI++ ) {
conf = allconfs[ confI ];
props = conf.matchFirstSub();
propSet = new PropertySet();
propSet.parse( props );
ps.overrideWith( propSet );
foundConf = true;
}
iOrderedPSM.get( Service.CONF_template ).overrideWith( ps );
if( foundConf ) {
// remove conf sections from template
// WARNING: relying on default replace to be empty string here
templateSource = iConfRegExp.replaceAll( templateSource );
}
else if( pConfRequired ) {
throw new TemplateException( TemplateException.CODE_no_conf, new ValueSet( ValueCode.TEMPLATE, iPath ) );
}
}
return templateSource;
}
catch( TemplateException te ) {
throw te;
}
catch( PropertySetException pse ) {
throw new TemplateException( TemplateException.CODE_parse_conf, new ValueSet( ValueCode.TEMPLATE, iPath ), pse );
}
catch( Exception e ) {
throw new TemplateException( TemplateException.CODE_no_conf, new ValueSet( ValueCode.TEMPLATE, iPath ), e );
}
}