All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.thymeleaf.processor.element.IElementModelProcessor Maven / Gradle / Ivy

Go to download

Modern server-side Java template engine for both web and standalone environments

There is a newer version: 3.1.3.RELEASE
Show newest version
/*
 * =============================================================================
 * 
 *   Copyright (c) 2011-2016, The THYMELEAF team (http://www.thymeleaf.org)
 * 
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 * =============================================================================
 */
package org.thymeleaf.processor.element;

import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.model.IModel;
import org.thymeleaf.model.IModelVisitor;

/**
 * 

* 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 {@link IModel} object that contains the complete sequence of events that models such * element and its contents. *

*

* Reading and modifying the model *

*

* The {@link IModel} object passed as a parameter to the * {@link #process(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 {@link IModel} interface includes an {@link IModel#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 {@link IModel} model object itself. *

*

* See the documentation for {@link IElementModelStructureHandler} for more info. *

*

* Abstract implementations *

*

* Two basic abstract implementations of this interface are offered: *

*
    *
  • {@link AbstractElementModelProcessor}, meant for processors that match element events by their element * name (i.e. without looking at any attributes).
  • *
  • {@link AbstractAttributeModelProcessor}, meant for processors that match element events by one of their * attributes (and optionally also the element name).
  • *
* * @author Daniel Fernández * @see AbstractElementModelProcessor * @see AbstractAttributeModelProcessor * @see IElementModelStructureHandler * @since 3.0.0 * */ public interface IElementModelProcessor extends IElementProcessor { /** *

* Execute the processor. *

*

* The {@link 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 the {@link IElementModelStructureHandler} handler. *

* * @param context the execution context. * @param model the model this processor is executing on. * @param structureHandler the handler that will centralise modifications and commands to the engine. */ public void process( final ITemplateContext context, final IModel model, final IElementModelStructureHandler structureHandler); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy