import net.pterodactylus.sone.utils.emptyToNull
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user bookmark a post.
*/
-class BookmarkAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage("bookmark.ajax", webInterface) {
+@ToadletPath("bookmark.ajax")
+class BookmarkAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val requiresLogin = false
/**
* AJAX handler that creates a new post.
*/
-class CreatePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage("createPost.ajax", webInterface) {
+@ToadletPath("createPost.ajax")
+class CreatePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["text"].emptyToNull
/**
* This AJAX page create a reply.
*/
-class CreateReplyAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage("createReply.ajax", webInterface) {
+@ToadletPath("createReply.ajax")
+class CreateReplyAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest): JsonReturnObject =
request.parameters["post"].emptyToNull
/**
* This AJAX page deletes a post.
*/
-class DeletePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage("deletePost.ajax", webInterface) {
+@ToadletPath("deletePost.ajax")
+class DeletePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["post"]
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user delete a profile field.
*/
-class DeleteProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("deleteProfileField.ajax", webInterface) {
+@ToadletPath("deleteProfileField.ajax")
+class DeleteProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
currentSone.profile.let { profile ->
/**
* This AJAX page deletes a reply.
*/
-class DeleteReplyAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("deleteReply.ajax", webInterface) {
+@ToadletPath("deleteReply.ajax")
+class DeleteReplyAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["reply"]
import net.pterodactylus.sone.utils.let
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user dismiss a notification.
*/
-class DismissNotificationAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("dismissNotification.ajax", webInterface) {
+@ToadletPath("dismissNotification.ajax")
+class DismissNotificationAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val requiresLogin = false
*
* @see Core.distrustSone(Sone, Sone)
*/
-class DistrustAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("distrustSone.ajax", webInterface) {
+@ToadletPath("distrustSone.ajax")
+class DistrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
import net.pterodactylus.sone.utils.ifTrue
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* Page that stores a user’s album modifications.
*/
-class EditAlbumAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage("editAlbum.ajax", webInterface) {
+@ToadletPath("editAlbum.ajax")
+class EditAlbumAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override fun createJsonObject(request: FreenetRequest) =
request.parameters["album"]!!
import net.pterodactylus.sone.utils.ifTrue
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.TemplateContext
import javax.inject.Inject
/**
* Page that stores a user’s image modifications.
*/
+@ToadletPath("editImage.ajax")
class EditImageAjaxPage @Inject constructor(webInterface: WebInterface,
private val parserFilter: ParserFilter,
private val shortenFilter: ShortenFilter,
- private val renderFilter: RenderFilter) : JsonPage("editImage.ajax", webInterface) {
+ private val renderFilter: RenderFilter) : JsonPage(webInterface) {
override fun createJsonObject(request: FreenetRequest) =
request.parameters["image"]
import net.pterodactylus.sone.utils.ifFalse
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user rename a profile field.
*/
-class EditProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("editProfileField.ajax", webInterface) {
+@ToadletPath("editProfileField.ajax")
+class EditProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
currentSone.profile.let { profile ->
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets a Sone follow another Sone.
*/
-class FollowSoneAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("followSone.ajax", webInterface) {
+@ToadletPath("followSone.ajax")
+class FollowSoneAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
import net.pterodactylus.sone.utils.jsonObject
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that retrieves the number of “likes” a [net.pterodactylus.sone.data.Post]
* or [net.pterodactylus.sone.data.PostReply] has.
*/
-class GetLikesAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("getLikes.ajax", webInterface) {
+@ToadletPath("getLikes.ajax")
+class GetLikesAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val needsFormPassword = false
import net.pterodactylus.sone.utils.jsonArray
import net.pterodactylus.sone.utils.jsonObject
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* Renders linked elements after they have been loaded.
*/
+@ToadletPath("getLinkedElement.ajax")
class GetLinkedElementAjaxPage @Inject constructor(webInterface: WebInterface, private val elementLoader: ElementLoader, private val linkedElementRenderFilter: LinkedElementRenderFilter):
- JsonPage("getLinkedElement.ajax", webInterface) {
+ JsonPage(webInterface) {
override val needsFormPassword = false
override val requiresLogin = false
import net.pterodactylus.sone.utils.jsonArray
import net.pterodactylus.sone.utils.jsonObject
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.notify.Notification
import net.pterodactylus.util.notify.TemplateNotification
import java.io.StringWriter
/**
* AJAX handler to return all current notifications.
*/
-class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("getNotifications.ajax", webInterface) {
+@ToadletPath("getNotifications.ajax")
+class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val needsFormPassword = false
override val requiresLogin = false
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.utils.render
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import javax.inject.Inject
/**
* This AJAX handler retrieves information and rendered representation of a [Post].
*/
-class GetPostAjaxPage @Inject constructor(webInterface: WebInterface, private val postTemplate: Template) :
- LoggedInJsonPage("getPost.ajax", webInterface) {
+@ToadletPath("getPost.ajax")
+class GetPostAjaxPage @Inject constructor(webInterface: WebInterface, private val postTemplate: Template) : LoggedInJsonPage(webInterface) {
override val needsFormPassword = false
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.utils.render
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.template.Template
import javax.inject.Inject
/**
* This AJAX page returns the details of a reply.
*/
-class GetReplyAjaxPage @Inject constructor(webInterface: WebInterface, private val template: Template) :
- LoggedInJsonPage("getReply.ajax", webInterface) {
+@ToadletPath("getReply.ajax")
+class GetReplyAjaxPage @Inject constructor(webInterface: WebInterface, private val template: Template) : LoggedInJsonPage(webInterface) {
override val needsFormPassword = false
import net.pterodactylus.sone.utils.jsonObject
import net.pterodactylus.sone.utils.toArray
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import java.text.SimpleDateFormat
import java.util.TimeZone
import javax.inject.Inject
* The “get status” AJAX handler returns all information that is necessary to
* update the web interface in real-time.
*/
+@ToadletPath("getStatus.ajax")
class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, timeZone: TimeZone):
- JsonPage("getStatus.ajax", webInterface) {
+ JsonPage(webInterface) {
@Inject constructor(webInterface: WebInterface, elementLoader: ElementLoader, timeTextConverter: TimeTextConverter, l10nFilter: L10nFilter):
this(webInterface, elementLoader, timeTextConverter, l10nFilter, TimeZone.getDefault())
import net.pterodactylus.sone.utils.jsonObject
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import java.text.SimpleDateFormat
import java.util.TimeZone
import javax.inject.Inject
/**
* Ajax page that returns a formatted, relative timestamp for replies or posts.
*/
+@ToadletPath("getTimes.ajax")
class GetTimesAjaxPage @Inject constructor(webInterface: WebInterface,
private val timeTextConverter: TimeTextConverter,
private val l10nFilter: L10nFilter,
- timeZone: TimeZone) : JsonPage("getTimes.ajax", webInterface) {
+ timeZone: TimeZone) : JsonPage(webInterface) {
private val dateTimeFormatter = SimpleDateFormat("MMM d, yyyy, HH:mm:ss").apply {
this.timeZone = timeZone
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* Returns the translation for a given key as JSON object.
*/
-class GetTranslationAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("getTranslation.ajax", webInterface) {
+@ToadletPath("getTranslation.ajax")
+class GetTranslationAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val needsFormPassword = false
override val requiresLogin = false
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.SessionProvider
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.util.web.Page
import net.pterodactylus.util.web.Response
import java.io.ByteArrayOutputStream
* A JSON page is a specialized [Page] that will always return a JSON
* object to the browser, e.g. for use with AJAX or other scripting frameworks.
*/
-abstract class JsonPage(private val path: String, protected val webInterface: WebInterface) : Page<FreenetRequest> {
+abstract class JsonPage(protected val webInterface: WebInterface) : Page<FreenetRequest> {
private val objectMapper = ObjectMapper()
private val sessionProvider: SessionProvider = webInterface
protected val core = webInterface.core
- override fun getPath() = path
+ override fun getPath() = toadletPath
override fun isPrefixPage() = false
open val needsFormPassword = true
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user like a [net.pterodactylus.sone.data.Post].
*/
-class LikeAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("like.ajax", webInterface) {
+@ToadletPath("like.ajax")
+class LikeAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
when (request.parameters["type"]) {
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* Lets the user [lock][net.pterodactylus.sone.core.Core.lockSone] a [Sone][net.pterodactylus.sone.data.Sone].
*/
-class LockSoneAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("lockSone.ajax", webInterface) {
+@ToadletPath("lockSone.ajax")
+class LockSoneAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val requiresLogin = false
/**
* Base JSON page for all pages that require the user to be logged in.
*/
-open class LoggedInJsonPage(path: String, webInterface: WebInterface) : JsonPage(path, webInterface) {
+open class LoggedInJsonPage(webInterface: WebInterface) : JsonPage(webInterface) {
final override val requiresLogin = true
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s,
* [net.pterodactylus.sone.data.Post]s, or [net.pterodactylus.sone.data.Reply]s as known.
*/
-class MarkAsKnownAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("markAsKnown.ajax", webInterface) {
+@ToadletPath("markAsKnown.ajax")
+class MarkAsKnownAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val requiresLogin = false
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* @see net.pterodactylus.sone.data.Profile#moveFieldUp(Field)
* @see net.pterodactylus.sone.data.Profile#moveFieldDown(Field)
*/
-class MoveProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("moveProfileField.ajax", webInterface) {
+@ToadletPath("moveProfileField.ajax")
+class MoveProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
currentSone.profile.let { profile ->
*
* @see net.pterodactylus.sone.core.Core.trustSone
*/
-class TrustAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("trustSone.ajax", webInterface) {
+@ToadletPath("trustSone.ajax")
+class TrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user unbookmark a post.
*/
-class UnbookmarkAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("unbookmark.ajax", webInterface) {
+@ToadletPath("unbookmark.ajax")
+class UnbookmarkAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val requiresLogin = false
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets a Sone unfollow another Sone.
*/
-class UnfollowSoneAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("unfollowSone.ajax", webInterface) {
+@ToadletPath("unfollowSone.ajax")
+class UnfollowSoneAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
import net.pterodactylus.sone.utils.emptyToNull
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user unlike a [net.pterodactylus.sone.data.Post].
*/
-class UnlikeAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("unlike.ajax", webInterface) {
+@ToadletPath("unlike.ajax")
+class UnlikeAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = when (request.parameters["type"]) {
"post" -> request.processEntity("post", currentSone::removeLikedPostId)
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* Lets the user [unlock][net.pterodactylus.sone.core.Core.unlockSone] a [Sone][net.pterodactylus.sone.data.Sone].
*/
-class UnlockSoneAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("unlockSone.ajax", webInterface) {
+@ToadletPath("unlockSone.ajax")
+class UnlockSoneAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
override val requiresLogin = false
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.utils.parameters
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import javax.inject.Inject
/**
* AJAX page that lets the user [untrust][net.pterodactylus.sone.core.Core.untrustSone] a [Sone].
*/
-class UntrustAjaxPage @Inject constructor(webInterface: WebInterface) :
- LoggedInJsonPage("untrustSone.ajax", webInterface) {
+@ToadletPath("untrustSone.ajax")
+class UntrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
private val outputStream = ByteArrayOutputStream()
private val response = Response(outputStream)
- private val page = object : JsonPage("path.html", webInterface) {
+ private val page = object : JsonPage(webInterface) {
override val needsFormPassword get() = this@JsonPageBaseTest.needsFormPassword
package net.pterodactylus.sone.web.ajax
+import net.pterodactylus.sone.web.*
+import net.pterodactylus.sone.web.page.*
+
/**
* Unit test for [LoggedInJsonPageTest].
*/
-class LoggedInJsonPageTest : JsonPageTest("path", requiresLogin = true, pageSupplier = { webInterface -> LoggedInJsonPage("path", webInterface) })
+class LoggedInJsonPageTest : JsonPageTest("path", requiresLogin = true, pageSupplier = ::TestPage)
+
+@ToadletPath("path")
+class TestPage(webInterface: WebInterface) : LoggedInJsonPage(webInterface)