Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.velocity
Class Template

    java.lang.Object
      |
      +--org.apache.velocity.runtime.resource.Resource
            |
            +--org.apache.velocity.Template

public class Template
extends Resource

This class is used for controlling all template operations. This class uses a parser created by JavaCC to create an AST that is subsequently traversed by a Visitor.

     Template template = Velocity.getTemplate("test.wm");
     Context context = new VelocityContext();

     context.put("foo", "bar");
     context.put("customer", new Customer());

     template.merge(context, writer);

Version:
  $Id: Template.java,v 1.35 2001/10/22 03:53:22 jon Exp $
Author:
  Jason van Zyl, Geir Magnusson Jr.

Field Summary
`private java.lang.Exception` | `errorCondition`
`private boolean` | `initialized` To keep track of whether this template has been initialized.

Fields inherited from class org.apache.velocity.runtime.resource.Resource
`data, encoding, lastModified, MILLIS_PER_SECOND, modificationCheckInterval, name, nextCheck, resourceLoader, rsvc`

Constructor Summary
`Template()` Default constructor

Method Summary
`void` | `initDocument()` initializes the document.
`void` | `merge(Context context, java.io.Writer writer)` The AST node structure is merged with the context to produce the final output.
`boolean` | `process()` gets the named resource as a stream, parses and inits

Methods inherited from class org.apache.velocity.runtime.resource.Resource
`getData, getEncoding, getLastModified, getName, getResourceLoader, isSourceModified, requiresChecking, setData, setEncoding, setLastModified, setModificationCheckInterval, setName, setResourceLoader, setRuntimeServices, touch`

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### initialized

    private boolean initialized

  To keep track of whether this template has been initialized. We use the document.init(context) to perform this.

### errorCondition

    private java.lang.Exception errorCondition

Constructor Detail

### Template

    public Template()

  Default constructor

Method Detail

### process

    public boolean process()
                    throws ResourceNotFoundException,
                           ParseErrorException,
                           java.lang.Exception

  gets the named resource as a stream, parses and inits
  Overrides:
    `process` in class `Resource`
  Returns:
    true if successful
  Throws:
    `ResourceNotFoundException` - if template not found from any available source.
    `ParseErrorException` - if template cannot be parsed due to syntax (or other) error.
    `java.lang.Exception` - some other problem, should only be from initialization of the template AST.

### initDocument

    public void initDocument()
                      throws java.lang.Exception

  initializes the document. init() is not longer dependant upon context, but we need to let the init() carry the template name down throught for VM namespace features

### merge

    public void merge(Context context,
                      java.io.Writer writer)
               throws ResourceNotFoundException,
                      ParseErrorException,
                      MethodInvocationException,
                      java.lang.Exception

  The AST node structure is merged with the context to produce the final output. Throws IOException if failure is due to a file related issue, and Exception otherwise
  Parameters:
    `context` - Conext with data elements accessed by template
    `writer` - output writer for rendered template
  Throws:
    `ResourceNotFoundException` - if template not found from any available source.
    `ParseErrorException` - if template cannot be parsed due to syntax (or other) error.
    `java.lang.Exception` - anything else.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003 Apache Software Foundation. All Rights Reserved.