Incrase maximum size for content to 2 MiB
[Sone.git] / src / main / java / net / pterodactylus / sone / main / DefaultLoaders.java
1 package net.pterodactylus.sone.main;
2
3 import static net.pterodactylus.util.template.TemplateParser.parse;
4
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 import java.io.Reader;
8 import java.io.UnsupportedEncodingException;
9
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;
18
19 /**
20  * Default {@link Loaders} implementation that loads resources from the classpath.
21  *
22  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
23  */
24 public class DefaultLoaders implements Loaders {
25
26         @Override
27         public Template loadTemplate(String path) {
28                 InputStream templateInputStream = null;
29                 Reader reader = null;
30                 try {
31                         templateInputStream = getClass().getResourceAsStream(path);
32                         reader = new InputStreamReader(templateInputStream, "UTF-8");
33                         return parse(reader);
34                 } catch (UnsupportedEncodingException uee1) {
35                         throw new RuntimeException("UTF-8 not supported.");
36                 } finally {
37                         Closer.close(reader);
38                         Closer.close(templateInputStream);
39                 }
40         }
41
42         @Override
43         public <REQ extends Request> Page<REQ> loadStaticPage(String pathPrefix, String basePath, String mimeType) {
44                 return new StaticPage<REQ>(pathPrefix, basePath, mimeType) {
45                 };
46         }
47
48         @Override
49         public TemplateProvider getTemplateProvider() {
50                 return new ClassPathTemplateProvider(WebInterface.class, "/templates/");
51         }
52
53 }