Class ExtensibilityModelImpl

java.lang.Object
org.springframework.extensions.surf.extensibility.impl.ExtensibilityModelImpl
All Implemented Interfaces:
ExtensibilityModel

public class ExtensibilityModelImpl extends Object implements ExtensibilityModel
  • Constructor Details

    • ExtensibilityModelImpl

      public ExtensibilityModelImpl(ExtensibilityModel parentModel, HandlesExtensibility handler)

      Constructor for the model. Accepts a parent model if the new instance is to be nested.

      Parameters:
      parentModel - The parent model (if this instance is to be nested)
      handler - The handler used to create the model.
  • Method Details

    • getParentModel

      public ExtensibilityModel getParentModel()

      Extensibility models can be nested. If the current model is nested then this method will return the model that it is nested within.

      Specified by:
      getParentModel in interface ExtensibilityModel
      Returns:
      The enclosing ExtensibilityModel if the current model is nested and null otherwise.
    • getDebugData

      public ExtensibilityDebugData getDebugData()
      Specified by:
      getDebugData in interface ExtensibilityModel
      Returns:
      The ExtensibilityDebugData associated with the ExtensibilityModel.
    • getChildDebugData

      public ExtensibilityDebugData getChildDebugData()
      Specified by:
      getChildDebugData in interface ExtensibilityModel
      Returns:
      The ExtensibilityDebugData associated with the nested child ExtensibilityModel.
    • setChildDebugData

      public void setChildDebugData(ExtensibilityDebugData childData)
      Description copied from interface: ExtensibilityModel

      Sets the ExtensibilityDebugData associated with the nested child ExtensibilityModel.

      Specified by:
      setChildDebugData in interface ExtensibilityModel
    • isModelStarted

      public boolean isModelStarted()
      Description copied from interface: ExtensibilityModel

      Indicates whether or not the has been started.

      Specified by:
      isModelStarted in interface ExtensibilityModel
      Returns:
      boolean
    • getWriter

      public ModelWriter getWriter()

      Returns the ModelWriter that will be written to when the model is flushed.

      Specified by:
      getWriter in interface ExtensibilityModel
      Returns:
      The ModelWriter used by this ExtensibilityModel
    • switchToExtensionProcessing

      public void switchToExtensionProcessing()

      Switches the model into extension processing mode. This means that content can no longer me appended to the end of the model but directives must be extending the existing model in some way.

      Specified by:
      switchToExtensionProcessing in interface ExtensibilityModel
    • isExtensionProcessing

      public boolean isExtensionProcessing()

      Indicates whether or not extensions are being processed or not.

      Specified by:
      isExtensionProcessing in interface ExtensibilityModel
      Returns:
      true if extensions are being processed or false if the base model is still being created.
    • insertDeferredContentTarget

      public void insertDeferredContentTarget(int index, OpenModelElement open, DeferredContentTargetModelElement target, CloseModelElement close)

      Allows DeferredContentTargetModelElement instances (along with their associated OpenModelElement and CloseModelElement instances) to be inserted at a requested point in the model. This facility should be used with extreme care and was provided to allow WebScripts run outside of the context of a page to process dependencies.

      Specified by:
      insertDeferredContentTarget in interface ExtensibilityModel
      Parameters:
      index - The index within the model to insert the elements
      open - The OpenModelElement that identifies the start of the content
      target - The DeferredContentTargetModelElement for adding deferred content into
      close - The CloseModelElement that identifies the end of the content
    • addUnboundContent

      public void addUnboundContent()

      Adds a new UnboundContentModelElementImpl to the model and sets its content as the current buffer element in the model writer. This will capture any output that is not contained within extensibility directives. Typically unbound content is added before extensibility processing begins and then again once it has completed.

      Specified by:
      addUnboundContent in interface ExtensibilityModel
    • addDiscardContent

      public void addDiscardContent()

      Adds a new DiscardUnboundContentModelElementImpl to the model and sets its content as the current buffer element in the ModelWriter. Any content that is subsequently rendered will effectively be discarded until a new ContentModelElement is added. This allows unbounded content in extending templates to be safely discarded.

      Specified by:
      addDiscardContent in interface ExtensibilityModel
    • getDeferredContent

      public DeferredContentTargetModelElement getDeferredContent(String directiveId, String directiveName)

      Finds and returns the deferred DeferredContentTargetModelElement specified by the supplied directive ID and name. The purpose of a DeferredContentTargetModelElement is to allow nested content to directly manipulate content outside their scope. This has been provided for the purpose of allowing WebScripts to add JavaScript and CSS dependencies into the <head> element of the HTML page which would otherwise not normally be possible because by the time the WebScript is being processed the <head> element would have already been processed.

      This method will only return DeferredContentTargetModelElement objects and not any other type of content added to the model. It will return null if the target content cannot be found.

      Specified by:
      getDeferredContent in interface ExtensibilityModel
      Parameters:
      directiveId - The ID of the deferred content to find
      directiveName - The directive name used to add the deferred content.
      Returns:
      The requested DeferredContentTargetModelElement or null if it couldn't be found.
    • flushModel

      public void flushModel(Writer out)

      Flushes the contents of the model to the supplied output stream. This should be called once extensibility processing has completed.

      Specified by:
      flushModel in interface ExtensibilityModel
      Parameters:
      out - The Writer to flush the model contents to.
    • merge

      public void merge(ExtensibilityDirectiveData directiveData) throws freemarker.template.TemplateException, IOException

      Merges the supplied ExtensibilityDirectiveData instance into the model. The merge action can only be used as part of extension processing when it is not the root action of the extension. For example a <@region> directive can be merged into the model as part of a "before", "after" or "replace" action of an enclosing <@markup> directive. This relies on some additional content elements being created in the model for the new content to be added to.

      Specified by:
      merge in interface ExtensibilityModel
      Parameters:
      directiveData - The ExtensibilityDirectiveData instance to merge into the model.
      Throws:
      freemarker.template.TemplateException
      IOException
    • getAdditionalContentElements

      public List<ExtensibilityModelElement> getAdditionalContentElements()

      Retrieves the current List of ExtensibilityModelElement instances that are being generated as part of extension processing. This List will either exist in the current ExtensibilityModel or somewhere within the model hierarchy. This method will return null if no List has been instantiated - this typically means that an extension has been created in error. Normally because a "merge" action has been requested as the root extension action.

      Specified by:
      getAdditionalContentElements in interface ExtensibilityModel
      Returns:
      List
    • before

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

      Generates the output from the supplied directive data and inserts it into the model at the index before the start of the target defined in the directive. If the target directive cannot be found then the generated output is not inserted into the model.

      WARNING: The content will also not be added if the model has not been switched into extension processing mode as it is not valid for a model declaring template to manipulate its own contents.

      Specified by:
      before in interface ExtensibilityModel
      Parameters:
      directiveData - ExtensibilityDirectiveData
      Throws:
      IOException
      freemarker.template.TemplateException
    • after

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

      Generates the output from the supplied directive data and inserts it into the model at the index after the end of the target defined in the directive. If the target directive cannot be found then the generated output is not inserted into the model.

      WARNING: The content will also not be added if the model has not been switched into extension processing mode as it is not valid for a model declaring template to manipulate its own contents.

      Specified by:
      after in interface ExtensibilityModel
      Parameters:
      directiveData - ExtensibilityDirectiveData
      Throws:
      IOException
      freemarker.template.TemplateException
    • remove

      public void remove(ExtensibilityDirectiveData directiveData)

      Finds the elements in the model that match the range (including all nested and unbound content) with the specified id parameter and removes them.

      Specified by:
      remove in interface ExtensibilityModel
      Parameters:
      directiveData - The id of the range of elements to remove
    • replace

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

      Replaces the elements of the content model within the range defined by the id of the supplied directive with the output generated by rendering the supplied TemplateDirectiveBody.

      Specified by:
      replace in interface ExtensibilityModel
      Parameters:
      directiveData - The directive requesting to replace the existing elements with the same id
      Throws:
      freemarker.template.TemplateException
      IOException
    • enterDeferredContentEditMode

      public List<DeferredContentSourceModelElement> enterDeferredContentEditMode(org.springframework.extensions.surf.extensibility.impl.ExtensibilityModelImpl.RangeData targetRange, String action)

      Iterates over the supplied RangeData object and calls the enterEditMode method on any DeferredContentSourceModelElement instances that are found within it. This allows deferred content to be manipulated when extensions are applied to it. For example - deferred content may have already been set which needs to be replaced.

      Parameters:
      targetRange - The range of elements that need to be checked for DeferredContentSourceModelElement instances
      action - The name of the action being processed
      Returns:
      A List of the DeferredContentSourceModelElement instances found - this is returned as the range is likely to be cleared.
    • exitDeferredContentEditMode

      public void exitDeferredContentEditMode(List<DeferredContentSourceModelElement> deferredSourceElements)

      Iterates over the supplied RangeData object and calls the exitEditMode method on any DeferredContentSourceModelElement instances that are found within it. This indicates to the associated DeferredContentTargetModelElement instance that editing is now finished.

      Parameters:
      deferredSourceElements - List
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • findContentModelElement

      public ContentModelElement findContentModelElement(String id)
      Description copied from interface: ExtensibilityModel

      Finds a specific ContentModelElement (with the supplied identifier) in the model.

      Specified by:
      findContentModelElement in interface ExtensibilityModel
      Parameters:
      id - String
      Returns:
      ContentModelElement
    • clearRelocatedContent

      public boolean clearRelocatedContent(String id, String directiveName)
      Specified by:
      clearRelocatedContent in interface ExtensibilityModel