in velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Include.java [198:286]
private boolean renderOutput( Node node, InternalContextAdapter context,
Writer writer )
throws IOException, MethodInvocationException,
ResourceNotFoundException
{
if ( node == null )
{
log.error("#include() null argument");
return false;
}
/*
* does it have a value? If you have a null reference, then no.
*/
Object value = node.value( context );
if ( value == null)
{
log.error("#include() null argument");
return false;
}
/*
* get the path
*/
String sourcearg = value.toString();
/*
* check to see if the argument will be changed by the event handler
*/
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;
Resource resource = null;
try
{
if (!blockinput)
resource = getResource(arg, getInputEncoding(context));
}
catch ( ResourceNotFoundException rnfe )
{
/*
* the arg wasn't found. Note it and throw
*/
log.error("#" + getName() + "(): cannot find resource '{}', called at {}",
arg, StringUtils.formatFileString(this));
throw rnfe;
}
/*
* pass through application level runtime exceptions
*/
catch( RuntimeException e )
{
log.error("#" + getName() + "(): arg = '{}', called at {}",
arg, StringUtils.formatFileString(this));
throw e;
}
catch (Exception e)
{
String msg = "#" + getName() + "(): arg = '" + arg +
"', called at " + StringUtils.formatFileString(this);
log.error(msg, e);
throw new VelocityException(msg, e, rsvc.getLogContext().getStackTrace());
}
/*
* note - a blocked input is still a successful operation as this is
* expected behavior.
*/
if ( blockinput )
return true;
else if ( resource == null )
return false;
writer.write((String)resource.getData());
return true;
}