org.apache.velocity.runtime.directive

Class Include

Implemented Interfaces:
Cloneable, DirectiveConstants

public class Include
extends Directive

Pluggable directive that handles the #include() statement in VTL. This #include() can take multiple arguments of either StringLiteral or Reference. Notes: ----- 1) The included source material can only come from somewhere in the TemplateRoot tree for security reasons. There is no way around this. If you want to include content from elsewhere on your disk, use a link from somwhere under Template Root to that content. 2) By default, there is no output to the render stream in the event of a problem. You can override this behavior with two property values : include.output.errormsg.start include.output.errormsg.end If both are defined in velocity.properties, they will be used to in the render output to bracket the arg string that caused the problem. Ex. : if you are working in html then include.output.errormsg.start=<!-- #include error : include.output.errormsg.end= --> might be an excellent way to start... 3) As noted above, #include() can take multiple arguments. Ex : #include( "foo.vm" "bar.vm" $foo ) will simply include all three if valid to output w/o any special separator.

Version:
$Id: Include.java,v 1.23 2001/10/22 03:53:24 jon Exp $

Authors:
Geir Magnusson Jr.
Jason van Zyl
Kasper Nielsen

Nested Class Summary

Field Summary

private String
outputMsgEnd
private String
outputMsgStart

Fields inherited from class org.apache.velocity.runtime.directive.Directive

column, line, rsvc

Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants

BLOCK, LINE

Method Summary

String
getName()
Return name of this directive.
int
getType()
Return type of this directive.
void
init(RuntimeServices rs, InternalContextAdapter context, Node node)
simple init - init the tree and get the elementKey from the AST
private void
outputErrorToStream(Writer writer, String msg)
Puts a message to the render output stream if ERRORMSG_START / END are valid property strings.
boolean
render(InternalContextAdapter context, Writer writer, Node node)
iterates through the argument list and renders every argument that is appropriate.
private boolean
renderOutput(Node node, InternalContextAdapter context, Writer writer)
does the actual rendering of the included file

Methods inherited from class org.apache.velocity.runtime.directive.Directive

getColumn, getLine, getName, getType, init, render, setLocation

Field Details

outputMsgEnd

private String outputMsgEnd


outputMsgStart

private String outputMsgStart

Method Details

getName

public String getName()
Return name of this directive.
Overrides:
getName in interface Directive


getType

public int getType()
Return type of this directive.
Overrides:
getType in interface Directive


init

public void init(RuntimeServices rs,
                 InternalContextAdapter context,
                 Node node)
            throws Exception
simple init - init the tree and get the elementKey from the AST
Overrides:
init in interface Directive


outputErrorToStream

private void outputErrorToStream(Writer writer,
                                 String msg)
            throws IOException
Puts a message to the render output stream if ERRORMSG_START / END are valid property strings. Mainly used for end-user template debugging.


render

public boolean render(InternalContextAdapter context,
                      Writer writer,
                      Node node)
            throws IOException,
                   MethodInvocationException,
                   ResourceNotFoundException
iterates through the argument list and renders every argument that is appropriate. Any non appropriate arguments are logged, but render() continues.
Overrides:
render in interface Directive


renderOutput

private boolean renderOutput(Node node,
                             InternalContextAdapter context,
                             Writer writer)
            throws IOException,
                   MethodInvocationException,
                   ResourceNotFoundException
does the actual rendering of the included file

Parameters:
node - AST argument of type StringLiteral or Reference
context - valid context so we can render References
writer - output Writer

Returns:
boolean success or failure. failures are logged


Copyright © 2003 Apache Software Foundation. All Rights Reserved.