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
IModel
object that contains the complete sequence of events that models such element and its contents.Reading and modifying the model
The
IModel
object 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
IModel
interface includes anIModel.accept(IModelVisitor)
method, useful for traversing an entire model looking for specific nodes or relevant data the Visitor pattern.Using the
structureHandler
Model 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
IModel
model object itself.See the documentation for
IElementModelStructureHandler
for 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 void
process(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
IModel
object 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 theIElementModelStructureHandler
handler.- 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.
-
-