X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FParserFilter.java;h=26254412eebe335ef703dce2382230b2b96be6d5;hb=449c24942c72153666e261b4b35df5cf2e0ac2ac;hp=db945b526560d4dcccf2a8c3cf59c1e79d4d196f;hpb=f68dae6e6afab586e6031242960f76d641b48402;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java
index db945b5..2625441 100644
--- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java
+++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java
@@ -1,5 +1,5 @@
/*
- * Sone - ParserFilter.java - Copyright © 2011 David Roden
+ * Sone - ParserFilter.java - Copyright © 2011â2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,67 +17,55 @@
package net.pterodactylus.sone.template;
+import static java.lang.String.valueOf;
+
import java.io.IOException;
import java.io.StringReader;
+import java.util.Collections;
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;
-import net.pterodactylus.sone.web.page.Page.Request;
+import net.pterodactylus.sone.text.Part;
+import net.pterodactylus.sone.text.SoneTextParser;
+import net.pterodactylus.sone.text.SoneTextParserContext;
+import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.template.Filter;
import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.template.TemplateContextFactory;
/**
- * Filter that filters a given text through a {@link FreenetLinkParser}.
+ * Filter that filters a given text through a {@link SoneTextParser} and returns the parsed {@link Part}s.
*
* @author David âBombeâ Roden
*/
public class ParserFilter implements Filter {
- /** The core. */
private final Core core;
+ private final SoneTextParser soneTextParser;
- /** The link parser. */
- private final FreenetLinkParser linkParser;
-
- /**
- * 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(Core core, TemplateContextFactory templateContextFactory) {
+ public ParserFilter(Core core, SoneTextParser soneTextParser) {
this.core = core;
- linkParser = new FreenetLinkParser(core, templateContextFactory);
+ this.soneTextParser = soneTextParser;
}
/**
* {@inheritDoc}
*/
@Override
- public Object format(TemplateContext templateContext, Object data, Map parameters) {
- String text = String.valueOf(data);
- String soneKey = parameters.get("sone");
- if (soneKey == null) {
- soneKey = "sone";
- }
- Sone sone = (Sone) templateContext.get(soneKey);
- if (sone == null) {
- sone = core.getSone(soneKey, false);
+ public Object format(TemplateContext templateContext, Object data, Map parameters) {
+ String text = valueOf(data);
+ Object sone = parameters.get("sone");
+ if (sone instanceof String) {
+ sone = core.getSone((String) sone).orNull();
}
- FreenetLinkParserContext context = new FreenetLinkParserContext((Request) templateContext.get("request"), sone);
+ FreenetRequest request = (FreenetRequest) templateContext.get("request");
+ SoneTextParserContext context = new SoneTextParserContext(request, (Sone) sone);
try {
- return linkParser.parse(context, new StringReader(text));
+ return soneTextParser.parse(context, new StringReader(text));
} catch (IOException ioe1) {
/* no exceptions in a StringReader, ignore. */
+ return Collections.emptyList();
}
- return null;
}
}