String logTag, SimpleNode nodeTree)
{
/*
* we want to init then render
*/
InternalContextAdapterImpl ica =
new InternalContextAdapterImpl(context);
ica.pushCurrentTemplateName(logTag);
try
{
try
{
nodeTree.init(ica, this);
}
catch (TemplateInitException pex)
{
throw new ParseErrorException(pex, null);
}
/**
* pass through application level runtime exceptions
*/
catch(RuntimeException e)
{
throw e;
}
catch(Exception e)
{
String msg = "RuntimeInstance.render(): init exception for tag = "+logTag;
getLog().error(msg, e);
throw new VelocityException(msg, e);
}
try
{
if (provideEvaluateScope)
{
Object previous = ica.get(evaluateScopeName);
context.put(evaluateScopeName, new Scope(this, previous));
}
nodeTree.render(ica, writer);
}
catch (StopCommand stop)
{
if (!stop.isFor(this))
{
throw stop;
}
else if (getLog().isDebugEnabled())
{
getLog().debug(stop.getMessage());
}
}
catch (IOException e)
{
throw new VelocityException("IO Error in writer: " + e.getMessage(), e);
}
}
finally
{
ica.popCurrentTemplateName();
if (provideEvaluateScope)
{
Object obj = ica.get(evaluateScopeName);
if (obj instanceof Scope)
{
Scope scope = (Scope)obj;
if (scope.getParent() != null)
{
ica.put(evaluateScopeName, scope.getParent());
}
else if (scope.getReplaced() != null)
{
ica.put(evaluateScopeName, scope.getReplaced());
}
else
{
ica.remove(evaluateScopeName);
}
}
}
}