/* do nothing. */
}
+ fun redirectTo(target: String?): Nothing =
+ throw RedirectException(target)
+
class RedirectException(val target: String?) : Exception() {
override fun toString(): String = format("RedirectException{target='%s'}", target)
}
soneRequest.core.getPost(postId)?.let {
soneRequest.core.bookmarkPost(it)
}
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
}
setDescription(TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), description))
}.update()
} catch (e: AlbumTitleMustNotBeEmpty) {
- throw RedirectException("emptyAlbumTitle.html")
+ redirectTo("emptyAlbumTitle.html")
}
soneRequest.core.touchConfiguration()
- throw RedirectException("imageBrowser.html?album=${album.id}")
+ redirectTo("imageBrowser.html?album=${album.id}")
}
}
val sender = soneRequest.core.getLocalSone(soneRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
val recipient = soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("recipient", 43))
soneRequest.core.createPost(sender, recipient, TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), text))
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
}
templateContext["errorTextEmpty"] = true
return
}
- val post = soneRequest.core.getPost(postId) ?: throw RedirectException("noPermission.html")
+ val post = soneRequest.core.getPost(postId) ?: redirectTo("noPermission.html")
val sender = soneRequest.core.getLocalSone(soneRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
soneRequest.core.createReply(sender, post, TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), text))
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
}
logger.log(Level.SEVERE, "Could not create Sone for OwnIdentity: $ownIdentity")
}
setCurrentSone(soneRequest.toadletContext, sone)
- throw RedirectException("index.html")
+ redirectTo("index.html")
}
templateContext["errorNoIdentity"] = true
}
override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
soneRequest.core.setDebug()
- throw RedirectException("./")
+ redirectTo("./")
}
}
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
if (soneRequest.isPOST) {
- val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
+ val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: redirectTo("invalid.html")
if (!album.sone.isLocal) {
- throw RedirectException("noPermission.html")
+ redirectTo("noPermission.html")
}
if (soneRequest.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") {
- throw RedirectException("imageBrowser.html?album=${album.id}")
+ redirectTo("imageBrowser.html?album=${album.id}")
}
soneRequest.core.deleteAlbum(album)
- throw RedirectException(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}")
+ redirectTo(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}")
}
val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getParam("album"))
- templateContext["album"] = album ?: throw RedirectException("invalid.html")
+ templateContext["album"] = album ?: redirectTo("invalid.html")
}
}
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
if (soneRequest.isPOST) {
- val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
+ val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: redirectTo("invalid.html")
if (!image.sone.isLocal) {
- throw RedirectException("noPermission.html")
+ redirectTo("noPermission.html")
}
if (soneRequest.httpRequest.isPartSet("abortDelete")) {
- throw RedirectException("imageBrowser.html?image=${image.id}")
+ redirectTo("imageBrowser.html?image=${image.id}")
}
soneRequest.core.deleteImage(image)
- throw RedirectException("imageBrowser.html?album=${image.album.id}")
+ redirectTo("imageBrowser.html?album=${image.album.id}")
}
- val image = soneRequest.core.getImage(soneRequest.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html")
+ val image = soneRequest.core.getImage(soneRequest.httpRequest.getParam("image")) ?: redirectTo("invalid.html")
if (!image.sone.isLocal) {
- throw RedirectException("noPermission.html")
+ redirectTo("noPermission.html")
}
templateContext["image"] = image
}
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
if (soneRequest.isPOST) {
- val post = soneRequest.core.getPost(soneRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: throw RedirectException("noPermission.html")
+ val post = soneRequest.core.getPost(soneRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: redirectTo("noPermission.html")
val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
if (!post.sone.isLocal) {
- throw RedirectException("noPermission.html")
+ redirectTo("noPermission.html")
}
if (soneRequest.httpRequest.isPartSet("confirmDelete")) {
soneRequest.core.deletePost(post)
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
} else if (soneRequest.httpRequest.isPartSet("abortDelete")) {
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
templateContext["post"] = post
templateContext["returnPage"] = returnPage
return
}
- templateContext["post"] = soneRequest.core.getPost(soneRequest.httpRequest.getParam("post")) ?: throw RedirectException("noPermission.html")
+ templateContext["post"] = soneRequest.core.getPost(soneRequest.httpRequest.getParam("post")) ?: redirectTo("noPermission.html")
templateContext["returnPage"] = soneRequest.httpRequest.getParam("returnPage")
}
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
if (soneRequest.isPOST) {
- val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
+ val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: redirectTo("invalid.html")
if (soneRequest.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") {
currentSone.profile = currentSone.profile.apply { removeField(field) }
}
- throw RedirectException("editProfile.html#profile-fields")
+ redirectTo("editProfile.html#profile-fields")
}
- val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
+ val field = currentSone.profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: redirectTo("invalid.html")
templateContext["field"] = field
}
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
if (soneRequest.isPOST) {
val replyId = soneRequest.httpRequest.getPartAsStringFailsafe("reply", 36)
- val reply = soneRequest.core.getPostReply(replyId) ?: throw RedirectException("noPermission.html")
+ val reply = soneRequest.core.getPostReply(replyId) ?: redirectTo("noPermission.html")
if (!reply.sone.isLocal) {
- throw RedirectException("noPermission.html")
+ redirectTo("noPermission.html")
}
val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
if (soneRequest.httpRequest.isPartSet("confirmDelete")) {
soneRequest.core.deleteReply(reply)
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
if (soneRequest.httpRequest.isPartSet("abortDelete")) {
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
templateContext["reply"] = replyId
templateContext["returnPage"] = returnPage
if (soneRequest.httpRequest.isPartSet("deleteSone")) {
soneRequest.core.deleteSone(currentSone)
}
- throw RedirectException("index.html")
+ redirectTo("index.html")
}
}
val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
val notificationId = soneRequest.httpRequest.getPartAsStringFailsafe("notification", 36)
soneRequest.webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss()
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
}
if (soneRequest.isPOST) {
soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("sone", 44))
?.run { soneRequest.core.distrustSone(currentSone, this) }
- throw RedirectException(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
+ redirectTo(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
}
}
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
if (soneRequest.isPOST) {
- val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
- album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
+ val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: redirectTo("invalid.html")
+ album.takeUnless { it.sone.isLocal }?.run { redirectTo("noPermission.html") }
if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
album.parent?.moveAlbumUp(album)
soneRequest.core.touchConfiguration()
- throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
+ redirectTo("imageBrowser.html?album=${album.parent?.id}")
} else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
album.parent?.moveAlbumDown(album)
soneRequest.core.touchConfiguration()
- throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
+ redirectTo("imageBrowser.html?album=${album.parent?.id}")
} else {
try {
album.modify()
.setDescription(soneRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
.update()
} catch (e: AlbumTitleMustNotBeEmpty) {
- throw RedirectException("emptyAlbumTitle.html")
+ redirectTo("emptyAlbumTitle.html")
}
soneRequest.core.touchConfiguration()
- throw RedirectException("imageBrowser.html?album=${album.id}")
+ redirectTo("imageBrowser.html?album=${album.id}")
}
}
}
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
if (soneRequest.isPOST) {
- val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html")
+ val image = soneRequest.core.getImage(soneRequest.httpRequest.getPartAsStringFailsafe("image", 36)) ?: redirectTo("invalid.html")
if (!image.sone.isLocal) {
- throw RedirectException("noPermission.html")
+ redirectTo("noPermission.html")
}
soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).let { returnPage ->
if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
.update()
soneRequest.core.touchConfiguration()
} catch (e: ImageTitleMustNotBeEmpty) {
- throw RedirectException("emptyImageTitle.html")
+ redirectTo("emptyImageTitle.html")
}
}
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
}
}
currentSone.profile.let { profile ->
if (soneRequest.isPOST) {
if (soneRequest.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") {
- throw RedirectException("editProfile.html#profile-fields")
+ redirectTo("editProfile.html#profile-fields")
}
- val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html")
+ val field = profile.getFieldById(soneRequest.httpRequest.getPartAsStringFailsafe("field", 36)) ?: redirectTo("invalid.html")
soneRequest.httpRequest.getPartAsStringFailsafe("name", 256).let { name ->
try {
if (name != field.name) {
field.name = name
currentSone.profile = profile
}
- throw RedirectException("editProfile.html#profile-fields")
+ redirectTo("editProfile.html#profile-fields")
} catch (e: IllegalArgumentException) {
templateContext["duplicateFieldName"] = true
return
}
}
}
- templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html")
+ templateContext["field"] = profile.getFieldById(soneRequest.httpRequest.getParam("field")) ?: redirectTo("invalid.html")
}
}
}
currentSone.profile = profile
soneRequest.core.touchConfiguration()
- throw RedirectException("editProfile.html")
+ redirectTo("editProfile.html")
} else if (soneRequest.httpRequest.getPartAsStringFailsafe("add-field", 4) == "true") {
val fieldName = soneRequest.httpRequest.getPartAsStringFailsafe("field-name", 100)
try {
profile.addField(fieldName)
currentSone.profile = profile
soneRequest.core.touchConfiguration()
- throw RedirectException("editProfile.html#profile-fields")
+ redirectTo("editProfile.html#profile-fields")
} catch (e: DuplicateField) {
templateContext["fieldName"] = fieldName
templateContext["duplicateFieldName"] = true
}
} else profile.fields.forEach { field ->
if (soneRequest.httpRequest.getPartAsStringFailsafe("delete-field-${field.id}", 4) == "true") {
- throw RedirectException("deleteProfileField.html?field=${field.id}")
+ redirectTo("deleteProfileField.html?field=${field.id}")
} else if (soneRequest.httpRequest.getPartAsStringFailsafe("edit-field-${field.id}", 4) == "true") {
- throw RedirectException("editProfileField.html?field=${field.id}")
+ redirectTo("editProfileField.html?field=${field.id}")
} else if (soneRequest.httpRequest.getPartAsStringFailsafe("move-down-field-${field.id}", 4) == "true") {
profile.moveFieldDown(field)
currentSone.profile = profile
- throw RedirectException("editProfile.html#profile-fields")
+ redirectTo("editProfile.html#profile-fields")
} else if (soneRequest.httpRequest.getPartAsStringFailsafe("move-up-field-${field.id}", 4) == "true") {
profile.moveFieldUp(field)
currentSone.profile = profile
- throw RedirectException("editProfile.html#profile-fields")
+ redirectTo("editProfile.html#profile-fields")
}
}
}
soneRequest.core.followSone(currentSone, sone.first)
soneRequest.core.markSoneKnown(sone.second)
}
- throw RedirectException(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
+ redirectTo(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256))
}
}
"reply" -> currentSone.addLikedReplyId(soneRequest.parameters["reply", 36]!!)
}
}
- throw RedirectException(soneRequest.parameters["returnPage", 256]!!)
+ redirectTo(soneRequest.parameters["returnPage", 256]!!)
}
}
soneRequest.parameters["sone", 44]!!
.let { soneRequest.core.getLocalSone(it) }
?.let { soneRequest.core.lockSone(it) }
- throw RedirectException(returnPage)
+ redirectTo(returnPage)
}
}
soneRequest.core.getLocalSone(soneId)?.let { sone ->
setCurrentSone(soneRequest.toadletContext, sone)
val target = soneRequest.httpRequest.getParam("target").emptyToNull ?: "index.html"
- throw RedirectException(target)
+ redirectTo(target)
}
}
templateContext["sones"] = soneRequest.core.localSones.sortedWith(Sone.NICE_NAME_COMPARATOR)
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
setCurrentSone(soneRequest.toadletContext, null)
- throw RedirectException("index.html")
+ redirectTo("index.html")
}
override fun isEnabled(soneRequest: SoneRequest): Boolean =
"sone" -> ids.mapNotNull(soneRequest.core::getSone).forEach(soneRequest.core::markSoneKnown)
"post" -> ids.mapNotNull(soneRequest.core::getPost).forEach(soneRequest.core::markPostKnown)
"reply" -> ids.mapNotNull(soneRequest.core::getPostReply).forEach(soneRequest.core::markReplyKnown)
- else -> throw RedirectException("invalid.html")
+ else -> redirectTo("invalid.html")
}
- throw RedirectException(soneRequest.parameters["returnPage", 256]!!)
+ redirectTo(soneRequest.parameters["returnPage", 256]!!)
}
}
if (fieldsWithErrors.isEmpty()) {
soneRequest.core.touchConfiguration()
- throw RedirectException("options.html")
+ redirectTo("options.html")
}
templateContext["fieldErrors"] = fieldsWithErrors
}
if (soneRequest.parameters["fetch", 8] == "true") {
soneRescuer.startNextFetch()
}
- throw RedirectException("rescue.html")
+ redirectTo("rescue.html")
}
}
}
}
- private fun redirect(target: String): Nothing = throw RedirectException(target)
+ private fun redirect(target: String): Nothing = redirectTo(target)
enum class Optionality {
OPTIONAL,
soneRequest.core.getSone(soneRequest.parameters["sone"]!!)?.let { sone ->
soneRequest.core.trustSone(currentSone, sone)
}
- throw RedirectException(soneRequest.parameters["returnPage", 256])
+ redirectTo(soneRequest.parameters["returnPage", 256])
}
}
soneRequest.core.bookmarkedPosts
.filterNot(Post::isLoaded)
.forEach(soneRequest.core::unbookmarkPost)
- throw RedirectException("bookmarks.html")
+ redirectTo("bookmarks.html")
}
soneRequest.isPOST -> {
soneRequest.parameters["post", 36]
?.let(soneRequest.core::getPost)
?.also(soneRequest.core::unbookmarkPost)
- throw RedirectException(soneRequest.parameters["returnPage", 256])
+ redirectTo(soneRequest.parameters["returnPage", 256])
}
}
}
if (soneRequest.isPOST) {
soneRequest.parameters["sone"]!!.split(Regex("[ ,]+"))
.forEach { soneRequest.core.unfollowSone(currentSone, it) }
- throw RedirectException(soneRequest.parameters["returnPage", 256])
+ redirectTo(soneRequest.parameters["returnPage", 256])
}
}
"post" -> currentSone.removeLikedPostId(soneRequest.parameters["post"]!!)
"reply" -> currentSone.removeLikedReplyId(soneRequest.parameters["reply"]!!)
}
- throw RedirectException(soneRequest.parameters["returnPage", 256])
+ redirectTo(soneRequest.parameters["returnPage", 256])
}
}
soneRequest.parameters["sone", 44]
.let(soneRequest.core::getLocalSone)
?.also(soneRequest.core::unlockSone)
- throw RedirectException(soneRequest.parameters["returnPage", 256])
+ redirectTo(soneRequest.parameters["returnPage", 256])
}
}
soneRequest.parameters["sone", 44]!!
.let(soneRequest.core::getSone)
?.also { soneRequest.core.untrustSone(currentSone, it) }
- throw RedirectException(soneRequest.parameters["returnPage", 256])
+ redirectTo(soneRequest.parameters["returnPage", 256])
}
}
override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
if (soneRequest.isPOST) {
- val parentAlbum = soneRequest.parameters["parent"]!!.let(soneRequest.core::getAlbum) ?: throw RedirectException("noPermission.html")
+ val parentAlbum = soneRequest.parameters["parent"]!!.let(soneRequest.core::getAlbum) ?: redirectTo("noPermission.html")
if (parentAlbum.sone != currentSone) {
- throw RedirectException("noPermission.html")
+ redirectTo("noPermission.html")
}
- val title = soneRequest.parameters["title", 200].emptyToNull ?: throw RedirectException("emptyImageTitle.html")
+ val title = soneRequest.parameters["title", 200].emptyToNull ?: redirectTo("emptyImageTitle.html")
val uploadedFile = soneRequest.httpRequest.getUploadedFile("image")
val bytes = uploadedFile.data.use { it.toByteArray() }
setTitle(title)
setDescription(TextFilter.filter(soneRequest.headers["Host"], soneRequest.parameters["description", 4000]))
}.update()
- throw RedirectException("imageBrowser.html?album=${parentAlbum.id}")
+ redirectTo("imageBrowser.html?album=${parentAlbum.id}")
}
}