Class ExtensibilityModelImpl
- All Implemented Interfaces:
ExtensibilityModel
-
Constructor Summary
ConstructorsConstructorDescriptionExtensibilityModelImpl(ExtensibilityModel parentModel, HandlesExtensibility handler) Constructor for the model. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a newDiscardUnboundContentModelElementImplto the model and sets its content as the current buffer element in theModelWriter.voidAdds a newUnboundContentModelElementImplto the model and sets its content as the current buffer element in the model writer.voidafter(ExtensibilityDirectiveData directiveData) 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.voidbefore(ExtensibilityDirectiveData directiveData) 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.booleanclearRelocatedContent(String id, String directiveName) enterDeferredContentEditMode(org.springframework.extensions.surf.extensibility.impl.ExtensibilityModelImpl.RangeData targetRange, String action) Iterates over the suppliedRangeDataobject and calls theenterEditModemethod on anyDeferredContentSourceModelElementinstances that are found within it.voidexitDeferredContentEditMode(List<DeferredContentSourceModelElement> deferredSourceElements) Iterates over the suppliedRangeDataobject and calls theexitEditModemethod on anyDeferredContentSourceModelElementinstances that are found within it.Finds a specificContentModelElement(with the supplied identifier) in the model.voidflushModel(Writer out) Flushes the contents of the model to the supplied output stream.Retrieves the currentListofExtensibilityModelElementinstances that are being generated as part of extension processing.getDeferredContent(String directiveId, String directiveName) Finds and returns the deferredDeferredContentTargetModelElementspecified by the supplied directive ID and name.Extensibility models can be nested.Returns theModelWriterthat will be written to when the model is flushed.voidinsertDeferredContentTarget(int index, OpenModelElement open, DeferredContentTargetModelElement target, CloseModelElement close) AllowsDeferredContentTargetModelElementinstances (along with their associatedOpenModelElementandCloseModelElementinstances) to be inserted at a requested point in the model.booleanIndicates whether or not extensions are being processed or not.booleanIndicates whether or not the has been started.voidmerge(ExtensibilityDirectiveData directiveData) Merges the suppliedExtensibilityDirectiveDatainstance into the model.voidremove(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.voidreplace(ExtensibilityDirectiveData directiveData) 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 suppliedTemplateDirectiveBody.voidsetChildDebugData(ExtensibilityDebugData childData) Sets theExtensibilityDebugDataassociated with the nested childExtensibilityModel.voidSwitches the model into extension processing mode.toString()
-
Constructor Details
-
ExtensibilityModelImpl
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
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:
getParentModelin interfaceExtensibilityModel- Returns:
- The enclosing
ExtensibilityModelif the current model is nested andnullotherwise.
-
getDebugData
- Specified by:
getDebugDatain interfaceExtensibilityModel- Returns:
- The
ExtensibilityDebugDataassociated with theExtensibilityModel.
-
getChildDebugData
- Specified by:
getChildDebugDatain interfaceExtensibilityModel- Returns:
- The
ExtensibilityDebugDataassociated with the nested childExtensibilityModel.
-
setChildDebugData
Description copied from interface:ExtensibilityModelSets the
ExtensibilityDebugDataassociated with the nested childExtensibilityModel.- Specified by:
setChildDebugDatain interfaceExtensibilityModel
-
isModelStarted
public boolean isModelStarted()Description copied from interface:ExtensibilityModelIndicates whether or not the has been started.
- Specified by:
isModelStartedin interfaceExtensibilityModel- Returns:
- boolean
-
getWriter
Returns the
ModelWriterthat will be written to when the model is flushed.- Specified by:
getWriterin interfaceExtensibilityModel- Returns:
- The
ModelWriterused by thisExtensibilityModel
-
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:
switchToExtensionProcessingin interfaceExtensibilityModel
-
isExtensionProcessing
public boolean isExtensionProcessing()Indicates whether or not extensions are being processed or not.
- Specified by:
isExtensionProcessingin interfaceExtensibilityModel- Returns:
trueif extensions are being processed orfalseif the base model is still being created.
-
insertDeferredContentTarget
public void insertDeferredContentTarget(int index, OpenModelElement open, DeferredContentTargetModelElement target, CloseModelElement close) Allows
DeferredContentTargetModelElementinstances (along with their associatedOpenModelElementandCloseModelElementinstances) 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:
insertDeferredContentTargetin interfaceExtensibilityModel- Parameters:
index- The index within the model to insert the elementsopen- TheOpenModelElementthat identifies the start of the contenttarget- TheDeferredContentTargetModelElementfor adding deferred content intoclose- TheCloseModelElementthat identifies the end of the content
-
addUnboundContent
public void addUnboundContent()Adds a new
UnboundContentModelElementImplto 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:
addUnboundContentin interfaceExtensibilityModel
-
addDiscardContent
public void addDiscardContent()Adds a new
DiscardUnboundContentModelElementImplto the model and sets its content as the current buffer element in theModelWriter. Any content that is subsequently rendered will effectively be discarded until a newContentModelElementis added. This allows unbounded content in extending templates to be safely discarded.- Specified by:
addDiscardContentin interfaceExtensibilityModel
-
getDeferredContent
public DeferredContentTargetModelElement getDeferredContent(String directiveId, String directiveName) Finds and returns the deferred
DeferredContentTargetModelElementspecified by the supplied directive ID and name. The purpose of aDeferredContentTargetModelElementis 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
DeferredContentTargetModelElementobjects and not any other type of content added to the model. It will returnnullif the target content cannot be found.- Specified by:
getDeferredContentin interfaceExtensibilityModel- Parameters:
directiveId- The ID of the deferred content to finddirectiveName- The directive name used to add the deferred content.- Returns:
- The requested
DeferredContentTargetModelElementornullif it couldn't be found.
-
flushModel
Flushes the contents of the model to the supplied output stream. This should be called once extensibility processing has completed.
- Specified by:
flushModelin interfaceExtensibilityModel- Parameters:
out- TheWriterto flush the model contents to.
-
merge
public void merge(ExtensibilityDirectiveData directiveData) throws freemarker.template.TemplateException, IOException Merges the supplied
ExtensibilityDirectiveDatainstance 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:
mergein interfaceExtensibilityModel- Parameters:
directiveData- TheExtensibilityDirectiveDatainstance to merge into the model.- Throws:
freemarker.template.TemplateExceptionIOException
-
getAdditionalContentElements
Retrieves the current
ListofExtensibilityModelElementinstances that are being generated as part of extension processing. ThisListwill either exist in the currentExtensibilityModelor somewhere within the model hierarchy. This method will returnnullif noListhas 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:
getAdditionalContentElementsin interfaceExtensibilityModel- 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:
beforein interfaceExtensibilityModel- Parameters:
directiveData- ExtensibilityDirectiveData- Throws:
IOExceptionfreemarker.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:
afterin interfaceExtensibilityModel- Parameters:
directiveData- ExtensibilityDirectiveData- Throws:
IOExceptionfreemarker.template.TemplateException
-
remove
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:
removein interfaceExtensibilityModel- 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:
replacein interfaceExtensibilityModel- Parameters:
directiveData- The directive requesting to replace the existing elements with the same id- Throws:
freemarker.template.TemplateExceptionIOException
-
enterDeferredContentEditMode
public List<DeferredContentSourceModelElement> enterDeferredContentEditMode(org.springframework.extensions.surf.extensibility.impl.ExtensibilityModelImpl.RangeData targetRange, String action) Iterates over the supplied
RangeDataobject and calls theenterEditModemethod on anyDeferredContentSourceModelElementinstances 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 forDeferredContentSourceModelElementinstancesaction- The name of the action being processed- Returns:
- A
Listof theDeferredContentSourceModelElementinstances found - this is returned as the range is likely to be cleared.
-
exitDeferredContentEditMode
public void exitDeferredContentEditMode(List<DeferredContentSourceModelElement> deferredSourceElements) Iterates over the supplied
RangeDataobject and calls theexitEditModemethod on anyDeferredContentSourceModelElementinstances that are found within it. This indicates to the associatedDeferredContentTargetModelElementinstance that editing is now finished.- Parameters:
deferredSourceElements- List
-
toString
-
findContentModelElement
Description copied from interface:ExtensibilityModelFinds a specific
ContentModelElement(with the supplied identifier) in the model.- Specified by:
findContentModelElementin interfaceExtensibilityModel- Parameters:
id- String- Returns:
- ContentModelElement
-
clearRelocatedContent
- Specified by:
clearRelocatedContentin interfaceExtensibilityModel
-