From: David ‘Bombe’ Roden Date: Wed, 26 Jan 2011 10:09:20 +0000 (+0100) Subject: Allow specifying a Sone ID in addition to a template object name. X-Git-Tag: 0.4.4^2~26 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=47d2becfd53af8314accaee3b1aaa3c7a7ef401e;p=Sone.git Allow specifying a Sone ID in addition to a template object name. --- diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index f1190e0..1e274cc 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.StringReader; import java.util.Map; +import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.text.FreenetLinkParser; import net.pterodactylus.sone.text.FreenetLinkParserContext; @@ -35,6 +36,9 @@ import net.pterodactylus.util.template.TemplateContextFactory; */ public class ParserFilter implements Filter { + /** The core. */ + private final Core core; + /** The link parser. */ private final FreenetLinkParser linkParser; @@ -42,10 +46,13 @@ public class ParserFilter implements Filter { * Creates a new filter that runs its input through a * {@link FreenetLinkParser}. * + * @param core + * The core * @param templateContextFactory * The context factory for rendering the parts */ - public ParserFilter(TemplateContextFactory templateContextFactory) { + public ParserFilter(Core core, TemplateContextFactory templateContextFactory) { + this.core = core; linkParser = new FreenetLinkParser(templateContextFactory); } @@ -60,6 +67,9 @@ public class ParserFilter implements Filter { soneKey = "sone"; } Sone sone = (Sone) templateContext.get(soneKey); + if (sone == null) { + sone = core.getSone(soneKey, false); + } FreenetLinkParserContext context = new FreenetLinkParserContext(sone); try { return linkParser.parse(context, new StringReader(text)); diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 9023ccf..cc5fd5b 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -198,7 +198,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(templateContextFactory)); + templateContextFactory.addFilter("parse", new ParserFilter(getCore(), templateContextFactory)); templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate")); templateContextFactory.addFilter("format", new FormatFilter()); templateContextFactory.addPlugin("getpage", new GetPagePlugin());