Remove request from parser context
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 6 Oct 2016 18:38:11 +0000 (20:38 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 6 Oct 2016 18:38:11 +0000 (20:38 +0200)
src/main/java/net/pterodactylus/sone/template/ParserFilter.java
src/main/java/net/pterodactylus/sone/text/SoneTextParserContext.java
src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java

index 479b3b2..7cf8c70 100644 (file)
@@ -39,7 +39,6 @@ import net.pterodactylus.sone.text.PostPart;
 import net.pterodactylus.sone.text.SonePart;
 import net.pterodactylus.sone.text.SoneTextParser;
 import net.pterodactylus.sone.text.SoneTextParserContext;
 import net.pterodactylus.sone.text.SonePart;
 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.Template;
 import net.pterodactylus.util.template.TemplateContext;
 import net.pterodactylus.util.template.Filter;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
@@ -97,8 +96,7 @@ public class ParserFilter implements Filter {
                if (sone instanceof String) {
                        sone = core.getSone((String) sone).orNull();
                }
                if (sone instanceof String) {
                        sone = core.getSone((String) sone).orNull();
                }
-               FreenetRequest request = (FreenetRequest) templateContext.get("request");
-               SoneTextParserContext context = new SoneTextParserContext(request, (Sone) sone);
+               SoneTextParserContext context = new SoneTextParserContext((Sone) sone);
                StringWriter parsedTextWriter = new StringWriter();
                Iterable<Part> parts = soneTextParser.parse(text, context);
                if (length > -1) {
                StringWriter parsedTextWriter = new StringWriter();
                Iterable<Part> parts = soneTextParser.parse(text, context);
                if (length > -1) {
@@ -246,7 +244,7 @@ public class ParserFilter implements Filter {
         */
        private void render(Writer writer, PostPart postPart) {
                SoneTextParser parser = new SoneTextParser(core, core);
         */
        private void render(Writer writer, PostPart postPart) {
                SoneTextParser parser = new SoneTextParser(core, core);
-               SoneTextParserContext parserContext = new SoneTextParserContext(null, postPart.getPost().getSone());
+               SoneTextParserContext parserContext = new SoneTextParserContext(postPart.getPost().getSone());
                Iterable<Part> parts = parser.parse(postPart.getPost().getText(), parserContext);
                StringBuilder excerpt = new StringBuilder();
                for (Part part : parts) {
                Iterable<Part> parts = parser.parse(postPart.getPost().getText(), parserContext);
                StringBuilder excerpt = new StringBuilder();
                for (Part part : parts) {
index 8918e40..fba81ab 100644 (file)
@@ -29,35 +29,20 @@ import net.pterodactylus.sone.web.page.FreenetRequest;
  */
 public class SoneTextParserContext implements ParserContext {
 
  */
 public class SoneTextParserContext implements ParserContext {
 
-       /** The request being processed. */
-       private final FreenetRequest request;
-
        /** The posting Sone. */
        private final Sone postingSone;
 
        /**
         * Creates a new link parser context.
         *
        /** The posting Sone. */
        private final Sone postingSone;
 
        /**
         * Creates a new link parser context.
         *
-        * @param request
-        *            The request being processed
         * @param postingSone
         *            The posting Sone
         */
         * @param postingSone
         *            The posting Sone
         */
-       public SoneTextParserContext(FreenetRequest request, Sone postingSone) {
-               this.request = request;
+       public SoneTextParserContext(Sone postingSone) {
                this.postingSone = postingSone;
        }
 
        /**
                this.postingSone = postingSone;
        }
 
        /**
-        * Returns the request that is currently being processed.
-        *
-        * @return The request being processed
-        */
-       public FreenetRequest getRequest() {
-               return request;
-       }
-
-       /**
         * Returns the Sone that provided the text that is being parsed.
         *
         * @return The posting Sone
         * Returns the Sone that provided the text that is being parsed.
         *
         * @return The posting Sone
index 74099f5..bfe218e 100644 (file)
@@ -206,28 +206,28 @@ public class SoneTextParserTest {
 
        @Test
        public void sskLinkWithContextWithoutSoneIsNotTrusted() {
 
        @Test
        public void sskLinkWithContextWithoutSoneIsNotTrusted() {
-               SoneTextParserContext context = new SoneTextParserContext(null, null);
+               SoneTextParserContext context = new SoneTextParserContext(null);
                Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
                assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
        }
 
        @Test
        public void sskLinkWithContextWithDifferentSoneIsNotTrusted() {
                Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
                assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
        }
 
        @Test
        public void sskLinkWithContextWithDifferentSoneIsNotTrusted() {
-               SoneTextParserContext context = new SoneTextParserContext(null, new IdOnlySone("DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU"));
+               SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("DAxKQzS48mtaQc7sUVHIgx3fnWZPQBz0EueBreUVWrU"));
                Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
                assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
        }
 
        @Test
        public void sskLinkWithContextWithCorrectSoneIsTrusted() {
                Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
                assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|test|test]"));
        }
 
        @Test
        public void sskLinkWithContextWithCorrectSoneIsTrusted() {
-               SoneTextParserContext context = new SoneTextParserContext(null, new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"));
+               SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"));
                Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
                assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|trusted|test|test]"));
        }
 
        @Test
        public void uskLinkWithContextWithCorrectSoneIsTrusted() {
                Iterable<Part> parts = soneTextParser.parse("SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test", context);
                assertThat("Part Text", convertText(parts), is("[SSK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test|trusted|test|test]"));
        }
 
        @Test
        public void uskLinkWithContextWithCorrectSoneIsTrusted() {
-               SoneTextParserContext context = new SoneTextParserContext(null, new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"));
+               SoneTextParserContext context = new SoneTextParserContext(new IdOnlySone("qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU"));
                Iterable<Part> parts = soneTextParser.parse("USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0", context);
                assertThat("Part Text", convertText(parts), is("[USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0|trusted|test|test]"));
        }
                Iterable<Part> parts = soneTextParser.parse("USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0", context);
                assertThat("Part Text", convertText(parts), is("[USK@qM1nmgU-YUnIttmEhqjTl7ifAF3Z6o~5EPwQW03uEQU,aztSUkT-VT1dWvfSUt9YpfyW~Flmf5yXpBnIE~v8sAg,AAMC--8/test/0|trusted|test|test]"));
        }