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.sone.web.page.FreenetRequest;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.json.JsonObject;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateException;
/**
* The template to render
*/
public GetReplyAjaxPage(WebInterface webInterface, Template replyTemplate) {
- super("ajax/getReply.ajax", webInterface);
+ super("getReply.ajax", webInterface);
this.replyTemplate = replyTemplate;
}
* {@inheritDoc}
*/
@Override
- protected JsonObject createJsonObject(Request request) {
+ protected JsonObject createJsonObject(FreenetRequest request) {
String replyId = request.getHttpRequest().getParam("reply");
Reply reply = webInterface.getCore().getReply(replyId);
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(request, reply, getCurrentSone(request.getToadletContext())));
}
/**
/**
* Creates a JSON representation of the given reply.
*
+ * @param request
+ * The request being processed
* @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(FreenetRequest request, 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();
+ TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext();
+ templateContext.set("core", webInterface.getCore());
+ templateContext.set("request", request);
+ templateContext.set("reply", reply);
+ templateContext.set("currentSone", currentSone);
try {
- replyTemplate.render(stringWriter);
+ replyTemplate.render(templateContext, stringWriter);
} catch (TemplateException te1) {
/* TODO - shouldn’t happen. */
} finally {