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

cn.hutool.extra.template.engine.wit.WitTemplate Maven / Gradle / Ivy

Go to download

Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。

There is a newer version: 5.8.34
Show newest version
package cn.hutool.extra.template.engine.wit;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.extra.template.AbstractTemplate;
import org.febit.wit.Template;

import java.io.OutputStream;
import java.io.Serializable;
import java.io.Writer;
import java.util.Map;

/**
 * Wit模板实现
 *
 * @author looly
 */
public class WitTemplate extends AbstractTemplate implements Serializable{
	private static final long serialVersionUID = 1L;

	private final Template rawTemplate;

	/**
	 * 包装Wit模板
	 *
	 * @param witTemplate Wit的模板对象 {@link Template}
	 * @return WitTemplate
	 */
	public static WitTemplate wrap(Template witTemplate) {
		return (null == witTemplate) ? null : new WitTemplate(witTemplate);
	}

	/**
	 * 构造
	 *
	 * @param witTemplate Wit的模板对象 {@link Template}
	 */
	public WitTemplate(Template witTemplate) {
		this.rawTemplate = witTemplate;
	}

	@Override
	public void render(Map bindingMap, Writer writer) {
		final Map map = Convert.convert(new TypeReference>() {}, bindingMap);
		rawTemplate.merge(map, writer);
	}

	@Override
	public void render(Map bindingMap, OutputStream out) {
		final Map map = Convert.convert(new TypeReference>() {}, bindingMap);
		rawTemplate.merge(map, out);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy