Class AbstractExtensibilityDirective

java.lang.Object
org.springframework.extensions.surf.extensibility.impl.AbstractFreeMarkerDirective
org.springframework.extensions.surf.extensibility.impl.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
  • Constructor Details

    • AbstractExtensibilityDirective

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

    • getId

      public String getId()
    • getModel

      public ExtensibilityModel getModel()
    • createExtensibilityDirectiveData

      public ExtensibilityDirectiveData createExtensibilityDirectiveData(String id, String action, String target, 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, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException
      Specified by:
      execute in interface freemarker.template.TemplateDirectiveModel
      Throws:
      freemarker.template.TemplateException
      IOException
    • merge

      public void merge(ExtensibilityDirectiveData directiveData, Map<String,Object> params) throws freemarker.template.TemplateException, 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<String, Object>
      Throws:
      freemarker.template.TemplateException
      IOException
    • before

      public void before(ExtensibilityDirectiveData directiveData) throws freemarker.template.TemplateException, 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
      IOException
    • after

      public void after(ExtensibilityDirectiveData directiveData) throws freemarker.template.TemplateException, 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
      IOException
    • remove

      public void remove(ExtensibilityDirectiveData directiveData) throws freemarker.template.TemplateException, 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
      IOException
    • replace

      public void replace(ExtensibilityDirectiveData directiveData) throws freemarker.template.TemplateException, 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
      IOException