org.xwiki.velocity.internal
Class DefaultVelocityFactory

java.lang.Object
  extended by org.xwiki.velocity.internal.DefaultVelocityFactory
All Implemented Interfaces:
VelocityFactory

@Component
@Singleton
public class DefaultVelocityFactory
extends java.lang.Object
implements VelocityFactory

Default implementation for VelocityFactory.

Version:
$Id$
See Also:
VelocityFactory

Constructor Summary
DefaultVelocityFactory()
           
 
Method Summary
 VelocityEngine createVelocityEngine(java.lang.String key, java.util.Properties properties)
          Creates a new Velocity engine instance, which will be cached using a specific key for later reuse.
 VelocityEngine getVelocityEngine(java.lang.String key)
          Retrieves from the cache the Velocity engine corresponding to a specific key, if such an engine was already created.
 boolean hasVelocityEngine(java.lang.String key)
          Check if an engine was already created for a certain key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultVelocityFactory

public DefaultVelocityFactory()
Method Detail

hasVelocityEngine

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

Specified by:
hasVelocityEngine in interface VelocityFactory
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 VelocityFactory.createVelocityEngine(String, java.util.Properties)
Returns:
true if there is a cached Velocity Engine matching the passed key, false otherwise.
See Also:
VelocityFactory.hasVelocityEngine(String)

getVelocityEngine

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

Specified by:
getVelocityEngine in interface VelocityFactory
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 VelocityFactory.createVelocityEngine(String, java.util.Properties)
Returns:
the cached Velocity engine instance corresponding to the passed key or null if not found
See Also:
VelocityFactory.getVelocityEngine(String)

createVelocityEngine

public VelocityEngine createVelocityEngine(java.lang.String key,
                                           java.util.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.

Specified by:
createVelocityEngine in interface VelocityFactory
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
See Also:
VelocityFactory.createVelocityEngine(String, Properties)


Copyright © 2004-2011 XWiki. All Rights Reserved.