package com.hunantv.fw.fmext;

import java.io.File;

import org.apache.log4j.Logger;

import com.hunantv.fw.Application;
import com.hunantv.fw.utils.SysConf;

import freemarker.cache.MruCacheStorage;
import freemarker.cache.SoftCacheStorage;
import freemarker.template.Configuration;

public class FmExt {
	private static final Logger logger = Logger.getLogger(FmExt.class);
	private Configuration freeMarkerCfg;
	private static FmExt fmExt = null;

	private FmExt() {
		try {
			SysConf sysConf = Application.getInstance().getSysConf();
			freeMarkerCfg = new Configuration();
			String viewPath = sysConf.getSysPath() + "views";
			File viewDir = new File(viewPath);
			if (!viewDir.exists()) {
				viewDir.mkdirs();
			}
			freeMarkerCfg.setDirectoryForTemplateLoading(viewDir);
			freeMarkerCfg.setDefaultEncoding("UTF-8");
			freeMarkerCfg.setSharedVariable("block", new BlockDirective());
			freeMarkerCfg.setSharedVariable("override", new OverrideDirective());
			freeMarkerCfg.setSharedVariable("extends", new ExtendsDirective());
			freeMarkerCfg.setClassicCompatible(true);
			freeMarkerCfg.setCacheStorage(new MruCacheStorage(0, Integer.MAX_VALUE));
			logger.info("init freemarker ok");
		} catch (Exception ex) {
			logger.error("init freemarker failed", ex);
			throw new RuntimeException(ex);
		}
	}

	public static FmExt getInstance() {
		if (null == fmExt)
			fmExt = new FmExt();
		return fmExt;
	}

	public Configuration getFreeMarkerCfg() {
		return this.freeMarkerCfg;
	}
}

@@ -477,23 +477,23 @@
 %0A%09%09%09
-SysConf sysConf
+Application app
  = A
@@ -516,16 +516,42 @@
 stance()
+;%0A%09%09%09SysConf sysConf = app
 .getSysC
@@ -1180,16 +1180,108 @@
 ALUE));%0A
+%09%09%09if (!app.isDebug())%0A%09%09%09%09freeMarkerCfg.setTemplateUpdateDelay(360 * 24 * 3600); // 1%E5%B9%B4%E6%9B%B4%E6%96%B0%E4%B8%80%E6%AC%A1%0A
 %09%09%09logge

fix bug：当为debug模式启动的时候，freemarker 5秒更新，如果是非debug模式，freemarker是1年更新