X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetReplyAjaxPage.java;h=292f3bfd44e4021ffb6e93b523ea6d2f5b5057a5;hb=ca65e4c3c3eec57227b50db1f10df0d2901fe0b0;hp=d00c7ddc2f0aa42ee7c123f7513c747c081cea95;hpb=009efe04643aa488075dba3a71a2afb60e3d675f;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 d00c7dd..292f3bf 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web.ajax; +import java.io.StringWriter; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -24,7 +25,10 @@ import java.util.Date; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.json.JsonObject; +import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateException; /** * This AJAX page returns the details of a reply. @@ -36,13 +40,20 @@ public class GetReplyAjaxPage extends JsonPage { /** Date formatter. */ private static final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy, HH:mm:ss"); + /** The template to render. */ + private final Template replyTemplate; + /** * Creates a new “get reply” page. * * @param webInterface + * The Sone web interface + * @param replyTemplate + * The template to render */ - public GetReplyAjaxPage(WebInterface webInterface) { + public GetReplyAjaxPage(WebInterface webInterface, Template replyTemplate) { super("ajax/getReply.ajax", webInterface); + this.replyTemplate = replyTemplate; } // @@ -59,8 +70,18 @@ public class GetReplyAjaxPage extends JsonPage { if ((reply == null) || (reply.getSone() == null)) { return createErrorJsonObject("invalid-reply-id"); } + replyTemplate.set("reply", reply); + replyTemplate.set("currentSone", getCurrentSone(request.getToadletContext())); + StringWriter templateWriter = new StringWriter(); + try { + replyTemplate.render(templateWriter); + } catch (TemplateException te1) { + /* TODO - shouldn’t happen. */ + } finally { + Closer.close(templateWriter); + } synchronized (dateFormat) { - return new JsonObject().put("success", true).put("sone-id", reply.getSone().getId()).put("sone-name", SoneAccessor.getNiceName(reply.getSone())).put("time", reply.getTime()).put("display-time", dateFormat.format(new Date(reply.getTime()))).put("text", reply.getText()); + return new JsonObject().put("success", true).put("soneId", reply.getSone().getId()).put("soneName", SoneAccessor.getNiceName(reply.getSone())).put("time", reply.getTime()).put("displayTime", dateFormat.format(new Date(reply.getTime()))).put("text", reply.getText()).put("html", templateWriter.toString()); } }