public boolean render(InternalContextAdapter context,
Writer writer,
Node node) throws MethodInvocationException, IOException, ResourceNotFoundException, ParseErrorException {
/*
* if rendering is no longer allowed (after a stop), we can safely
* skip execution of all the parse directives.
*/
if(!context.getAllowRendering())
{
return true;
}
/*
* did we get an argument?
*/
if ( node.jjtGetChild(0) == null)
{
rsvc.getLog().error("#parse() null argument");
return false;
}
/*
* does it have a value? If you have a null reference, then no.
*/
Object value = node.jjtGetChild(0).value( context );
if ( value == null)
{
rsvc.getLog().error("#parse() null argument");
return false;
}
/*
* get the path
*/
String sourcearg = value.toString();
/*
* check to see if the argument will be changed by the event cartridge
*/
String arg = EventHandlerUtil.includeEvent( rsvc, context, sourcearg, context.getCurrentTemplateName(), getName());
/*
* a null return value from the event cartridge indicates we should not
* input a resource.
*/
boolean blockinput = false;
if (arg == null)
blockinput = true;
/*
* see if we have exceeded the configured depth.
* If it isn't configured, put a stop at 20 just in case.
*/
Object[] templateStack = context.getTemplateNameStack();
if ( templateStack.length >=
rsvc.getInt(RuntimeConstants.PARSE_DIRECTIVE_MAXDEPTH, 20) )
{
StringBuffer path = new StringBuffer();
for( int i = 0; i < templateStack.length; ++i)
{
path.append( " > " + templateStack[i] );
}
rsvc.getLog().error("Max recursion depth reached (" +
templateStack.length + ')" + " File stack:" +
path);
return false;
}
/*
* now use the Runtime resource loader to get the template
*/
Template t = null;
try
{
if (!blockinput)
t = rsvc.getTemplate( arg, getInputEncoding(context) );
}
catch ( ResourceNotFoundException rnfe )
{
/*
* the arg wasn't found. Note it and throw
*/
rsvc.getLog().error("#parse(): cannot find template '" + arg +
"', called from template " +
context.getCurrentTemplateName() + " at (" +
getLine() + ", " + getColumn() + ")" );
throw rnfe;
}
catch ( ParseErrorException pee )
{
/*
* the arg was found, but didn't parse - syntax error
* note it and throw
*/
rsvc.getLog().error("#parse(): syntax error in #parse()-ed template '"
+ arg + "', called from template " +
context.getCurrentTemplateName() + " at (" +
getLine() + ", " + getColumn() + ")" );
throw pee;
}
/**
* pass through application level runtime exceptions
*/
catch( RuntimeException e )
{
throw e;
}
catch ( Exception e)
{
rsvc.getLog().error("#parse() : arg = " + arg + '.", e);
return false;
}
/*
* and render it
*/
try
{
if (!blockinput) {
context.pushCurrentTemplateName(arg);
((SimpleNode) t.getData()).render( context, writer );
}
}
/*
* if it's a MIE, it came from the render.... throw it...
*/
catch( MethodInvocationException e )
{
throw e;
}
/**
* pass through application level runtime exceptions
*/
catch( RuntimeException e )
{
throw e;
}
catch ( Exception e )
{
rsvc.getLog().error("Exception rendering #parse(" + arg + ')", e);
return false;
}
finally
{
if (!blockinput)
context.popCurrentTemplateName();
}
/*
* note - a blocked input is still a successful operation as this is
* expected behavior.
*/
return true;
}
iterates through the argument list and renders every
argument that is appropriate. Any non appropriate
arguments are logged, but render() continues. |