---
title: "Light-Commons 加入 Template Facade"
author: "jasongreen"
date: "2008-06-18T00:33:54Z"
tags: ["ASP", "JSP", "Java", "commontemplate", "freemarker"]
categories: ["企业架构"]
slug: "light-commons-template-facade"
draft: false
lastmod: "2008-06-18T00:33:54Z"
id: 204960
url: "https://jasongreen.iteye.com/blog/204960"
---

template 个人认为是web的精髓，如今看来JSP，ASP也都可列为模板范畴，但*SP无疑是失败的，个人观点。

模板+数据=输出，所有模板引擎都是如此，light-commons 试图为流行模板提供统一的接口。目前实现了Freemarker,Commontemplate的Facade.

对于代码开发而言，所需要关心的只有Template,TemplateFactory，剩下的就是了解模板语言。


```java

public interface Template {
	String render(Object rootMap);

	void render(Object rootMap, Writer writer);
}
```




```java

public interface TemplateFactory {
	Template compile(String name,String source) throws IOException;

	Template getTemplate(String location,String encoding) throws Exception;
	
	Template getTemplate(String location,Locale local,String encoding) throws Exception;
	
	Template getTemplate(String name,InputStream inputStream, String encoding) throws IOException;

	Template getTemplate(Resource resource, String encoding) throws Exception;
	
	void setResourceLoader(ResourceLoader resourceLoader);
}
```