org.xwiki.velocity
Interface VelocityFactory


@ComponentRole
public interface VelocityFactory

Allows creating different Velocity engine instances. This is useful when you need to have different Velocity engines running in the same JVM but with different configurations. Since global templates in Velocity are part of the configuration the only solution to use different global templates is to use different Velocity engines. As an example we need this in XWiki since we want to allow each Skin to provide its own global macros.

Version:
$Id$

Method Summary
 VelocityEngine createVelocityEngine(String key, Properties properties)
          Creates a new Velocity engine instance, which will be cached using a specific key for later reuse.
 VelocityEngine getVelocityEngine(String key)
          Retrieves from the cache the Velocity engine corresponding to a specific key, if such an engine was already created.
 boolean hasVelocityEngine(String key)
          Check if an engine was already created for a certain key.
 

Method Detail

hasVelocityEngine

boolean hasVelocityEngine(String key)
Check if an engine was already created for a certain key.

Parameters:
key - the key under which the Velocity engine has been saved in cache. This is the key used when the Velocity engine was created using createVelocityEngine(String, java.util.Properties)
Returns:
true if there is a cached Velocity Engine matching the passed key, false otherwise.

getVelocityEngine

VelocityEngine getVelocityEngine(String key)
Retrieves from the cache the Velocity engine corresponding to a specific key, if such an engine was already created.

Parameters:
key - the key under which the Velocity engine has been saved in cache. This is the key used when the Velocity engine was created using createVelocityEngine(String, java.util.Properties)
Returns:
the cached Velocity engine instance corresponding to the passed key or null if not found

createVelocityEngine

VelocityEngine createVelocityEngine(String key,
                                    Properties properties)
                                    throws XWikiVelocityException
Creates a new Velocity engine instance, which will be cached using a specific key for later reuse. The key allows having different Velocity Engines, so that each one can have its own special configuration. This is especially handy for having different sets of global Velocity libraries (such as for different XWiki Skins for example). If another engine was previously created for the same key, then that instance is returned instead, without creating any other instance.

Parameters:
key - the key used to cache the Velocity engine instance to return
properties - the list of properties that will override the default properties when creating the engine. For example it's possible to define a list of global velocimacros by passing the RuntimeConstants.VM_LIBRARY property key.
Returns:
the newly created Velocity Engine, or an existing one, if an engine was previously created for the same key.
Throws:
XWikiVelocityException - if the Velocity Engine cannot be initialized for some reason


Copyright © 2004-2011 XWiki. All Rights Reserved.