Add method to create a “success” JSON object.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Nov 2010 14:07:22 +0000 (15:07 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Nov 2010 14:07:22 +0000 (15:07 +0100)
12 files changed:
src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetSoneStatusPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java
src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java
src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java

index aa8849a..486fb75 100644 (file)
@@ -60,7 +60,7 @@ public class CreateReplyAjaxPage extends JsonPage {
                        return createErrorJsonObject("invalid-post-id");
                }
                Reply reply = webInterface.getCore().createReply(currentSone, post, text);
-               return new JsonObject().put("success", true).put("reply", reply.getId());
+               return createSuccessJsonObject().put("reply", reply.getId());
        }
 
 }
index 16c047d..603c013 100644 (file)
@@ -61,7 +61,7 @@ public class DeletePostAjaxPage extends JsonPage {
                        return createErrorJsonObject("not-authorized");
                }
                currentSone.removePost(post);
-               return new JsonObject().put("success", true);
+               return createSuccessJsonObject();
        }
 
 }
index b34ca5a..6563a7c 100644 (file)
@@ -61,7 +61,7 @@ public class DeleteReplyAjaxPage extends JsonPage {
                        return createErrorJsonObject("not-authorized");
                }
                webInterface.getCore().deleteReply(reply);
-               return new JsonObject().put("success", true);
+               return createSuccessJsonObject();
        }
 
 }
index e90fa5f..5cb03e1 100644 (file)
@@ -53,7 +53,7 @@ public class FollowSoneAjaxPage extends JsonPage {
                }
                currentSone.addFriend(soneId);
                webInterface.getCore().saveSone(currentSone);
-               return new JsonObject().put("success", true);
+               return createSuccessJsonObject();
        }
 
 }
index 7b55faa..58b1265 100644 (file)
@@ -64,11 +64,11 @@ public class GetLikesAjaxPage extends JsonPage {
                if ("post".equals(type)) {
                        Post post = webInterface.getCore().getPost(id);
                        Set<Sone> sones = webInterface.getCore().getLikes(post);
-                       return new JsonObject().put("success", true).put("likes", sones.size()).put("sones", getSones(sones));
+                       return createSuccessJsonObject().put("likes", sones.size()).put("sones", getSones(sones));
                } else if ("reply".equals(type)) {
                        Reply reply = webInterface.getCore().getReply(id);
                        Set<Sone> sones = webInterface.getCore().getLikes(reply);
-                       return new JsonObject().put("success", true).put("likes", sones.size()).put("sones", getSones(sones));
+                       return createSuccessJsonObject().put("likes", sones.size()).put("sones", getSones(sones));
                }
                return createErrorJsonObject("invalid-type");
        }
index 292f3bf..6b94874 100644 (file)
@@ -81,7 +81,7 @@ public class GetReplyAjaxPage extends JsonPage {
                        Closer.close(templateWriter);
                }
                synchronized (dateFormat) {
-                       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());
+                       return createSuccessJsonObject().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());
                }
        }
 
index ff8e181..13ed15e 100644 (file)
@@ -57,7 +57,7 @@ public class GetSoneStatusPage extends JsonPage {
                String soneId = request.getHttpRequest().getParam("sone");
                Sone sone = webInterface.getCore().getSone(soneId);
                SoneStatus soneStatus = webInterface.getCore().getSoneStatus(sone);
-               return new JsonObject().put("status", soneStatus.name()).put("name", SoneAccessor.getNiceName(sone)).put("modified", webInterface.getCore().isModifiedSone(sone)).put("lastUpdated", new SimpleDateFormat("MMM d, yyyy, HH:mm:ss").format(new Date(sone.getTime()))).put("age", (System.currentTimeMillis() - sone.getTime()) / 1000);
+               return createSuccessJsonObject().put("status", soneStatus.name()).put("name", SoneAccessor.getNiceName(sone)).put("modified", webInterface.getCore().isModifiedSone(sone)).put("lastUpdated", new SimpleDateFormat("MMM d, yyyy, HH:mm:ss").format(new Date(sone.getTime()))).put("age", (System.currentTimeMillis() - sone.getTime()) / 1000);
        }
 
        /**
index 20f1636..014bc88 100644 (file)
@@ -48,7 +48,7 @@ public class GetTranslationPage extends JsonPage {
        protected JsonObject createJsonObject(Request request) {
                String key = request.getHttpRequest().getParam("key");
                String translation = webInterface.getL10n().getString(key);
-               return new JsonObject().put("value", translation);
+               return createSuccessJsonObject().put("value", translation);
        }
 
        /**
index 8e7d27e..b9bdc77 100644 (file)
@@ -145,6 +145,15 @@ public abstract class JsonPage implements Page {
        //
 
        /**
+        * Creates a success reply.
+        *
+        * @return A reply signaling success
+        */
+       protected JsonObject createSuccessJsonObject() {
+               return new JsonObject().put("success", true);
+       }
+
+       /**
         * Creates an error reply.
         *
         * @param error
index 258eb7f..1a49ccd 100644 (file)
@@ -60,7 +60,7 @@ public class LikeAjaxPage extends JsonPage {
                } else {
                        return createErrorJsonObject("invalid-type");
                }
-               return new JsonObject().put("success", true);
+               return createSuccessJsonObject();
        }
 
 }
index 7e620ef..586ab55 100644 (file)
@@ -53,7 +53,7 @@ public class UnfollowSoneAjaxPage extends JsonPage {
                }
                currentSone.removeFriend(soneId);
                webInterface.getCore().saveSone(currentSone);
-               return new JsonObject().put("success", true);
+               return createSuccessJsonObject();
        }
 
 }
index ecacf98..6a4dde7 100644 (file)
@@ -60,7 +60,7 @@ public class UnlikeAjaxPage extends JsonPage {
                } else {
                        return createErrorJsonObject("invalid-type");
                }
-               return new JsonObject().put("success", true);
+               return createSuccessJsonObject();
        }
 
 }