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 public class DefaultLoaders implements Loaders {
25 public Template loadTemplate(String path) {
26 InputStream templateInputStream = null;
29 templateInputStream = getClass().getResourceAsStream(path);
30 reader = new InputStreamReader(templateInputStream, "UTF-8");
32 } catch (UnsupportedEncodingException uee1) {
33 throw new RuntimeException("UTF-8 not supported.");
36 Closer.close(templateInputStream);
41 public <REQ extends Request> Page<REQ> loadStaticPage(String pathPrefix, String basePath, String mimeType) {
42 return new StaticPage<REQ>(pathPrefix, basePath, mimeType) {
47 public TemplateProvider getTemplateProvider() {
48 return new ClassPathTemplateProvider(WebInterface.class, "/templates/");