Class AbstractExtensibilityDirective

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

    public abstract class AbstractExtensibilityDirective
    extends AbstractFreeMarkerDirective
    implements ExtensibilityDirective

    Defines the abstract behaviour of an extensibility directive by implementing the common structure. An extensibility directive has the following attributes:

    • id: The identifier of the directive to declare or modify
    • action: The action to before (merge is the implicit default action)
    • target: The identifier of the directive that some actions use as a relative target (i.e. when adding new content)
    The basic actions defined are:
    • merge: Merges content into the model
    • remove: Removes content from the model
    • replace: Replaces content in the model
    • modify: Modifies existing content in the model
    • before: Places new content before existing content in the model
    • after: Places new content after existing content in the model
    The class has been structured so that concrete directive implementations can modify the default action behaviour easily.

    Author:
    David Draper
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void after​(ExtensibilityDirectiveData directiveData)
      The default implementation of this action is simply to delegate the request to the ExtensibilityModel.after() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.
      void before​(ExtensibilityDirectiveData directiveData)
      The default implementation of this action is simply to delegate the request to the ExtensibilityModel.before() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.
      ExtensibilityDirectiveData createExtensibilityDirectiveData​(java.lang.String id, java.lang.String action, java.lang.String target, java.util.Map params, freemarker.template.TemplateDirectiveBody body, freemarker.core.Environment env)
      Creates and returns a DefaultExtensibilityDirectiveData object containing the primary data needed for processing the current directive invocation.
      void execute​(freemarker.core.Environment env, java.util.Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body)  
      java.lang.String getId()  
      ExtensibilityModel getModel()  
      void merge​(ExtensibilityDirectiveData directiveData, java.util.Map<java.lang.String,​java.lang.Object> params)
      Merges the output of directive data into the content model.
      void remove​(ExtensibilityDirectiveData directiveData)
      The default implementation of this action is simply to delegate the request to the ExtensibilityModel.remove() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.
      void replace​(ExtensibilityDirectiveData directiveData)
      The default implementation of this action is simply to delegate the request to the ExtensibilityModel.replace() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractExtensibilityDirective

        public AbstractExtensibilityDirective​(java.lang.String directiveName,
                                              ExtensibilityModel model)
        Requires a DirectiveModel to contribute to.
        Parameters:
        directiveName - String
        model - ExtensibilityModel
    • Method Detail

      • getId

        public java.lang.String getId()
      • createExtensibilityDirectiveData

        public ExtensibilityDirectiveData createExtensibilityDirectiveData​(java.lang.String id,
                                                                           java.lang.String action,
                                                                           java.lang.String target,
                                                                           java.util.Map params,
                                                                           freemarker.template.TemplateDirectiveBody body,
                                                                           freemarker.core.Environment env)
                                                                    throws freemarker.template.TemplateException

        Creates and returns a DefaultExtensibilityDirectiveData object containing the primary data needed for processing the current directive invocation. This object is required when building the model because TemplateDirectiveModel instances are re-used so the data assigned to them is volatile.

        Extending classes implementing concrete directives should choose to override this method if the directive being defined requires additional data or needs to instantiate different ContentModelElement instances in order to provide more advance content processing.

        Parameters:
        id - The id of the current directive invocation
        action - The action of the current directive invocation
        target - The target of the current directive invocation (this could be null)
        params - The parameters used by the directive invocation.
        body - The TemplateDirectiveBody of the current directive invocation.
        env - The current FreeMarker template Environment
        Returns:
        A new DefaultExtensibilityDirectiveData object containing the data supplied as parameters to the method call.
        Throws:
        freemarker.template.TemplateException
      • execute

        public void execute​(freemarker.core.Environment env,
                            java.util.Map params,
                            freemarker.template.TemplateModel[] loopVars,
                            freemarker.template.TemplateDirectiveBody body)
                     throws freemarker.template.TemplateException,
                            java.io.IOException
        Specified by:
        execute in interface freemarker.template.TemplateDirectiveModel
        Throws:
        freemarker.template.TemplateException
        java.io.IOException
      • merge

        public void merge​(ExtensibilityDirectiveData directiveData,
                          java.util.Map<java.lang.String,​java.lang.Object> params)
                   throws freemarker.template.TemplateException,
                          java.io.IOException

        Merges the output of directive data into the content model.

        The default implementation of this action is simply to delegate the request to the ExtensibilityModel.merge() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.

        Parameters:
        directiveData - ExtensibilityDirectiveData
        params - Map
        Throws:
        freemarker.template.TemplateException
        java.io.IOException
      • before

        public void before​(ExtensibilityDirectiveData directiveData)
                    throws freemarker.template.TemplateException,
                           java.io.IOException

        The default implementation of this action is simply to delegate the request to the ExtensibilityModel.before() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.

        Parameters:
        directiveData - ExtensibilityDirectiveData
        Throws:
        freemarker.template.TemplateException
        java.io.IOException
      • after

        public void after​(ExtensibilityDirectiveData directiveData)
                   throws freemarker.template.TemplateException,
                          java.io.IOException

        The default implementation of this action is simply to delegate the request to the ExtensibilityModel.after() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.

        Parameters:
        directiveData - ExtensibilityDirectiveData
        Throws:
        freemarker.template.TemplateException
        java.io.IOException
      • remove

        public void remove​(ExtensibilityDirectiveData directiveData)
                    throws freemarker.template.TemplateException,
                           java.io.IOException

        The default implementation of this action is simply to delegate the request to the ExtensibilityModel.remove() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.

        Parameters:
        directiveData - ExtensibilityDirectiveData
        Throws:
        freemarker.template.TemplateException
        java.io.IOException
      • replace

        public void replace​(ExtensibilityDirectiveData directiveData)
                     throws freemarker.template.TemplateException,
                            java.io.IOException

        The default implementation of this action is simply to delegate the request to the ExtensibilityModel.replace() method but this has been abstracted into its own method so that extending directives can easily modify the default behaviour of this action.

        Parameters:
        directiveData - ExtensibilityDirectiveData
        Throws:
        freemarker.template.TemplateException
        java.io.IOException