Interface IElementModelProcessor
-
- All Superinterfaces:
IElementProcessor,IProcessor
- All Known Implementing Classes:
AbstractAttributeModelProcessor,AbstractElementModelProcessor
public interface IElementModelProcessor extends IElementProcessor
Interface to be implemented by all element model processors.
Processors of this kind are executed on the entire elements they match --including their bodies--, in the form of an
IModelobject that contains the complete sequence of events that models such element and its contents.Reading and modifying the model
The
IModelobject passed as a parameter to theprocess(ITemplateContext, IModel, IElementModelStructureHandler)method is mutable, so it allows any modifications to be done on it. For example, we might want to modify it so that we replace every text node from its body with a comment with the same contents:final IModelFactory modelFactory = context.getModelFactory();
int n = model.size();
while (n-- != 0) {
final ITemplateEvent event = model.get(n);
if (event instanceof IText) {
final IComment comment =
modelFactory.createComment(((IText)event).getText());
model.insert(n, comment);
model.remove(n + 1);
}
}
Note also that the
IModelinterface includes anIModel.accept(IModelVisitor)method, useful for traversing an entire model looking for specific nodes or relevant data the Visitor pattern.Using the
structureHandlerModel processors are passed a structure handler object that allows them to instruct the engine to take any actions that cannot be done by directly acting on the
IModelmodel object itself.See the documentation for
IElementModelStructureHandlerfor more info.Abstract implementations
Two basic abstract implementations of this interface are offered:
AbstractElementModelProcessor, meant for processors that match element events by their element name (i.e. without looking at any attributes).AbstractAttributeModelProcessor, meant for processors that match element events by one of their attributes (and optionally also the element name).
- Since:
- 3.0.0
- Author:
- Daniel Fernández
- See Also:
AbstractElementModelProcessor,AbstractAttributeModelProcessor,IElementModelStructureHandler
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidprocess(ITemplateContext context, IModel model, IElementModelStructureHandler structureHandler)Execute the processor.-
Methods inherited from interface org.thymeleaf.processor.element.IElementProcessor
getMatchingAttributeName, getMatchingElementName
-
Methods inherited from interface org.thymeleaf.processor.IProcessor
getPrecedence, getTemplateMode
-
-
-
-
Method Detail
-
process
void process(ITemplateContext context, IModel model, IElementModelStructureHandler structureHandler)
Execute the processor.
The
IModelobject represents the section of template (a fragment) on which the processor is executing, and can be directly modified. Instructions to be given to the template engine such as local variable creation, inlining etc. should be done via theIElementModelStructureHandlerhandler.- Parameters:
context- the execution context.model- the model this processor is executing on.structureHandler- the handler that will centralise modifications and commands to the engine.
-
-