X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetReplyAjaxPage.java;h=e5891912ec1d46ae14cba88e726acc7024d6fbc9;hb=4f7f61499282e109ced38a020c23b8b2024d18c4;hp=3c43593b09d5b5111f4548b37a046944e630d63a;hpb=57b5f730c79f77d8d7dc5ddaadbb7c9ec2aaca91;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java index 3c43593..e589191 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -20,9 +20,11 @@ package net.pterodactylus.sone.web.ajax; import java.io.StringWriter; import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.json.JsonObject; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateException; @@ -45,7 +47,7 @@ public class GetReplyAjaxPage extends JsonPage { * The template to render */ public GetReplyAjaxPage(WebInterface webInterface, Template replyTemplate) { - super("ajax/getReply.ajax", webInterface); + super("getReply.ajax", webInterface); this.replyTemplate = replyTemplate; } @@ -63,8 +65,7 @@ public class GetReplyAjaxPage extends JsonPage { if ((reply == null) || (reply.getSone() == null)) { return createErrorJsonObject("invalid-reply-id"); } - replyTemplate.set("currentSone", getCurrentSone(request.getToadletContext())); - return createSuccessJsonObject().put("reply", createJsonReply(reply)); + return createSuccessJsonObject().put("reply", createJsonReply(reply, getCurrentSone(request.getToadletContext()))); } /** @@ -84,18 +85,22 @@ public class GetReplyAjaxPage extends JsonPage { * * @param reply * The reply to convert + * @param currentSone + * The currently logged in Sone (to store in the template) * @return The JSON representation of the reply */ - private JsonObject createJsonReply(Reply reply) { + private JsonObject createJsonReply(Reply reply, Sone currentSone) { JsonObject jsonReply = new JsonObject(); jsonReply.put("id", reply.getId()); jsonReply.put("postId", reply.getPost().getId()); jsonReply.put("soneId", reply.getSone().getId()); jsonReply.put("time", reply.getTime()); - replyTemplate.set("reply", reply); StringWriter stringWriter = new StringWriter(); + DataProvider dataProvider = replyTemplate.createDataProvider(); + dataProvider.setData("reply", reply); + dataProvider.setData("currentSone", currentSone); try { - replyTemplate.render(stringWriter); + replyTemplate.render(dataProvider, stringWriter); } catch (TemplateException te1) { /* TODO - shouldn’t happen. */ } finally {