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;
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) {
*/
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) {
*/
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.
*
- * @param request
- * The request being processed
* @param postingSone
* The posting Sone
*/
- public SoneTextParserContext(FreenetRequest request, Sone postingSone) {
- this.request = request;
+ public SoneTextParserContext(Sone 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
@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() {
- 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() {
- 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() {
- 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]"));
}