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

org.mybatis.scripting.thymeleaf.TemplateEngineCustomizer Maven / Gradle / Ivy

The newest version!
/*
 *    Copyright 2018-2022 the original author or authors.
 *
 *    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
 *
 *       https://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.mybatis.scripting.thymeleaf;

import java.util.Optional;
import java.util.function.Consumer;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.templateresolver.ITemplateResolver;

/**
 * The interface for customizing a default {@code TemplateEngine} instanced by the MyBatis Thymeleaf. 
* If you want to customize a default {@code TemplateEngine}, you implements class of this interface and you need to * specify the 'customizer' property of mybatis-thymeleaf.properties.
*
* e.g.) Implementation class: * *
 * package com.example;
 *
 * // ...
 * public class MyTemplateEngineCustomizer implements TemplateEngineCustomizer {
 *   public void customize(TemplateEngine defaultTemplateEngine) {
 *     // ...
 *   }
 * }
 * 
* *
* e.g.) Configuration file (mybatis-thymeleaf.properties): * *
 * customizer = com.example.MyTemplateEngineCustomizer
 * 
* * @author Kazuki Shimizu * * @version 1.0.0 */ @FunctionalInterface public interface TemplateEngineCustomizer extends Consumer { /** * {@inheritDoc} * * @see #customize(TemplateEngine) */ @Override default void accept(TemplateEngine templateEngine) { customize(templateEngine); } /** * Customize a default {@code TemplateEngine} instanced by the MyBatis Thymeleaf. * * @param defaultTemplateEngine * a default {@code TemplateEngine} instanced by the MyBatis Thymeleaf */ void customize(TemplateEngine defaultTemplateEngine); /** * Utility method to extract a {@code ITemplateResolver} that implements specified type. * * @param templateEngine * A target {@code TemplateEngine} * @param type * A target type for extracting instance * @param * A type that implements the {@code ITemplateResolver} * * @return A {@code ITemplateResolver} instance that implements specified type */ static Optional extractTemplateResolver(TemplateEngine templateEngine, Class type) { return templateEngine.getTemplateResolvers().stream().filter(type::isInstance).map(type::cast).findFirst(); } /** * Enum for providing builtin customizer instance. * * @since 1.0.0 */ enum BuiltIn implements TemplateEngineCustomizer { /** * Default instance. *

* This customizer instance do nothing. *

*/ DO_NOTHING { @Override public void customize(TemplateEngine defaultTemplateEngine) { // NOP } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy