
org.xidea.lite.LiteEngine Maven / Gradle / Ivy
package org.xidea.lite;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Writer;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xidea.el.json.JSONDecoder;
public class LiteEngine implements TemplateEngine {
private static final Log log = LogFactory.getLog(LiteEngine.class);
protected URI compiledBase;
/**
* WeakHashMap 回收的太快了?
*/
protected Map templateMap = new java.util.WeakHashMap();
protected ExecutorService executorService = Executors.newScheduledThreadPool(8);//最多允许是个并发写装载的lazy_widget
protected LiteEngine() {
}
public LiteEngine(URI compiledBase) {
if (compiledBase != null) {
this.compiledBase = compiledBase.normalize();
}
}
public void render(String path, Object context, Writer out)
throws IOException {
getTemplate(path).render(context, out);
out.flush();
}
public Template getTemplate(String path) throws IOException {
Template template = templateMap.get(path);
if (template == null) {
template = createTemplate(path);
templateMap.put(path, template);
return template;
} else {
return template;
}
}
public void clear(String path) {
templateMap.remove(path);
}
@SuppressWarnings("unchecked")
protected Template createTemplate(String path) throws IOException {
// [resources,litecode,config]
String litecode = getLitecode(path);
if(litecode !=null){
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy