org.apache.cocoon.generation
Class VelocityGenerator

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.xml.AbstractXMLProducer
              |
              +--org.apache.cocoon.generation.AbstractGenerator
                    |
                    +--org.apache.cocoon.generation.ComposerGenerator
                          |
                          +--org.apache.cocoon.generation.VelocityGenerator
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Disposable, Generator, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.logger.Loggable, org.apache.velocity.runtime.log.LogSystem, org.apache.avalon.excalibur.pool.Poolable, org.apache.avalon.excalibur.pool.Recyclable, SitemapModelComponent, XMLProducer

public class VelocityGenerator
extends ComposerGenerator
implements org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.configuration.Configurable, org.apache.velocity.runtime.log.LogSystem

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

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 key="propertyKey" 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.
<export-object key="objectMapKey" name="velocityContextName"/> (optional; 0..n)
Export the object specified by key from the Cocoon object map to the Velocity context of the template. The object can be accessed from the template as name. Be careful to use a valid VTL variable name.

Default Java objects exported to the Velocity context:

request (org.apache.cocoon.environment.Request)
The Cocoon current request
template (java.lang.String)
The path of the template file currently being evaluated
response (org.apache.cocoon.environment.Response)
The Cocoon response 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

Additional Java objects can be exported from the Cocoon object map to the Velocity context by adding one or more <export-object key="objectMapKey" name="velocityContextName"/> child elements to the generator configuration in the sitemap.

Version:
CVS $Id: VelocityGenerator.java,v 1.8 2002/02/22 07:03:51 cziegeler Exp $
Author:
Davanum Srinivas, Michael McKibben

Inner Class Summary
static class VelocityGenerator.TemplateLoader
          Velocity ResourceLoader implementation to load template resources using Cocoon's SourceResolver.
 
Fields inherited from class org.apache.cocoon.generation.ComposerGenerator
manager
 
Fields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, source
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.velocity.runtime.log.LogSystem
DEBUG_ID, DEBUG_ON, ERROR_ID, INFO_ID, WARN_ID
 
Fields inherited from interface org.apache.cocoon.generation.Generator
ROLE
 
Constructor Summary
VelocityGenerator()
           
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
          Read any additional objects to export to the Velocity context from the configuration.
 void generate()
          Generate XML data using Velocity template.
 void init(org.apache.velocity.runtime.RuntimeServices rs)
          This implementation does nothing.
 void initialize()
           
 void logVelocityMessage(int level, java.lang.String message)
          Pass along Velocity log messages to our configured logger.
 void recycle()
          Free up the VelocityContext associated with the pipeline, and release any Source objects resolved by the resource loader.
 void setup(SourceResolver resolver, java.util.Map objectModel, java.lang.String src, org.apache.avalon.framework.parameters.Parameters params)
          Set the SourceResolver, object model Map, the source and sitemap Parameters used to process the request.
 
Methods inherited from class org.apache.cocoon.generation.ComposerGenerator
compose, dispose
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Constructor Detail

VelocityGenerator

public VelocityGenerator()
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Read any additional objects to export to the Velocity context from the configuration.
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
configuration - the class configurations.
See Also:
Configurable.configure(org.apache.avalon.framework.configuration.Configuration)

initialize

public void initialize()
                throws java.lang.Exception
Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
See Also:
Initializable.initialize()

setup

public void setup(SourceResolver resolver,
                  java.util.Map objectModel,
                  java.lang.String src,
                  org.apache.avalon.framework.parameters.Parameters params)
           throws ProcessingException,
                  org.xml.sax.SAXException,
                  java.io.IOException
Description copied from class: AbstractGenerator
Set the SourceResolver, object model Map, the source and sitemap Parameters used to process the request.
Overrides:
setup in class AbstractGenerator
See Also:
SitemapModelComponent.setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)

recycle

public void recycle()
Free up the VelocityContext associated with the pipeline, and release any Source objects resolved by the resource loader.
Overrides:
recycle in class AbstractGenerator
See Also:
Recyclable.recycle()

generate

public void generate()
              throws java.io.IOException,
                     org.xml.sax.SAXException,
                     ProcessingException
Generate XML data using Velocity template.
See Also:
Generator.generate()

init

public void init(org.apache.velocity.runtime.RuntimeServices rs)
          throws java.lang.Exception
This implementation does nothing.
Specified by:
init in interface org.apache.velocity.runtime.log.LogSystem
See Also:
LogSystem.init(org.apache.velocity.runtime.RuntimeServices)

logVelocityMessage

public void logVelocityMessage(int level,
                               java.lang.String message)
Pass along Velocity log messages to our configured logger.
Specified by:
logVelocityMessage in interface org.apache.velocity.runtime.log.LogSystem
See Also:
LogSystem.logVelocityMessage(int, java.lang.String)


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.