/*
* The new string needs to be parsed since the text has been dynamically generated.
*/
String templateName = context.getCurrentTemplateName();
SimpleNode nodeTree = null;
try
{
nodeTree = rsvc.parse(sourceText, templateName);
}
catch (ParseException pex)
{
// use the line/column from the template
Info info = new Info( templateName, node.getLine(), node.getColumn() );
throw new ParseErrorException( pex.getMessage(), info );
}
catch (TemplateInitException pex)
{
Info info = new Info( templateName, node.getLine(), node.getColumn() );
throw new ParseErrorException( pex.getMessage(), info );
}
/*
* now we want to init and render. Chain the context
* to prevent any changes to the current context.
*/
if (nodeTree != null)
{
InternalContextAdapterImpl ica =
new InternalContextAdapterImpl( new EvaluateContext(context, rsvc) );
ica.pushCurrentTemplateName( templateName );
try
{
try
{
nodeTree.init( ica, rsvc );
}
catch (TemplateInitException pex)
{
Info info = new Info( templateName, node.getLine(), node.getColumn() );
throw new ParseErrorException( pex.getMessage(), info );
}
try
{
/*
* now render, and let any exceptions fly
*/
nodeTree.render( ica, writer );
}
catch (ParseErrorException pex)
{
// convert any parsing errors to the correct line/col
Info info = new Info( templateName, node.getLine(), node.getColumn() );