1 package net.pterodactylus.sone.main;
3 import static net.pterodactylus.util.template.TemplateParser.parse;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
8 import java.io.UnsupportedEncodingException;
10 import net.pterodactylus.sone.web.WebInterface;
11 import net.pterodactylus.util.io.Closer;
12 import net.pterodactylus.util.template.ClassPathTemplateProvider;
13 import net.pterodactylus.util.template.Template;
14 import net.pterodactylus.util.template.TemplateProvider;
15 import net.pterodactylus.util.web.Page;
16 import net.pterodactylus.util.web.Request;
17 import net.pterodactylus.util.web.StaticPage;
20 * Default {@link Loaders} implementation that loads resources from the classpath.
22 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
24 public class DefaultLoaders implements Loaders {
27 public Template loadTemplate(String path) {
28 InputStream templateInputStream = null;
31 templateInputStream = getClass().getResourceAsStream(path);
32 reader = new InputStreamReader(templateInputStream, "UTF-8");
34 } catch (UnsupportedEncodingException uee1) {
35 throw new RuntimeException("UTF-8 not supported.");
38 Closer.close(templateInputStream);
43 public <REQ extends Request> Page<REQ> loadStaticPage(String pathPrefix, String basePath, String mimeType) {
44 return new StaticPage<REQ>(pathPrefix, basePath, mimeType) {
49 public TemplateProvider getTemplateProvider() {
50 return new ClassPathTemplateProvider(WebInterface.class, "/templates/");