From: David ‘Bombe’ Roden Date: Mon, 8 Jul 2013 11:13:15 +0000 (+0200) Subject: Use Jackson to create JSON pages, get rid of utils-json dependency. X-Git-Tag: 0.8.7^2~40^2~3 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9fbafff8f3467329e7c8ad24d5d13273962ade28;p=Sone.git Use Jackson to create JSON pages, get rid of utils-json dependency. --- diff --git a/pom.xml b/pom.xml index d2f00a4..d879cad 100644 --- a/pom.xml +++ b/pom.xml @@ -34,11 +34,6 @@ provided - net.pterodactylus - utils.json - 0.1 - - com.google.inject guice 3.0 @@ -53,6 +48,11 @@ commons-lang 2.6 + + com.fasterxml.jackson.core + jackson-databind + 2.1.2 + diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.java index 1005381..acee365 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.java @@ -19,7 +19,6 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user bookmark a post. @@ -46,7 +45,7 @@ public class BookmarkAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String id = request.getHttpRequest().getParam("post", null); if ((id == null) || (id.length() == 0)) { return createErrorJsonObject("invalid-post-id"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java index 4c278c6..423d2df 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java @@ -22,7 +22,6 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; import com.google.common.base.Optional; @@ -47,7 +46,7 @@ public class CreatePostAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { Sone sone = getCurrentSone(request.getToadletContext()); if (sone == null) { return createErrorJsonObject("auth-required"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java index 8a35185..ea2a2c2 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java @@ -25,7 +25,6 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * This AJAX page create a reply. @@ -52,7 +51,7 @@ public class CreateReplyAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); String text = request.getHttpRequest().getParam("text").trim(); String senderId = request.getHttpRequest().getParam("sender"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java index 71b0016..acf5f03 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java @@ -22,7 +22,6 @@ import com.google.common.base.Optional; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * This AJAX page deletes a post. @@ -49,7 +48,7 @@ public class DeletePostAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); Optional post = webInterface.getCore().getPost(postId); if (!post.isPresent()) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java index 7874f83..cb33fb9 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java @@ -17,12 +17,16 @@ package net.pterodactylus.sone.web.ajax; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; + import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; /** * AJAX page that lets the user delete a profile field. @@ -45,7 +49,7 @@ public class DeleteProfileFieldAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String fieldId = request.getHttpRequest().getParam("field"); Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); @@ -56,7 +60,7 @@ public class DeleteProfileFieldAjaxPage extends JsonPage { profile.removeField(field); currentSone.setProfile(profile); webInterface.getCore().touchConfiguration(); - return createSuccessJsonObject().put("field", new JsonObject().put("id", field.getId())); + return createSuccessJsonObject().put("field", new ObjectNode(instance).put("id", new TextNode(field.getId()))); } } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java index 2aa217d..3ea9f7f 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java @@ -22,7 +22,6 @@ import com.google.common.base.Optional; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * This AJAX page deletes a reply. @@ -49,7 +48,7 @@ public class DeleteReplyAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String replyId = request.getHttpRequest().getParam("reply"); Optional reply = webInterface.getCore().getPostReply(replyId); if (!reply.isPresent()) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java index 595696f..aed9cad 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java @@ -19,7 +19,6 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.notify.Notification; /** @@ -43,7 +42,7 @@ public class DismissNotificationAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String notificationId = request.getHttpRequest().getParam("notification"); Notification notification = webInterface.getNotifications().getNotification(notificationId); if (notification == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java index 843b088..4206e8f 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java @@ -23,7 +23,6 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user distrust a Sone. @@ -47,7 +46,7 @@ public class DistrustAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext(), false); if (currentSone == null) { return createErrorJsonObject("auth-required"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java index 8d436ea..1bd94ca 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditAlbumAjaxPage.java @@ -21,7 +21,6 @@ import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * Page that stores a user’s album modifications. @@ -48,7 +47,7 @@ public class EditAlbumAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String albumId = request.getHttpRequest().getParam("album"); Album album = webInterface.getCore().getAlbum(albumId, false); if (album == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java index 378b03b..08452ef 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditImageAjaxPage.java @@ -22,7 +22,6 @@ import net.pterodactylus.sone.template.ParserFilter; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.template.TemplateContext; import com.google.common.collect.ImmutableMap; @@ -58,7 +57,7 @@ public class EditImageAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String imageId = request.getHttpRequest().getParam("image"); Image image = webInterface.getCore().getImage(imageId, false); if (image == null) { @@ -81,7 +80,7 @@ public class EditImageAjaxPage extends JsonPage { String description = request.getHttpRequest().getParam("description").trim(); image.setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)); webInterface.getCore().touchConfiguration(); - return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription()).put("parsedDescription", (String) parserFilter.format(new TemplateContext(), image.getDescription(), ImmutableMap. builder().put("sone", image.getSone()).build())); + return createSuccessJsonObject().put("imageId", image.getId()).put("title", image.getTitle()).put("description", image.getDescription()).put("parsedDescription", (String) parserFilter.format(new TemplateContext(), image.getDescription(), ImmutableMap.builder().put("sone", image.getSone()).build())); } } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.java index 8a47ffe..b4596ad 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.java @@ -22,7 +22,6 @@ import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user rename a profile field. @@ -49,7 +48,7 @@ public class EditProfileFieldAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String fieldId = request.getHttpRequest().getParam("field"); Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java index 071f8e9..64c402a 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java @@ -22,7 +22,6 @@ import com.google.common.base.Optional; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets a Sone follow another Sone. @@ -45,7 +44,7 @@ public class FollowSoneAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); Optional sone = webInterface.getCore().getSone(soneId); if (!sone.isPresent()) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java index 1a5286f..ccc51dc 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java @@ -17,9 +17,9 @@ package net.pterodactylus.sone.web.ajax; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; +import static net.pterodactylus.sone.data.Sone.NICE_NAME_COMPARATOR; + import java.util.Set; import net.pterodactylus.sone.data.Post; @@ -28,10 +28,12 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonArray; -import net.pterodactylus.util.json.JsonObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Optional; +import com.google.common.collect.FluentIterable; /** * AJAX page that retrieves the number of “likes” a {@link Post} has. @@ -58,7 +60,7 @@ public class GetLikesAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type", null); String id = request.getHttpRequest().getParam(type, null); if ((id == null) || (id.length() == 0)) { @@ -102,12 +104,10 @@ public class GetLikesAjaxPage extends JsonPage { * The Sones to convert to an array * @return The Sones, sorted by name */ - private static JsonArray getSones(Set sones) { - JsonArray soneArray = new JsonArray(); - List sortedSones = new ArrayList(sones); - Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR); - for (Sone sone : sortedSones) { - soneArray.add(new JsonObject().put("id", sone.getId()).put("name", SoneAccessor.getNiceName(sone))); + private static JsonNode getSones(Set sones) { + ArrayNode soneArray = new ArrayNode(instance); + for (Sone sone : FluentIterable.from(sones).toSortedList(NICE_NAME_COMPARATOR)) { + soneArray.add(new ObjectNode(instance).put("id", sone.getId()).put("name", SoneAccessor.getNiceName(sone))); } return soneArray; } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java index 6573dda..e8107ef 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.web.ajax; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; + import java.io.IOException; import java.io.StringWriter; import java.util.Collection; @@ -28,12 +30,14 @@ import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonArray; -import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.notify.TemplateNotification; import net.pterodactylus.util.template.TemplateContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + /** * AJAX handler to return all current notifications. * @@ -75,12 +79,12 @@ public class GetNotificationsAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext(), false); Collection notifications = webInterface.getNotifications().getNotifications(); List filteredNotifications = ListNotificationFilters.filterNotifications(notifications, currentSone); Collections.sort(filteredNotifications, Notification.CREATED_TIME_SORTER); - JsonArray jsonNotifications = new JsonArray(); + ArrayNode jsonNotifications = new ArrayNode(instance); for (Notification notification : filteredNotifications) { jsonNotifications.add(createJsonNotification(request, notification)); } @@ -100,8 +104,8 @@ public class GetNotificationsAjaxPage extends JsonPage { * The notification to create a JSON object * @return The JSON object */ - private JsonObject createJsonNotification(FreenetRequest request, Notification notification) { - JsonObject jsonNotification = new JsonObject(); + private JsonNode createJsonNotification(FreenetRequest request, Notification notification) { + ObjectNode jsonNotification = new ObjectNode(instance); jsonNotification.put("id", notification.getId()); StringWriter notificationWriter = new StringWriter(); try { @@ -140,8 +144,8 @@ public class GetNotificationsAjaxPage extends JsonPage { * The current Sone (may be {@code null}) * @return The current options */ - private static JsonObject createJsonOptions(Sone currentSone) { - JsonObject options = new JsonObject(); + private static JsonNode createJsonOptions(Sone currentSone) { + ObjectNode options = new ObjectNode(instance); if (currentSone != null) { options.put("ShowNotification/NewSones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get()); options.put("ShowNotification/NewPosts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get()); 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 8eeedc9..96002b3 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web.ajax; import java.io.StringWriter; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; import com.google.common.base.Optional; @@ -26,11 +27,13 @@ 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; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + /** * This AJAX handler retrieves information and rendered representation of a * {@link Post}. @@ -59,7 +62,7 @@ public class GetPostAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); Optional post = webInterface.getCore().getPost(postId); if (!post.isPresent()) { @@ -92,8 +95,8 @@ public class GetPostAjaxPage extends JsonPage { * The currently logged in Sone (to store in the template) * @return The JSON representation of the post */ - private JsonObject createJsonPost(FreenetRequest request, Post post, Sone currentSone) { - JsonObject jsonPost = new JsonObject(); + private JsonNode createJsonPost(FreenetRequest request, Post post, Sone currentSone) { + ObjectNode jsonPost = new ObjectNode(instance); jsonPost.put("id", post.getId()); jsonPost.put("sone", post.getSone().getId()); jsonPost.put("recipient", post.getRecipientId().orNull()); 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 b617608..251c784 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web.ajax; import java.io.StringWriter; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; import com.google.common.base.Optional; @@ -26,11 +27,13 @@ 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; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + /** * This AJAX page returns the details of a reply. * @@ -62,7 +65,7 @@ public class GetReplyAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String replyId = request.getHttpRequest().getParam("reply"); Optional reply = webInterface.getCore().getPostReply(replyId); if (!reply.isPresent()) { @@ -94,8 +97,8 @@ public class GetReplyAjaxPage extends JsonPage { * The currently logged in Sone (to store in the template) * @return The JSON representation of the reply */ - private JsonObject createJsonReply(FreenetRequest request, PostReply reply, Sone currentSone) { - JsonObject jsonReply = new JsonObject(); + private JsonNode createJsonReply(FreenetRequest request, PostReply reply, Sone currentSone) { + ObjectNode jsonReply = new ObjectNode(instance); jsonReply.put("id", reply.getId()); jsonReply.put("postId", reply.getPostId()); jsonReply.put("soneId", reply.getSone().getId()); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index 48b25d6..e43910c 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.web.ajax; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collection; @@ -33,10 +35,11 @@ import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonArray; -import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.notify.Notification; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; @@ -65,7 +68,7 @@ public class GetStatusAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { final Sone currentSone = getCurrentSone(request.getToadletContext(), false); /* load Sones. always return the status of the current Sone. */ Set sones = new HashSet(Collections.singleton(getCurrentSone(request.getToadletContext(), false))); @@ -77,13 +80,12 @@ public class GetStatusAjaxPage extends JsonPage { sones.add(webInterface.getCore().getSone(soneId).orNull()); } } - JsonArray jsonSones = new JsonArray(); + ArrayNode jsonSones = new ArrayNode(instance); for (Sone sone : sones) { if (sone == null) { continue; } - JsonObject jsonSone = createJsonSone(sone); - jsonSones.add(jsonSone); + jsonSones.add(createJsonSone(sone)); } /* load notifications. */ List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone); @@ -100,9 +102,9 @@ public class GetStatusAjaxPage extends JsonPage { }); } - JsonArray jsonPosts = new JsonArray(); + ArrayNode jsonPosts = new ArrayNode(instance); for (Post post : newPosts) { - JsonObject jsonPost = new JsonObject(); + ObjectNode jsonPost = new ObjectNode(instance); jsonPost.put("id", post.getId()); jsonPost.put("sone", post.getSone().getId()); jsonPost.put("recipient", post.getRecipientId().orNull()); @@ -123,9 +125,9 @@ public class GetStatusAjaxPage extends JsonPage { } /* remove replies to unknown posts. */ newReplies = Collections2.filter(newReplies, PostReply.HAS_POST_FILTER); - JsonArray jsonReplies = new JsonArray(); + ArrayNode jsonReplies = new ArrayNode(instance); for (PostReply reply : newReplies) { - JsonObject jsonReply = new JsonObject(); + ObjectNode jsonReply = new ObjectNode(instance); jsonReply.put("id", reply.getId()); jsonReply.put("sone", reply.getSone().getId()); jsonReply.put("post", reply.getPostId()); @@ -162,8 +164,8 @@ public class GetStatusAjaxPage extends JsonPage { * The Sone to convert to a JSON object * @return The JSON representation of the given Sone */ - private JsonObject createJsonSone(Sone sone) { - JsonObject jsonSone = new JsonObject(); + private JsonNode createJsonSone(Sone sone) { + ObjectNode jsonSone = new ObjectNode(instance); jsonSone.put("id", sone.getId()); jsonSone.put("name", SoneAccessor.getNiceName(sone)); jsonSone.put("local", sone.getInsertUri() != null); @@ -187,8 +189,8 @@ public class GetStatusAjaxPage extends JsonPage { * The current Sone (may be {@code null}) * @return The current options */ - private static JsonObject createJsonOptions(Sone currentSone) { - JsonObject options = new JsonObject(); + private static JsonNode createJsonOptions(Sone currentSone) { + ObjectNode options = new ObjectNode(instance); if (currentSone != null) { options.put("ShowNotification/NewSones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get()); options.put("ShowNotification/NewPosts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get()); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java index b0d9dac..0c78bb6 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.web.ajax; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -26,8 +28,8 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Optional; /** @@ -54,9 +56,9 @@ public class GetTimesAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String allIds = request.getHttpRequest().getParam("posts"); - JsonObject postTimes = new JsonObject(); + ObjectNode postTimes = new ObjectNode(instance); if (allIds.length() > 0) { String[] ids = allIds.split(","); for (String id : ids) { @@ -64,7 +66,7 @@ public class GetTimesAjaxPage extends JsonPage { if (!post.isPresent()) { continue; } - JsonObject postTime = new JsonObject(); + ObjectNode postTime = new ObjectNode(instance); Time time = getTime(post.get().getTime()); postTime.put("timeText", time.getText()); postTime.put("refreshTime", TimeUnit.MILLISECONDS.toSeconds(time.getRefresh())); @@ -74,7 +76,7 @@ public class GetTimesAjaxPage extends JsonPage { postTimes.put(id, postTime); } } - JsonObject replyTimes = new JsonObject(); + ObjectNode replyTimes = new ObjectNode(instance); allIds = request.getHttpRequest().getParam("replies"); if (allIds.length() > 0) { String[] ids = allIds.split(","); @@ -83,7 +85,7 @@ public class GetTimesAjaxPage extends JsonPage { if (!reply.isPresent()) { continue; } - JsonObject replyTime = new JsonObject(); + ObjectNode replyTime = new ObjectNode(instance); Time time = getTime(reply.get().getTime()); replyTime.put("timeText", time.getText()); replyTime.put("refreshTime", TimeUnit.MILLISECONDS.toSeconds(time.getRefresh())); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java index 0ecfaea..5c81d95 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java @@ -19,7 +19,6 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * Returns the translation for a given key as JSON object. @@ -46,7 +45,7 @@ public class GetTranslationPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String key = request.getHttpRequest().getParam("key"); String translation = webInterface.getL10n().getString(key); return createSuccessJsonObject().put("value", translation); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/JsonErrorReturnObject.java b/src/main/java/net/pterodactylus/sone/web/ajax/JsonErrorReturnObject.java new file mode 100644 index 0000000..0dae0a3 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/JsonErrorReturnObject.java @@ -0,0 +1,31 @@ +/* + * © 2013 xplosion interactive + */ + +package net.pterodactylus.sone.web.ajax; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * {@link JsonReturnObject} that signals an error has occured. + * + * @author David Roden + */ +public class JsonErrorReturnObject extends JsonReturnObject { + + /** The error that has occured. */ + @JsonProperty + private final String error; + + /** + * Creates a new error JSON return object. + * + * @param error + * The error that occured + */ + public JsonErrorReturnObject(String error) { + super(false); + this.error = error; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java index 994f90c..3c7f587 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java @@ -30,11 +30,11 @@ import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetPage; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.io.Closer; -import net.pterodactylus.util.json.JsonObject; -import net.pterodactylus.util.json.JsonUtils; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.web.Page; import net.pterodactylus.util.web.Response; + +import com.fasterxml.jackson.databind.ObjectMapper; import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContext; @@ -49,6 +49,9 @@ public abstract class JsonPage implements FreenetPage { /** The logger. */ private static final Logger logger = Logging.getLogger(JsonPage.class); + /** The JSON serializer. */ + private static final ObjectMapper objectMapper = new ObjectMapper(); + /** The path of the page. */ private final String path; @@ -140,7 +143,7 @@ public abstract class JsonPage implements FreenetPage { * The request to handle * @return The created JSON object */ - protected abstract JsonObject createJsonObject(FreenetRequest request); + protected abstract JsonReturnObject createJsonObject(FreenetRequest request); /** * Returns whether this command needs the form password for authentication @@ -174,8 +177,8 @@ public abstract class JsonPage implements FreenetPage { * * @return A reply signaling success */ - protected static JsonObject createSuccessJsonObject() { - return new JsonObject().put("success", true); + protected static JsonReturnObject createSuccessJsonObject() { + return new JsonReturnObject(true); } /** @@ -185,8 +188,8 @@ public abstract class JsonPage implements FreenetPage { * The error that has occured * @return The JSON object, signalling failure and the error code */ - protected static JsonObject createErrorJsonObject(String error) { - return new JsonObject().put("success", false).put("error", error); + protected static JsonReturnObject createErrorJsonObject(String error) { + return new JsonErrorReturnObject(error); } // @@ -215,22 +218,22 @@ public abstract class JsonPage implements FreenetPage { @Override public Response handleRequest(FreenetRequest request, Response response) throws IOException { if (webInterface.getCore().getPreferences().isRequireFullAccess() && !request.getToadletContext().isAllowedFullAccess()) { - return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); + return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(objectMapper.writeValueAsString(new JsonErrorReturnObject("auth-required"))); } if (needsFormPassword()) { String formPassword = request.getHttpRequest().getParam("formPassword"); if (!webInterface.getFormPassword().equals(formPassword)) { - return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); + return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(objectMapper.writeValueAsString(new JsonErrorReturnObject("auth-required"))); } } if (requiresLogin()) { if (getCurrentSone(request.getToadletContext(), false) == null) { - return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); + return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(objectMapper.writeValueAsString(new JsonErrorReturnObject("auth-required"))); } } try { - JsonObject jsonObject = createJsonObject(request); - return response.setStatusCode(200).setStatusText("OK").setContentType("application/json").write(JsonUtils.format(jsonObject)); + JsonReturnObject jsonObject = createJsonObject(request); + return response.setStatusCode(200).setStatusText("OK").setContentType("application/json").write(objectMapper.writeValueAsString(jsonObject)); } catch (Exception e1) { logger.log(Level.WARNING, "Error executing JSON page!", e1); return response.setStatusCode(500).setStatusText(e1.getMessage()).setContentType("text/plain").write(dumpStackTrace(e1)); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/JsonReturnObject.java b/src/main/java/net/pterodactylus/sone/web/ajax/JsonReturnObject.java new file mode 100644 index 0000000..3b237da --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/JsonReturnObject.java @@ -0,0 +1,99 @@ +/* + * © 2013 xplosion interactive + */ + +package net.pterodactylus.sone.web.ajax; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.BooleanNode; +import com.fasterxml.jackson.databind.node.IntNode; +import com.fasterxml.jackson.databind.node.TextNode; +import com.google.common.collect.Maps; + +/** + * JSON return object for AJAX requests. + * + * @author David Roden + */ +public class JsonReturnObject { + + /** Whether the request was successful. */ + @JsonProperty + private final boolean success; + + /** The returned values. */ + @JsonUnwrapped + private final Map content = Maps.newHashMap(); + + /** + * Creates a new JSON return object. + * + * @param success + * {@code true} if the request was successful, {@code false} otherwise + */ + public JsonReturnObject(boolean success) { + this.success = success; + } + + // + // ACTIONS + // + + /** + * Stores the given value under the given key. + * + * @param key + * The key under which to store the value + * @param value + * The value to store + * @return This JSON return object + */ + public JsonReturnObject put(String key, boolean value) { + return put(key, BooleanNode.valueOf(value)); + } + + /** + * Stores the given value under the given key. + * + * @param key + * The key under which to store the value + * @param value + * The value to store + * @return This JSON return object + */ + public JsonReturnObject put(String key, int value) { + return put(key, new IntNode(value)); + } + + /** + * Stores the given value under the given key. + * + * @param key + * The key under which to store the value + * @param value + * The value to store + * @return This JSON return object + */ + public JsonReturnObject put(String key, String value) { + return put(key, new TextNode(value)); + } + + /** + * Stores the given value under the given key. + * + * @param key + * The key under which to store the value + * @param value + * The value to store + * @return This JSON return object + */ + public JsonReturnObject put(String key, JsonNode value) { + content.put(key, value); + return this; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java index 6787711..55a947a 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java @@ -21,7 +21,6 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user like a {@link Post}. @@ -44,7 +43,7 @@ public class LikeAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type", null); String id = request.getHttpRequest().getParam(type, null); if ((id == null) || (id.length() == 0)) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java index af74426..68668b7 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java @@ -21,7 +21,6 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * Lets the user {@link Core#lockSone(Sone) lock} a {@link Sone}. @@ -44,7 +43,7 @@ public class LockSoneAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); Sone sone = webInterface.getCore().getLocalSone(soneId, false); if (sone == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java index 6610971..cd026ef 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java @@ -24,7 +24,6 @@ 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.json.JsonObject; import com.google.common.base.Optional; @@ -50,7 +49,7 @@ public class MarkAsKnownAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type"); if (!type.equals("sone") && !type.equals("post") && !type.equals("reply")) { return createErrorJsonObject("invalid-type"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.java index 7721aa3..d8781ba 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.java @@ -22,7 +22,6 @@ import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user move a profile field up or down. @@ -51,7 +50,7 @@ public class MoveProfileFieldAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); String fieldId = request.getHttpRequest().getParam("field"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java index d03e030..3661cb1 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java @@ -23,7 +23,6 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user trust a Sone. @@ -47,7 +46,7 @@ public class TrustAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext(), false); if (currentSone == null) { return createErrorJsonObject("auth-required"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.java index 8d209af..65bb14d 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.java @@ -19,7 +19,6 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user unbookmark a post. @@ -46,7 +45,7 @@ public class UnbookmarkAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String id = request.getHttpRequest().getParam("post", null); if ((id == null) || (id.length() == 0)) { return createErrorJsonObject("invalid-post-id"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java index 3d984b9..a285d20 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java @@ -20,7 +20,6 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets a Sone unfollow another Sone. @@ -43,7 +42,7 @@ public class UnfollowSoneAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); if (!webInterface.getCore().getSone(soneId).isPresent()) { return createErrorJsonObject("invalid-sone-id"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java index 0633fda..17be966 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java @@ -21,7 +21,6 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user unlike a {@link Post}. @@ -44,7 +43,7 @@ public class UnlikeAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type", null); String id = request.getHttpRequest().getParam(type, null); if ((id == null) || (id.length() == 0)) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java index 32bb93c..f92132d 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java @@ -21,7 +21,6 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * Lets the user {@link Core#unlockSone(Sone) unlock} a {@link Sone}. @@ -44,7 +43,7 @@ public class UnlockSoneAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); Sone sone = webInterface.getCore().getLocalSone(soneId, false); if (sone == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java index 65d45c9..229f219 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java @@ -23,7 +23,6 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user untrust a Sone. @@ -47,7 +46,7 @@ public class UntrustAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext(), false); if (currentSone == null) { return createErrorJsonObject("auth-required");