package org.ndogen.util; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import freemarker.cache.TemplateLoader; public class SingleTemplateLoader implements TemplateLoader { File file; public SingleTemplateLoader(File file) { super(); this.file = file; if(!file.exists()) { throw new RuntimeException("Tmplate file does not exist: " + file); } } @Override public Object findTemplateSource(String name) throws IOException { return file; } @Override public long getLastModified(Object templateSource) { if(templateSource != file) { throw new RuntimeException("Incompatible template source"); } return file.lastModified(); } @Override public Reader getReader(Object templateSource, String encoding) throws IOException { if(templateSource != file) { throw new RuntimeException("Incompatible template source"); } return new BufferedReader(new FileReader(file)); } @Override public void closeTemplateSource(Object templateSource) throws IOException { } }