From d7df2d32e1986db76e36103167b41f0edc5d831d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 12 Dec 2010 17:22:13 +0100 Subject: [PATCH] Synchronize template access to prevent multiple copies appearing in the HTML. --- .../net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java | 16 +++++++++------- .../pterodactylus/sone/web/ajax/GetReplyAjaxPage.java | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java index 7c96d56..ec0145a 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java @@ -90,14 +90,16 @@ public class GetPostAjaxPage extends JsonPage { jsonPost.put("sone", post.getSone().getId()); jsonPost.put("recipient", (post.getRecipient() == null) ? null : post.getRecipient().getId()); jsonPost.put("time", post.getTime()); - postTemplate.set("post", post); StringWriter stringWriter = new StringWriter(); - try { - postTemplate.render(stringWriter); - } catch (TemplateException te1) { - /* TODO - shouldn’t happen. */ - } finally { - Closer.close(stringWriter); + synchronized (postTemplate) { + postTemplate.set("post", post); + try { + postTemplate.render(stringWriter); + } catch (TemplateException te1) { + /* TODO - shouldn’t happen. */ + } finally { + Closer.close(stringWriter); + } } jsonPost.put("html", stringWriter.toString()); return jsonPost; 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 77b3ada..0963b09 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -92,14 +92,16 @@ public class GetReplyAjaxPage extends JsonPage { 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(); - try { - replyTemplate.render(stringWriter); - } catch (TemplateException te1) { - /* TODO - shouldn’t happen. */ - } finally { - Closer.close(stringWriter); + synchronized (replyTemplate) { + replyTemplate.set("reply", reply); + try { + replyTemplate.render(stringWriter); + } catch (TemplateException te1) { + /* TODO - shouldn’t happen. */ + } finally { + Closer.close(stringWriter); + } } return jsonReply.put("html", stringWriter.toString()); } -- 2.7.4