Class AbstractFreeMarkerDirective

  • All Implemented Interfaces:
    freemarker.template.TemplateDirectiveModel, freemarker.template.TemplateModel
    Direct Known Subclasses:
    AbstractExtensibilityDirective

    public abstract class AbstractFreeMarkerDirective
    extends java.lang.Object
    implements freemarker.template.TemplateDirectiveModel

    Should be extended to take advantage of the helper methods it provides for retrieving properties required for the directive represented by the subclass. Extending this class and using the helper methods will prevent unnecessary duplication of code.

    The helper methods provided are initially for finding properties and ensuring that they are of the expected type, although more methods could be provided in the future.

    Author:
    David Draper
    • Field Summary

      • Fields inherited from interface freemarker.template.TemplateModel

        NOTHING
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractFreeMarkerDirective​(java.lang.String directiveName)
      This constructor will need to invoked by subclasses and ensures that a directive name is provided.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean getBooleanProperty​(java.util.Map<java.lang.String,​java.lang.Object> params, java.lang.String targetProp, boolean required)
      Attempts to retrieve a boolean property from the map of parameters supplied using the key provided.
      java.lang.String getDirectiveName()  
      protected java.lang.String getStringProperty​(java.util.Map<java.lang.String,​java.lang.Object> params, java.lang.String targetProp, boolean required)
      Attempts to retrieve a String property from the map of parameters supplied using the key provided.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface freemarker.template.TemplateDirectiveModel

        execute
    • Constructor Detail

      • AbstractFreeMarkerDirective

        public AbstractFreeMarkerDirective​(java.lang.String directiveName)

        This constructor will need to invoked by subclasses and ensures that a directive name is provided. The directive name is used in exception messages to assist debugging.

        Parameters:
        directiveName - The name of the directive represented by the subclass.
    • Method Detail

      • getDirectiveName

        public java.lang.String getDirectiveName()
      • getStringProperty

        protected java.lang.String getStringProperty​(java.util.Map<java.lang.String,​java.lang.Object> params,
                                                     java.lang.String targetProp,
                                                     boolean required)
                                              throws freemarker.template.TemplateModelException

        Attempts to retrieve a String property from the map of parameters supplied using the key provided.

        • If a property is found but it is not a String then an exception will be thrown.
        • If a property is not found and not required then null will be returned.
        • If a property is not found and is required then an exception will be thrown

        Parameters:
        params - A map of parameters (this is supplied to the execute method that must be implemented by subclasses.
        targetProp - The name of the property to attempt to retrieve.
        required - Indicates whether or not the property is required for the directive to process successfully.
        Returns:
        A String value for the property name supplied (or null if it could not be found)
        Throws:
        freemarker.template.TemplateModelException - When a property matching the supplied name is found but is not a String.
      • getBooleanProperty

        protected boolean getBooleanProperty​(java.util.Map<java.lang.String,​java.lang.Object> params,
                                             java.lang.String targetProp,
                                             boolean required)
                                      throws freemarker.template.TemplateModelException

        Attempts to retrieve a boolean property from the map of parameters supplied using the key provided.

        • If a property is found but it is not a boolean then an exception will be thrown.
        • If a property is not found and not required then false will be returned.
        • If a property is not found and is required then an exception will be thrown

        Parameters:
        params - A map of parameters (this is supplied to the execute method that must be implemented by subclasses.
        targetProp - The name of the property to attempt to retrieve.
        required - Indicates whether or not the property is required for the directive to process successfully.
        Returns:
        A boolean value for the property name supplied (or false if it could not be found)
        Throws:
        freemarker.template.TemplateModelException - When a property matching the supplied name is found but is not a boolean.