Synchronize template access to prevent multiple copies appearing in the HTML.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 12 Dec 2010 16:22:13 +0000 (17:22 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 12 Dec 2010 16:22:13 +0000 (17:22 +0100)
src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java

index 7c96d56..ec0145a 100644 (file)
@@ -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;
index 77b3ada..0963b09 100644 (file)
@@ -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());
        }