From 65808c9c5b9c06d22e5386f29cea9de561e020e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 14 Nov 2010 15:37:11 +0100 Subject: [PATCH] Convert template factory into field. --- .../net/pterodactylus/sone/web/WebInterface.java | 42 ++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 2f10567..1a1027d 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -94,6 +94,9 @@ public class WebInterface { /** The form password. */ private final String formPassword; + /** The template factory. */ + private DefaultTemplateFactory templateFactory; + /** * Creates a new web interface. * @@ -103,6 +106,25 @@ public class WebInterface { public WebInterface(SonePlugin sonePlugin) { this.sonePlugin = sonePlugin; formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword(); + + templateFactory = new DefaultTemplateFactory(); + templateFactory.addAccessor(Object.class, new ReflectionAccessor()); + templateFactory.addAccessor(Collection.class, new CollectionAccessor()); + templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore())); + templateFactory.addAccessor(Post.class, new PostAccessor(getCore())); + templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore())); + templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore())); + templateFactory.addFilter("date", new DateFilter()); + templateFactory.addFilter("l10n", new L10nFilter(getL10n())); + templateFactory.addFilter("substring", new SubstringFilter()); + templateFactory.addFilter("xml", new XmlFilter()); + templateFactory.addFilter("change", new RequestChangeFilter()); + templateFactory.addFilter("match", new MatchFilter()); + templateFactory.addFilter("css", new CssClassNameFilter()); + templateFactory.addPlugin("getpage", new GetPagePlugin()); + templateFactory.addPlugin("paginate", new PaginationPlugin()); + templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory)); + templateFactory.addTemplateObject("formPassword", formPassword); } // @@ -176,25 +198,6 @@ public class WebInterface { * Register all toadlets. */ private void registerToadlets() { - DefaultTemplateFactory templateFactory = new DefaultTemplateFactory(); - templateFactory.addAccessor(Object.class, new ReflectionAccessor()); - templateFactory.addAccessor(Collection.class, new CollectionAccessor()); - templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore())); - templateFactory.addAccessor(Post.class, new PostAccessor(getCore())); - templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore())); - templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore())); - templateFactory.addFilter("date", new DateFilter()); - templateFactory.addFilter("l10n", new L10nFilter(getL10n())); - templateFactory.addFilter("substring", new SubstringFilter()); - templateFactory.addFilter("xml", new XmlFilter()); - templateFactory.addFilter("change", new RequestChangeFilter()); - templateFactory.addFilter("match", new MatchFilter()); - templateFactory.addFilter("css", new CssClassNameFilter()); - templateFactory.addPlugin("getpage", new GetPagePlugin()); - templateFactory.addPlugin("paginate", new PaginationPlugin()); - templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory)); - templateFactory.addTemplateObject("formPassword", formPassword); - Template loginTemplate = templateFactory.createTemplate(createReader("/templates/login.html")); Template indexTemplate = templateFactory.createTemplate(createReader("/templates/index.html")); Template knownSonesTemplate = templateFactory.createTemplate(createReader("/templates/knownSones.html")); @@ -304,6 +307,7 @@ public class WebInterface { private class ClassPathTemplateProvider implements TemplateProvider { /** The template factory. */ + @SuppressWarnings("hiding") private final TemplateFactory templateFactory; /** -- 2.7.4