Save This Page
Home » cocoon-2.1.11-src » org.apache » cocoon » generation » [javadoc | source]
org.apache.cocoon.generation
public class: VelocityGenerator [javadoc | source]
java.lang.Object
   org.apache.avalon.framework.logger.AbstractLogEnabled
      org.apache.cocoon.xml.AbstractXMLProducer
         org.apache.cocoon.generation.AbstractGenerator
            org.apache.cocoon.generation.ServiceableGenerator
               org.apache.cocoon.generation.VelocityGenerator

All Implemented Interfaces:
    org.apache.velocity.runtime.log.LogSystem, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.service.Serviceable, Generator, org.apache.avalon.excalibur.pool.Recyclable, XMLProducer

Cocoon Generator that produces dynamic XML SAX events from a Velocity template file.

If called from a Flowscript, the immediate properties of the context object from the Flowscript are available in the Velocity context. In that case, the current Web Continuation from the Flowscript is also available as a variable named continuation. You would typically access its id:

<form action="$continuation.id">

You can also reach previous continuations by using the getContinuation() function:

<form action="$continuation.getContinuation(1).id}" >

In addition the following implicit objects are always available in the Velocity context:

request (org.apache.cocoon.environment.Request)
The Cocoon current request
response (org.apache.cocoon.environment.Response)
The Cocoon response associated with the current request
session (org.apache.cocoon.environment.Session)
The Cocoon session associated with the current request
context (org.apache.cocoon.environment.Context)
The Cocoon context associated with the current request
parameters (org.apache.avalon.framework.parameters.Parameters)
Any parameters passed to the generator in the pipeline

Sitemap Configuration

Attributes:

usecache (optional; default: 'false')
set to 'true' to enable template caching on the 'cocoon' resource loader
checkInterval (optional; default: '0')
This is the number of seconds between modification checks when caching is turned on. When this is an integer > 0, this represents the number of seconds between checks to see if the template was modified. If the template has been modified since last check, then it is reloaded and reparsed. Otherwise nothing is done. When <= 0, no modification checks will take place, and assuming that the property cache (above) is true, once a template is loaded and parsed the first time it is used, it will not be checked or reloaded after that until the application or servlet engine is restarted.

Child Elements:

<property name="propertyName" value="propertyValue"/> (optional; 0..n)
An additional property to pass along to the Velocity template engine during initialization
<resource-loader name="loaderName" class="javaClassName" > (optional; 0..n; children: property*)
The default configuration uses the 'cocoon' resource loader which resolves resources via the Cocoon SourceResolver. Additional resource loaders can be added with this configuration element. Configuration properties for the resource loader can be specified by adding a child property element of the resource-loader element. The prefix '<name>.resource.loader.' is automatically added to the property name.
Nested Class Summary:
public static class  VelocityGenerator.ChainedContext  

Velocity context implementation specific to the Servlet environment.

It provides the following special features:

  • puts the request, response, session, and servlet context objects into the Velocity context for direct access, and keeps them read-only
  • supports a read-only toolbox of view tools
  • auto-searches servlet request attributes, session attributes and servlet context attribues for objects

The {@link #internalGet(String key)} method implements the following search order for objects:

  1. servlet request, servlet response, servlet session, servlet context
  2. toolbox
  3. local hashtable of objects (traditional use)
  4. servlet request attribues, servlet session attribute, servlet context attributes

The purpose of this class is to make it easy for web designer to work with Java servlet based web applications. They do not need to be concerned with the concepts of request, session or application attributes and the live time of objects in these scopes.

Note that the put() method always puts objects into the local hashtable.

Acknowledge: the source code is borrowed from the jakarta-velocity-tools project with slight modifications.

 
public static class  VelocityGenerator.JSIntrospector  Velocity Introspector that supports Rhino JavaScript objects as well as Java Objects 
public static class  VelocityGenerator.TemplateLoader  Velocity {@link org.apache.velocity.runtime.resource.loader.ResourceLoader} implementation to load template resources using Cocoon's {@link SourceResolver}. This class is created by the Velocity framework via the ResourceLoaderFactory. 
Fields inherited from org.apache.cocoon.generation.ServiceableGenerator:
manager
Fields inherited from org.apache.cocoon.generation.AbstractGenerator:
resolver,  objectModel,  parameters,  source
Fields inherited from org.apache.cocoon.xml.AbstractXMLProducer:
EMPTY_CONTENT_HANDLER,  xmlConsumer,  contentHandler,  lexicalHandler
Method from org.apache.cocoon.generation.VelocityGenerator Summary:
configure,   generate,   init,   initialize,   logVelocityMessage,   recycle,   setup
Methods from org.apache.cocoon.generation.ServiceableGenerator:
dispose,   service
Methods from org.apache.cocoon.generation.AbstractGenerator:
recycle,   setup
Methods from org.apache.cocoon.xml.AbstractXMLProducer:
recycle,   setConsumer,   setContentHandler,   setLexicalHandler
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.cocoon.generation.VelocityGenerator Detail:
 public  void configure(Configuration configuration) throws ConfigurationException 
    Read any additional objects to export to the Velocity context from the configuration.
 public  void generate() throws IOException, SAXException, ProcessingException 
    Generate XML data using Velocity template.
 public  void init(RuntimeServices rs) throws Exception 
    This implementation does nothing.
 public  void initialize() throws Exception 
 public  void logVelocityMessage(int level,
    String message) 
    Pass along Velocity log messages to our configured logger.
 public  void recycle() 
    Free up the VelocityContext associated with the pipeline, and release any Source objects resolved by the resource loader.
 public  void setup(SourceResolver resolver,
    Map objectModel,
    String src,
    Parameters params) throws IOException, SAXException, ProcessingException