package jp.sourceforge.shovel.servlet.freemarker;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Reader;

import javax.servlet.ServletContext;

import jp.sourceforge.shovel.io.InputStreamReaderExt;

import freemarker.cache.WebappTemplateLoader;

public class WebappTemplateLoaderExt extends WebappTemplateLoader {
    public WebappTemplateLoaderExt(ServletContext servletContext) {
        super(servletContext);
    }
    public WebappTemplateLoaderExt(ServletContext servletContext, String path) {
        super(servletContext, path);
    }
    public Reader getReader(Object templateSource, String encoding)
    throws IOException {
        if (templateSource instanceof File) {
            return new InputStreamReaderExt(
                    new FileInputStream((File) templateSource),
                    encoding);
        }
        return super.getReader(templateSource, encoding);
    }
}
