panda.tpl.ftl.ClassTemplateLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.tpl.ftl;
import java.net.URL;
import panda.lang.ClassLoaders;
import freemarker.cache.URLTemplateLoader;
/**
* ClassTemplateLoader
*/
public class ClassTemplateLoader extends URLTemplateLoader {
private String path;
/**
* Constructor
*/
public ClassTemplateLoader() {
this("/");
}
/**
* Constructor
* @param path the base path to template resources.
*/
public ClassTemplateLoader(String path) {
setPath(path);
}
private void setPath(String path) {
if (path == null) {
throw new IllegalArgumentException("path == null");
}
this.path = canonicalizePrefix(path);
}
protected URL getURL(String name) {
if (name.startsWith("/")) {
name = name.substring(1);
}
return ClassLoaders.getResourceAsURL(path + name, getClass().getClassLoader());
}
}