/** * Copyright (C) 2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package de.neuland.jade4j.template; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; /** * Loads a Jade template from Classpath * It is useful when Jade templates are in the same JAR or WAR * * @author emiguelt * */ public class ClasspathTemplateLoader implements TemplateLoader { private static final String suffix = ".jade"; private String encoding = "UTF-8"; public long getLastModified(String name) { return -1; } @Override public Reader getReader(String name) throws IOException { if(!name.endsWith(suffix))name = name + suffix; return new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(name), getEncoding()); } public String getEncoding() { return encoding; } public void setEncoding(String encoding) { this.encoding = encoding; } }