From 9a51be48388d6f94c692444e986a616e52b5909d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 8 Jun 2011 12:46:59 +0200 Subject: [PATCH] Use Sone text parser from web interface in parser filter. --- .../java/net/pterodactylus/sone/template/ParserFilter.java | 10 ++++++---- src/main/java/net/pterodactylus/sone/web/WebInterface.java | 7 ++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index 632af02..26afe2e 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -51,7 +51,7 @@ public class ParserFilter implements Filter { private final Core core; /** The link parser. */ - private final SoneTextParser textParser; + private final SoneTextParser soneTextParser; /** The template context factory. */ private final TemplateContextFactory templateContextFactory; @@ -70,11 +70,13 @@ public class ParserFilter implements Filter { * The core * @param templateContextFactory * The context factory for rendering the parts + * @param soneTextParser + * The Sone text parser */ - public ParserFilter(Core core, TemplateContextFactory templateContextFactory) { + public ParserFilter(Core core, TemplateContextFactory templateContextFactory, SoneTextParser soneTextParser) { this.core = core; this.templateContextFactory = templateContextFactory; - textParser = new SoneTextParser(core); + this.soneTextParser = soneTextParser; } /** @@ -95,7 +97,7 @@ public class ParserFilter implements Filter { SoneTextParserContext context = new SoneTextParserContext(request, sone); StringWriter parsedTextWriter = new StringWriter(); try { - render(parsedTextWriter, textParser.parse(context, new StringReader(text))); + render(parsedTextWriter, soneTextParser.parse(context, new StringReader(text))); } catch (IOException ioe1) { /* no exceptions in a StringReader or StringWriter, ignore. */ } diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 98539fe..90249d3 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -58,6 +58,7 @@ import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.template.SubstringFilter; import net.pterodactylus.sone.template.TrustAccessor; import net.pterodactylus.sone.template.UnknownDateFilter; +import net.pterodactylus.sone.text.SoneTextParser; import net.pterodactylus.sone.web.ajax.BookmarkAjaxPage; import net.pterodactylus.sone.web.ajax.CreatePostAjaxPage; import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage; @@ -151,6 +152,9 @@ public class WebInterface implements CoreListener { /** The template context factory. */ private final TemplateContextFactory templateContextFactory; + /** The Sone text parser. */ + private final SoneTextParser soneTextParser; + /** The “new Sone” notification. */ private final ListNotification newSoneNotification; @@ -185,6 +189,7 @@ public class WebInterface implements CoreListener { public WebInterface(SonePlugin sonePlugin) { this.sonePlugin = sonePlugin; formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword(); + soneTextParser = new SoneTextParser(getCore()); templateContextFactory = new TemplateContextFactory(); templateContextFactory.addAccessor(Object.class, new ReflectionAccessor()); @@ -206,7 +211,7 @@ public class WebInterface implements CoreListener { templateContextFactory.addFilter("match", new MatchFilter()); templateContextFactory.addFilter("css", new CssClassNameFilter()); templateContextFactory.addFilter("js", new JavascriptFilter()); - templateContextFactory.addFilter("parse", new ParserFilter(getCore(), templateContextFactory)); + templateContextFactory.addFilter("parse", new ParserFilter(getCore(), templateContextFactory, soneTextParser)); templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate")); templateContextFactory.addFilter("format", new FormatFilter()); templateContextFactory.addFilter("sort", new CollectionSortFilter()); -- 2.7.4