Class ExtensibilityModelImpl

    • Constructor Detail

      • 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 Detail

      • 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.
      • 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.
      • 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
      • getDeferredContent

        public DeferredContentTargetModelElement getDeferredContent​(java.lang.String directiveId,
                                                                    java.lang.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 element of the HTML page which would otherwise not normally be possible because by the time the WebScript is being processed the 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​(java.io.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,
                          java.io.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
        java.io.IOException
      • getAdditionalContentElements

        public java.util.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,
                           java.io.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:
        java.io.IOException
        freemarker.template.TemplateException
      • after

        public void after​(ExtensibilityDirectiveData directiveData)
                   throws freemarker.template.TemplateException,
                          java.io.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:
        java.io.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,
                            java.io.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
        java.io.IOException
      • enterDeferredContentEditMode

        public java.util.List<DeferredContentSourceModelElement> enterDeferredContentEditMode​(org.springframework.extensions.surf.extensibility.impl.ExtensibilityModelImpl.RangeData targetRange,
                                                                                              java.lang.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.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object