org.thymeleaf.model.IModel Maven / Gradle / Ivy
Show all versions of thymeleaf Show documentation
/*
* =============================================================================
*
* Copyright (c) 2011-2018, 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.model;
import java.io.IOException;
import java.io.Writer;
import org.thymeleaf.IEngineConfiguration;
import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.templatemode.TemplateMode;
/**
*
* Interface representing all model objects.
*
*
* Models are sequences of events ({@link ITemplateEvent}) normally representing a specific element
* with all its body and nested elements, or even an entire document.
*
*
* {@link IModel} implementations are the classes used at the template engine for representing
* templates or fragments.
*
*
* From the user's code (e.g. custom processors), implementations of {@link IModel} are created using an
* {@link IModelFactory}, obtained from {@link ITemplateContext#getModelFactory()}.
*
*
* @author Daniel Fernández
* @see org.thymeleaf.engine.TemplateModel
* @see IModelFactory
* @see org.thymeleaf.processor.element.IElementModelProcessor
* @since 3.0.0
*
*/
public interface IModel {
/**
*
* Returns the engine configuration that was used for creating this model.
*
*
* @return the engine configuration.
*/
public IEngineConfiguration getConfiguration();
/**
*
* Returns the template mode used for creating this model.
*
*
* @return the template mode.
*/
public TemplateMode getTemplateMode();
/**
*
* The size of the model (number of {@link ITemplateEvent} objects contained).
*
*
* @return the size of the model.
*/
public int size();
/**
*
* Retrieves a specific event from the model sequence.
*
*
* @param pos the position (zero-based) of the event to be retrieved.
* @return the retrieved event.
*/
public ITemplateEvent get(final int pos);
/**
*
* Adds an event at the end of the sequence.
*
*
* @param event the event to be added.
*/
public void add(final ITemplateEvent event);
/**
*
* Inserts an event into a specific position in the sequence.
*
*
* @param pos the position to insert the event (zero-based).
* @param event the event to be inserted.
*/
public void insert(final int pos, final ITemplateEvent event);
/**
*
* Replaces the event at the specified position with the one passed
* as argument.
*
*
* @param pos the position of the event to be replaced (zero-based).
* @param event the event to serve as replacement.
*/
public void replace(final int pos, final ITemplateEvent event);
/**
*
* Add an entire model at the end of the sequence. This effectively appends the
* {@code model} argument's sequence to this one.
*
*
* @param model the model to be appended.
*/
public void addModel(final IModel model);
/**
*
* Inserts an entire model into a specific position in this model's sequence.
*
*
* @param pos the position to insert the mdoel (zero-based).
* @param model the model to be inserted.
*/
public void insertModel(final int pos, final IModel model);
/**
*
* Remove an event from the sequence.
*
*
* @param pos the position (zero-based) of the event to be removed.
*/
public void remove(final int pos);
/**
*
* Remove all events from the model sequence.
*
*/
public void reset();
/**
*
* Clones the model and all its events.
*
*
* @return the new model.
*/
public IModel cloneModel();
/**
*
* Accept a visitor implementing {@link IModelVisitor}. This visitor will be executed
* for each event in the sequence.
*
*
* @param visitor the visitor object.
*/
public void accept(final IModelVisitor visitor);
/**
*
* Write this model (its events) through the specified writer.
*
*
* @param writer the writer that will be used for writing the model.
* @throws IOException should any exception happen.
*/
public void write(final Writer writer) throws IOException;
}