Class Include
java.lang.Object
org.apache.velocity.runtime.directive.Directive
org.apache.velocity.runtime.directive.InputBase
org.apache.velocity.runtime.directive.Include
- All Implemented Interfaces:
Cloneable
,DirectiveConstants
Pluggable directive that handles the #include() statement in VTL. This #include() can take multiple arguments of either StringLiteral or Reference.
Notes:
- For security reasons, the included source material can only come from somewhere within the template root tree. If you want to include content from elsewhere on your disk, add extra template roots, or use a link from somwhere under template root to that content.
- 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...
- As noted above, #include() can take multiple arguments. Ex : #include('foo.vm' 'bar.vm' $foo) will include all three if valid to output without any special separator.
- Version:
- $Id: Include.java 746438 2009-02-21 05:41:24Z nbubna $
-
Field Summary
FieldsFields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetName()
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 ASTboolean
Since there is no processing of content, there is never a need for an internal scope.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 fileMethods inherited from class org.apache.velocity.runtime.directive.InputBase
getInputEncoding
Methods inherited from class org.apache.velocity.runtime.directive.Directive
getColumn, getLine, getScopeName, getTemplateName, makeScope, postRender, preRender, setLocation, setLocation
-
Field Details
-
outputMsgStart
-
outputMsgEnd
-
-
Constructor Details
-
Include
public Include()
-
-
Method Details
-
getName
Return name of this directive. -
getType
public int getType()Return type of this directive. -
isScopeProvided
public boolean isScopeProvided()Since there is no processing of content, there is never a need for an internal scope.- Overrides:
isScopeProvided
in classDirective
- Returns:
- true if there will be a scope control injected into the context when rendering this directive.
-
init
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException simple init - init the tree and get the elementKey from the AST- Overrides:
init
in classDirective
- Parameters:
rs
-context
-node
-- Throws:
TemplateInitException
-
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.- Specified by:
render
in classDirective
- Parameters:
context
-writer
-node
-- Returns:
- True if the directive rendered successfully.
- Throws:
IOException
MethodInvocationException
ResourceNotFoundException
-
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 Referencecontext
- valid context so we can render Referenceswriter
- output Writer- Returns:
- boolean success or failure. failures are logged
- Throws:
IOException
MethodInvocationException
ResourceNotFoundException
-
outputErrorToStream
Puts a message to the render output stream if ERRORMSG_START / END are valid property strings. Mainly used for end-user template debugging.- Parameters:
writer
-msg
-- Throws:
IOException
-