Interface VelocityFactory


  • @Role
    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: 9de513efd38f3a0c49d237e694765ef06fe37538 $
    • 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.
        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
      • removeVelocityEngine

        VelocityEngine removeVelocityEngine​(String key)
        Remove from the cache a 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
        Since:
        6.4M1