Class VelocityMethods


  • public final class VelocityMethods
    extends Object

    A utility class for Velocity-related operations.

    Apache Velocity is a Java-based template engine that provides a template language to reference objects defined in Java code. The one-liners in this class make it easy to parse Velocity templates.

    • Constructor Detail

      • VelocityMethods

        @Autowired
        VelocityMethods​(org.apache.velocity.app.VelocityEngine esbVelocityEngine)
    • Method Detail

      • parse

        public static String parse​(@GloopParameter(allowNull=false)
                                   String template,
                                   @GloopParameter(allowNull=false)
                                   Map<String,​Object> params)

        Parses a Velocity template.

        Example usage:

         def context = [ "firstname": "James", "lastname": "Greg" ]
         def template = 'Hello, $firstname $lastname.'
         def parsedTemplate = template.parse( context );
         assert parsedTemplate.equals( 'Hello, James Greg.' )
         

        A variable called esb is added to the context as well, which can be used to call one-liners from GroovyMethods.

        Parameters:
        template - the template to parse
        params - the context, which contains values which will be mapped to variables used in the template
        Returns:
        evaluated Velocity template
        Since:
        1.0
      • parse

        public static String parse​(String template)

        Parses a Velocity template.

        Example usage:

         def template = 'Hello, world.'
         def parsedTemplate = template.parse();
         assert parsedTemplate.equals( 'Hello, world.' )
         

        Parameters:
        template - the template to parse
        Returns:
        evaluated Velocity template
        Since:
        1.0
      • parse

        public static String parse​(Map params,
                                   Closure<Object> template)

        Parses a Velocity template.

        Example usage:

         def context = [ "firstname": "James", "lastname": "Greg" ]
         def template = { 'Hello, $firstname $lastname.' }
         def parsedTemplate = context.parse( template );
         assert parsedTemplate.equals( 'Hello, James Greg.' )
         

        A variable called esb is added to the context as well, which can be used to call one-liners from GroovyMethods.

        Parameters:
        params - the context, which contains values which will be mapped to variables used in the template
        template - a closure returning the template to parse
        Returns:
        evaluated Velocity template
        Since:
        1.0
      • parse

        public static String parse​(String template,
                                   Closure<Map> params)

        Parses a Velocity template.

        Example usage:

         def context = [ "firstname": "James", "lastname": "Greg" ]
         def template = 'Hello, $firstname $lastname.'
         def parsedTemplate = context.parse( template );
         assert parsedTemplate.equals( 'Hello, James Greg.' )
         

        A variable called esb is added to the context as well, which can be used to call one-liners from GroovyMethods.

        Parameters:
        template - the template to parse
        params - the context, which contains values which will be mapped to variables used in the template
        Returns:
        evaluated Velocity template
        Since:
        1.0
      • parse

        public static String parse​(@GloopParameter(allowNull=false)
                                   String template,
                                   GloopExecutionContext context)

        Parses a Velocity template, using all the variables available in the current Gloop context.

        Parameters:
        template - the template to parse
        context - the Gloop execution context (automatically mapped by Gloop), from which the template context will be derived; the context contains values which will be mapped to variables used in the template
        Returns:
        evaluated Velocity template
        Since:
        1.0
      • parse

        public static String parse​(@GloopParameter(allowNull=false)
                                   String template,
                                   GloopModel context,
                                   GloopExecutionContext gloopExecutionContext)

        Parses a Velocity template, using all the variables available in the current Gloop context, and provided context.

        Parameters:
        template - the template to parse
        context - the context, which contains values which will be mapped to variables used in the template
        gloopExecutionContext - the Gloop execution context (automatically mapped by Gloop), from which the template context will be derived; the context contains values which will be mapped to variables used in the template
        Returns:
        evaluated Velocity template
        Since:
        1.0