Class VelTemplate


  • public class VelTemplate
    extends Object

    Provides a Apache Velocity templating class.

    Examples

    Email Template from Service Parameter

    Provides an example creating an email body message using a Velocity template provided as a service parameter.

     import com.avoka.tm.util.*
    
     String emailTemplate = svcDef.paramsMap["emailTemplate"]
     User user = ...
    
     String emailMessage  = new VelTemplate()
          .setTemplate(emailTemplate)
          .addModelValue("user", user)
          .merge() 

    Email Template from Organization Property

    Provides an example creating an email body message using a Velocity template provided from an Organization property.

     import com.avoka.tm.query.*
     import com.avoka.tm.util.*
    
     String emailTemplate = new PropertyQuery()
          .setName("HTML Email Welcome")
          .setClientCode("maguire")
          .getValue()
    
     User user = ...
    
     String emailMessage  = new VelTemplate()
          .setTemplate(emailTemplate)
          .addModelValue("user", user)
          .merge() 
    Since:
    5.0.0
    See Also:
    PropertyQuery
    • Constructor Detail

      • VelTemplate

        public VelTemplate()
    • Method Detail

      • setTemplate

        public VelTemplate setTemplate​(String template)
        Set the Velocity template value.
        Parameters:
        template - the velocity template value
        Returns:
        the vel template
      • setModel

        public VelTemplate setModel​(Map<String,​Object> model)
        Set the model value to merge with the template.
        Parameters:
        model - the model value to merge with the template (required)
        Returns:
        the vel template
      • addModelValue

        public VelTemplate addModelValue​(String key,
                                         Object value)
        Set the model key and value to merge with the template.
        Parameters:
        key - the model key to add (required)
        value - the model value to add (required)
        Returns:
        the vel template
      • merge

        public String merge()
        Merge the velocity template with the model and return the evaluated text value.
        Returns:
        the evaluated text value from merging the Velocity template with the model