Move web pages to their own package
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 8 Apr 2017 13:12:20 +0000 (15:12 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 8 Apr 2017 13:22:58 +0000 (15:22 +0200)
184 files changed:
src/main/java/net/pterodactylus/sone/main/DebugLoaders.java
src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt [deleted file]
src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt [deleted file]
src/main/java/net/pterodactylus/sone/web/EditImagePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/EditProfilePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/FollowSonePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/GetImagePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/IndexPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/LikePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/LockSonePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/LogoutPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/NewPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/OptionsPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/ReloadingPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/RescuePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/SearchPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/TrustPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/UnlikePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/UntrustPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/UploadImagePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/ViewPostPage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java [deleted file]
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/pages/EditImagePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/EditProfileFieldPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/EditProfilePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/FollowSonePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/GetImagePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/ImageBrowserPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/IndexPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/KnownSonesPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/LikePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/LockSonePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/LogoutPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/MarkAsKnownPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/NewPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/OptionsPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/ReloadingPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/RescuePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/SearchPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/SoneTemplatePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/TrustPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/UnbookmarkPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/UnfollowSonePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/UnlikePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/UnlockSonePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/UntrustPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/UploadImagePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/ViewPostPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/pages/ViewSonePage.java [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/AboutPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/BookmarkPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/BookmarksPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/CreatePostPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/CreateSonePage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/DeleteAlbumPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/DeleteImagePage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/DeletePostPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/DeleteProfileFieldPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/DeleteReplyPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/DeleteSonePage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/DismissNotificationPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/DistrustPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/EditAlbumPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/LoginPage.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt [new file with mode: 0644]
src/test/java/net/pterodactylus/sone/web/CreateAlbumPageTest.kt [deleted file]
src/test/java/net/pterodactylus/sone/web/CreateReplyPageTest.kt [deleted file]
src/test/java/net/pterodactylus/sone/web/NewPageTest.java [deleted file]
src/test/java/net/pterodactylus/sone/web/WebPageTest.java [deleted file]
src/test/java/net/pterodactylus/sone/web/pages/NewPageTest.java [new file with mode: 0644]
src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/AboutPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/BookmarkPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/BookmarksPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/CreatePostPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/CreateSonePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/DeleteAlbumPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/DeleteImagePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/DeletePostPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/DeleteProfileFieldPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/DeleteReplyPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/DeleteSonePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/DismissNotificationPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/DistrustPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/EditAlbumPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/EditImagePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/EditProfileFieldPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/FollowSonePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/GetImagePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/ImageBrowserPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/IndexPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/KnownSonesPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/LikePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/LockSonePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/LoginPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/LogoutPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/MarkAsKnownPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/OptionsPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/ReloadingPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/RescuePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/SearchPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/SoneTemplatePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/TrustPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/UnbookmarkPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/UnfollowSonePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/UnlikePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/UnlockSonePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/UntrustPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/UploadImagePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/ViewPostPageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/ViewSonePageTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/web/pages/AboutPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarksPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/GetImagePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/LockSonePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/LogoutPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt [new file with mode: 0644]
src/test/resources/net/pterodactylus/sone/web/image.png [deleted file]
src/test/resources/net/pterodactylus/sone/web/no-image.png [deleted file]
src/test/resources/net/pterodactylus/sone/web/pages/image.png [new file with mode: 0644]
src/test/resources/net/pterodactylus/sone/web/pages/no-image.png [new file with mode: 0644]

index 11755e0..d0168ae 100644 (file)
@@ -3,7 +3,7 @@ package net.pterodactylus.sone.main;
 import java.io.File;
 
 import net.pterodactylus.sone.template.FilesystemTemplate;
-import net.pterodactylus.sone.web.ReloadingPage;
+import net.pterodactylus.sone.web.pages.ReloadingPage;
 import net.pterodactylus.util.template.FilesystemTemplateProvider;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateProvider;
diff --git a/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt b/src/main/java/net/pterodactylus/sone/web/CreateAlbumPage.kt
deleted file mode 100644 (file)
index e91ad37..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package net.pterodactylus.sone.web
-
-import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
-import net.pterodactylus.sone.text.TextFilter
-import net.pterodactylus.sone.utils.isPOST
-import net.pterodactylus.sone.web.page.FreenetRequest
-import net.pterodactylus.util.template.Template
-import net.pterodactylus.util.template.TemplateContext
-
-/**
- * Page that lets the user create a new album.
- */
-class CreateAlbumPage(template: Template, webInterface: WebInterface):
-               SoneTemplatePage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, true) {
-
-       override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
-               if (request.isPOST) {
-                       val name = request.httpRequest.getPartAsStringFailsafe("name", 64).trim()
-                       if (name.isEmpty()) {
-                               templateContext["nameMissing"] = true
-                               return
-                       }
-                       val description = request.httpRequest.getPartAsStringFailsafe("description", 256).trim()
-                       val currentSone = webInterface.getCurrentSoneCreatingSession(request.toadletContext)
-                       val parentId = request.httpRequest.getPartAsStringFailsafe("parent", 36)
-                       val parent = if (parentId == "") currentSone.rootAlbum else webInterface.core.getAlbum(parentId)
-                       val album = webInterface.core.createAlbum(currentSone, parent)
-                       try {
-                               album.modify().apply {
-                                       setTitle(name)
-                                       setDescription(TextFilter.filter(request.httpRequest.getHeader("Host"), description))
-                               }.update()
-                       } catch (e: AlbumTitleMustNotBeEmpty) {
-                               throw RedirectException("emptyAlbumTitle.html")
-                       }
-                       webInterface.core.touchConfiguration()
-                       throw RedirectException("imageBrowser.html?album=${album.id}")
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.kt
deleted file mode 100644 (file)
index 43fbeaf..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-package net.pterodactylus.sone.web
-
-import net.pterodactylus.sone.text.TextFilter
-import net.pterodactylus.sone.utils.isPOST
-import net.pterodactylus.sone.web.page.FreenetRequest
-import net.pterodactylus.util.template.Template
-import net.pterodactylus.util.template.TemplateContext
-
-/**
- * This page lets the user post a reply to a post.
- */
-class CreateReplyPage(template: Template, webInterface: WebInterface):
-               SoneTemplatePage("createReply.html", template, "Page.CreateReply.Title", webInterface, true) {
-
-       override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
-               val postId = request.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
-               val text = request.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
-               val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
-               if (request.isPOST) {
-                       if (text == "") {
-                               templateContext["errorTextEmpty"] = true
-                               return
-                       }
-                       val post = webInterface.core.getPost(postId).orNull() ?: throw RedirectException("noPermission.html")
-                       val sender = webInterface.core.getLocalSone(request.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(request.toadletContext)
-                       webInterface.core.createReply(sender, post, TextFilter.filter(request.httpRequest.getHeader("Host"), text))
-                       throw RedirectException(returnPage)
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/EditImagePage.java b/src/main/java/net/pterodactylus/sone/web/EditImagePage.java
deleted file mode 100644 (file)
index 419bc1d..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Sone - EditImagePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.text.TextFilter;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * Page that lets the user edit title and description of an {@link Image}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class EditImagePage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “edit image” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public EditImagePage(Template template, WebInterface webInterface) {
-               super("editImage.html", template, "Page.EditImage.Title", webInterface, true);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       String imageId = request.getHttpRequest().getPartAsStringFailsafe("image", 36);
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-                       Image image = webInterface.getCore().getImage(imageId, false);
-                       if (image == null) {
-                               throw new RedirectException("invalid.html");
-                       }
-                       if (!image.getSone().isLocal()) {
-                               throw new RedirectException("noPermission.html");
-                       }
-                       if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveLeft", 4))) {
-                               image.getAlbum().moveImageUp(image);
-                       } else if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveRight", 4))) {
-                               image.getAlbum().moveImageDown(image);
-                       } else {
-                               String title = request.getHttpRequest().getPartAsStringFailsafe("title", 100).trim();
-                               String description = request.getHttpRequest().getPartAsStringFailsafe("description", 1024).trim();
-                               if (title.length() == 0) {
-                                       throw new RedirectException("emptyImageTitle.html");
-                               }
-                               image.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
-                       }
-                       webInterface.getCore().touchConfiguration();
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java
deleted file mode 100644 (file)
index bbc6d6b..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Sone - EditProfileFieldPage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Profile;
-import net.pterodactylus.sone.data.Profile.Field;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * Page that lets the user edit the name of a profile field.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class EditProfileFieldPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “edit profile field” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public EditProfileFieldPage(Template template, WebInterface webInterface) {
-               super("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, true);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               Sone currentSone = getCurrentSone(request.getToadletContext());
-               Profile profile = currentSone.getProfile();
-
-               /* get parameters from request. */
-               String fieldId = request.getHttpRequest().getParam("field");
-               Field field = profile.getFieldById(fieldId);
-               if (field == null) {
-                       throw new RedirectException("invalid.html");
-               }
-
-               /* process the POST request. */
-               if (request.getMethod() == Method.POST) {
-                       if (request.getHttpRequest().getPartAsStringFailsafe("cancel", 4).equals("true")) {
-                               throw new RedirectException("editProfile.html#profile-fields");
-                       }
-                       fieldId = request.getHttpRequest().getPartAsStringFailsafe("field", 36);
-                       field = profile.getFieldById(fieldId);
-                       if (field == null) {
-                               throw new RedirectException("invalid.html");
-                       }
-                       String name = request.getHttpRequest().getPartAsStringFailsafe("name", 256);
-                       Field existingField = profile.getFieldByName(name);
-                       if ((existingField != null) && (!field.equals(existingField))) {
-                               templateContext.set("duplicateFieldName", true);
-                       } else {
-                               if (!name.equals(field.getName())) {
-                                       field.setName(name);
-                                       currentSone.setProfile(profile);
-                               }
-                               throw new RedirectException("editProfile.html#profile-fields");
-                       }
-               }
-
-               /* store current values in template. */
-               templateContext.set("field", field);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java
deleted file mode 100644 (file)
index cffdeb9..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Sone - EditProfilePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.text.TextFilter.filter;
-import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
-
-import java.util.List;
-
-import net.pterodactylus.sone.data.Profile;
-import net.pterodactylus.sone.data.Profile.DuplicateField;
-import net.pterodactylus.sone.data.Profile.Field;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-import freenet.clients.http.ToadletContext;
-
-/**
- * This page lets the user edit her profile.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class EditProfilePage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “edit profile” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public EditProfilePage(Template template, WebInterface webInterface) {
-               super("editProfile.html", template, "Page.EditProfile.Title", webInterface, true);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               ToadletContext toadletContenxt = request.getToadletContext();
-               Sone currentSone = getCurrentSone(toadletContenxt);
-               Profile profile = currentSone.getProfile();
-               String firstName = profile.getFirstName();
-               String middleName = profile.getMiddleName();
-               String lastName = profile.getLastName();
-               Integer birthDay = profile.getBirthDay();
-               Integer birthMonth = profile.getBirthMonth();
-               Integer birthYear = profile.getBirthYear();
-               String avatarId = profile.getAvatar();
-               List<Field> fields = profile.getFields();
-               if (request.getMethod() == Method.POST) {
-                       if (request.getHttpRequest().getPartAsStringFailsafe("save-profile", 4).equals("true")) {
-                               firstName = request.getHttpRequest().getPartAsStringFailsafe("first-name", 256).trim();
-                               middleName = request.getHttpRequest().getPartAsStringFailsafe("middle-name", 256).trim();
-                               lastName = request.getHttpRequest().getPartAsStringFailsafe("last-name", 256).trim();
-                               birthDay = parseInt(request.getHttpRequest().getPartAsStringFailsafe("birth-day", 256).trim(), null);
-                               birthMonth = parseInt(request.getHttpRequest().getPartAsStringFailsafe("birth-month", 256).trim(), null);
-                               birthYear = parseInt(request.getHttpRequest().getPartAsStringFailsafe("birth-year", 256).trim(), null);
-                               avatarId = request.getHttpRequest().getPartAsStringFailsafe("avatarId", 36);
-                               profile.setFirstName(firstName.length() > 0 ? firstName : null);
-                               profile.setMiddleName(middleName.length() > 0 ? middleName : null);
-                               profile.setLastName(lastName.length() > 0 ? lastName : null);
-                               profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
-                               profile.setAvatar(webInterface.getCore().getImage(avatarId, false));
-                               for (Field field : fields) {
-                                       String value = request.getHttpRequest().getPartAsStringFailsafe("field-" + field.getId(), 400);
-                                       String filteredValue = filter(request.getHttpRequest().getHeader("Host"), value);
-                                       field.setValue(filteredValue);
-                               }
-                               currentSone.setProfile(profile);
-                               webInterface.getCore().touchConfiguration();
-                               throw new RedirectException("editProfile.html");
-                       } else if (request.getHttpRequest().getPartAsStringFailsafe("add-field", 4).equals("true")) {
-                               String fieldName = request.getHttpRequest().getPartAsStringFailsafe("field-name", 256).trim();
-                               try {
-                                       profile.addField(fieldName);
-                                       currentSone.setProfile(profile);
-                                       webInterface.getCore().touchConfiguration();
-                                       throw new RedirectException("editProfile.html#profile-fields");
-                               } catch (DuplicateField df1) {
-                                       templateContext.set("fieldName", fieldName);
-                                       templateContext.set("duplicateFieldName", true);
-                               }
-                       } else {
-                               String id = getFieldId(request, "delete-field-");
-                               if (id != null) {
-                                       throw new RedirectException("deleteProfileField.html?field=" + id);
-                               }
-                               id = getFieldId(request, "move-up-field-");
-                               if (id != null) {
-                                       Field field = profile.getFieldById(id);
-                                       if (field == null) {
-                                               throw new RedirectException("invalid.html");
-                                       }
-                                       profile.moveFieldUp(field);
-                                       currentSone.setProfile(profile);
-                                       throw new RedirectException("editProfile.html#profile-fields");
-                               }
-                               id = getFieldId(request, "move-down-field-");
-                               if (id != null) {
-                                       Field field = profile.getFieldById(id);
-                                       if (field == null) {
-                                               throw new RedirectException("invalid.html");
-                                       }
-                                       profile.moveFieldDown(field);
-                                       currentSone.setProfile(profile);
-                                       throw new RedirectException("editProfile.html#profile-fields");
-                               }
-                               id = getFieldId(request, "edit-field-");
-                               if (id != null) {
-                                       throw new RedirectException("editProfileField.html?field=" + id);
-                               }
-                       }
-               }
-               templateContext.set("firstName", firstName);
-               templateContext.set("middleName", middleName);
-               templateContext.set("lastName", lastName);
-               templateContext.set("birthDay", birthDay);
-               templateContext.set("birthMonth", birthMonth);
-               templateContext.set("birthYear", birthYear);
-               templateContext.set("avatarId", avatarId);
-               templateContext.set("fields", fields);
-       }
-
-       //
-       // PRIVATE METHODS
-       //
-
-       /**
-        * Searches for a part whose names starts with the given {@code String} and
-        * extracts the ID from the located name.
-        *
-        * @param request
-        *            The request to get the parts from
-        * @param partNameStart
-        *            The start of the name of the requested part
-        * @return The parsed ID, or {@code null} if there was no part matching the
-        *         given string
-        */
-       private static String getFieldId(FreenetRequest request, String partNameStart) {
-               for (String partName : request.getHttpRequest().getParts()) {
-                       if (partName.startsWith(partNameStart)) {
-                               return partName.substring(partNameStart.length());
-                       }
-               }
-               return null;
-       }
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java
deleted file mode 100644 (file)
index 0652a52..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Sone - FollowSonePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import com.google.common.base.Optional;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * This page lets the user follow another Sone.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class FollowSonePage extends SoneTemplatePage {
-
-       /**
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public FollowSonePage(Template template, WebInterface webInterface) {
-               super("followSone.html", template, "Page.FollowSone.Title", webInterface, true);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       String soneIds = request.getHttpRequest().getPartAsStringFailsafe("sone", 1200);
-                       for (String soneId : soneIds.split("[ ,]+")) {
-                               Optional<Sone> sone = webInterface.getCore().getSone(soneId);
-                               if (sone.isPresent()) {
-                                       webInterface.getCore().followSone(currentSone, soneId);
-                                       webInterface.getCore().markSoneKnown(sone.get());
-                               }
-                       }
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/GetImagePage.java b/src/main/java/net/pterodactylus/sone/web/GetImagePage.java
deleted file mode 100644 (file)
index ec38d0a..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Sone - GetImagePage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import java.io.IOException;
-import java.net.URI;
-
-import net.pterodactylus.sone.data.TemporaryImage;
-import net.pterodactylus.sone.web.page.FreenetPage;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.web.Response;
-
-/**
- * Page that delivers a {@link TemporaryImage} to the browser.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class GetImagePage implements FreenetPage {
-
-       /** The Sone web interface. */
-       private final WebInterface webInterface;
-
-       /**
-        * Creates a new “get image” page.
-        *
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public GetImagePage(WebInterface webInterface) {
-               this.webInterface = webInterface;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public String getPath() {
-               return "getImage.html";
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean isPrefixPage() {
-               return false;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public Response handleRequest(FreenetRequest request, Response response) throws IOException {
-               String imageId = request.getHttpRequest().getParam("image");
-               TemporaryImage temporaryImage = webInterface.getCore().getTemporaryImage(imageId);
-               if (temporaryImage == null) {
-                       return response.setStatusCode(404).setStatusText("Not found.").setContentType("text/html; charset=utf-8");
-               }
-               String contentType= temporaryImage.getMimeType();
-               return response.setStatusCode(200).setStatusText("OK").setContentType(contentType).addHeader("Content-Disposition", "attachment; filename=" + temporaryImage.getId() + "." + contentType.substring(contentType.lastIndexOf('/') + 1)).write(temporaryImage.getImageData());
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean isLinkExcepted(URI link) {
-               return false;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java
deleted file mode 100644 (file)
index 7a222d2..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Sone - ImageBrowserPage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static com.google.common.collect.FluentIterable.from;
-import static net.pterodactylus.sone.data.Album.FLATTENER;
-import static net.pterodactylus.sone.data.Album.NOT_EMPTY;
-import static net.pterodactylus.sone.data.Album.TITLE_COMPARATOR;
-import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import com.google.common.base.Optional;
-
-import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-/**
- * The image browser page is the entry page for the image management.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class ImageBrowserPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new image browser page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public ImageBrowserPage(Template template, WebInterface webInterface) {
-               super("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               String albumId = request.getHttpRequest().getParam("album", null);
-               if (albumId != null) {
-                       Album album = webInterface.getCore().getAlbum(albumId);
-                       templateContext.set("albumRequested", true);
-                       templateContext.set("album", album);
-                       templateContext.set("page", request.getHttpRequest().getParam("page"));
-                       return;
-               }
-               String imageId = request.getHttpRequest().getParam("image", null);
-               if (imageId != null) {
-                       Image image = webInterface.getCore().getImage(imageId, false);
-                       templateContext.set("imageRequested", true);
-                       templateContext.set("image", image);
-                       return;
-               }
-               String soneId = request.getHttpRequest().getParam("sone", null);
-               if (soneId != null) {
-                       Optional<Sone> sone = webInterface.getCore().getSone(soneId);
-                       templateContext.set("soneRequested", true);
-                       templateContext.set("sone", sone.orNull());
-                       return;
-               }
-               String mode = request.getHttpRequest().getParam("mode", null);
-               if ("gallery".equals(mode)) {
-                       templateContext.set("galleryRequested", true);
-                       List<Album> albums = new ArrayList<Album>();
-                       for (Sone sone : webInterface.getCore().getSones()) {
-                               albums.addAll(from(sone.getRootAlbum().getAlbums()).transformAndConcat(FLATTENER).filter(NOT_EMPTY).toList());
-                       }
-                       Collections.sort(albums, TITLE_COMPARATOR);
-                       Pagination<Album> albumPagination = new Pagination<Album>(albums, 12).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
-                       templateContext.set("albumPagination", albumPagination);
-                       templateContext.set("albums", albumPagination.getItems());
-                       return;
-               }
-               Sone sone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
-               templateContext.set("soneRequested", true);
-               templateContext.set("sone", sone);
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean isLinkExcepted(URI link) {
-               return true;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/IndexPage.java
deleted file mode 100644 (file)
index 1d40f45..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Sone - IndexPage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.notify.PostVisibilityFilter;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.Collections2;
-
-/**
- * The index page shows the main page of Sone. This page will contain the posts
- * of all friends of the current user.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class IndexPage extends SoneTemplatePage {
-
-       private final PostVisibilityFilter postVisibilityFilter;
-
-       public IndexPage(Template template, WebInterface webInterface, PostVisibilityFilter postVisibilityFilter) {
-               super("index.html", template, "Page.Index.Title", webInterface, true);
-               this.postVisibilityFilter = postVisibilityFilter;
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               final Sone currentSone = getCurrentSone(request.getToadletContext());
-               Collection<Post> allPosts = new ArrayList<Post>();
-               allPosts.addAll(currentSone.getPosts());
-               for (String friendSoneId : currentSone.getFriends()) {
-                       Optional<Sone> friendSone = webInterface.getCore().getSone(friendSoneId);
-                       if (!friendSone.isPresent()) {
-                               continue;
-                       }
-                       allPosts.addAll(friendSone.get().getPosts());
-               }
-               for (Sone sone : webInterface.getCore().getSones()) {
-                       for (Post post : sone.getPosts()) {
-                               if (currentSone.equals(post.getRecipient().orNull()) && !allPosts.contains(post)) {
-                                       allPosts.add(post);
-                               }
-                       }
-               }
-               allPosts = Collections2.filter(allPosts, postVisibilityFilter.isVisible(currentSone));
-               List<Post> sortedPosts = new ArrayList<Post>(allPosts);
-               Collections.sort(sortedPosts, Post.NEWEST_FIRST);
-               Pagination<Post> pagination = new Pagination<Post>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
-               templateContext.set("pagination", pagination);
-               templateContext.set("posts", pagination.getItems());
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java
deleted file mode 100644 (file)
index c74f4b9..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Sone - KnownSonesPage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Ordering;
-
-/**
- * This page shows all known Sones.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class KnownSonesPage extends SoneTemplatePage {
-
-       private static final String defaultSortField = "activity";
-       private static final String defaultSortOrder = "desc";
-
-       /**
-        * Creates a “known Sones” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public KnownSonesPage(Template template, WebInterface webInterface) {
-               super("knownSones.html", template, "Page.KnownSones.Title", webInterface, false);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               String sortField = request.getHttpRequest().getParam("sort", defaultSortField);
-               String sortOrder = request.getHttpRequest().getParam("order", defaultSortOrder);
-               String filter = request.getHttpRequest().getParam("filter");
-               templateContext.set("sort", sortField);
-               templateContext.set("order", sortOrder);
-               templateContext.set("filter", filter);
-               final Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
-               Collection<Sone> knownSones = Collections2.filter(webInterface.getCore().getSones(), Sone.EMPTY_SONE_FILTER);
-               if ((currentSone != null) && "followed".equals(filter)) {
-                       knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
-
-                               @Override
-                               public boolean apply(Sone sone) {
-                                       return currentSone.hasFriend(sone.getId());
-                               }
-                       });
-               } else if ((currentSone != null) && "not-followed".equals(filter)) {
-                       knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
-
-                               @Override
-                               public boolean apply(Sone sone) {
-                                       return !currentSone.hasFriend(sone.getId());
-                               }
-                       });
-               } else if ("new".equals(filter)) {
-                       knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
-
-                               /**
-                                * {@inheritDoc}
-                                */
-                               @Override
-                               public boolean apply(Sone sone) {
-                                       return !sone.isKnown();
-                               }
-                       });
-               } else if ("not-new".equals(filter)) {
-                       knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
-
-                               /**
-                                * {@inheritDoc}
-                                */
-                               @Override
-                               public boolean apply(Sone sone) {
-                                       return sone.isKnown();
-                               }
-                       });
-               } else if ("own".equals(filter)) {
-                       knownSones = Collections2.filter(knownSones, Sone.LOCAL_SONE_FILTER);
-               } else if ("not-own".equals(filter)) {
-                       knownSones = Collections2.filter(knownSones, Predicates.not(Sone.LOCAL_SONE_FILTER));
-               }
-               List<Sone> sortedSones = new ArrayList<Sone>(knownSones);
-               if ("activity".equals(sortField)) {
-                       if ("asc".equals(sortOrder)) {
-                               Collections.sort(sortedSones, Ordering.from(Sone.LAST_ACTIVITY_COMPARATOR).reverse());
-                       } else {
-                               Collections.sort(sortedSones, Sone.LAST_ACTIVITY_COMPARATOR);
-                       }
-               } else if ("posts".equals(sortField)) {
-                       if ("asc".equals(sortOrder)) {
-                               Collections.sort(sortedSones, Ordering.from(Sone.POST_COUNT_COMPARATOR).reverse());
-                       } else {
-                               Collections.sort(sortedSones, Sone.POST_COUNT_COMPARATOR);
-                       }
-               } else if ("images".equals(sortField)) {
-                       if ("asc".equals(sortOrder)) {
-                               Collections.sort(sortedSones, Ordering.from(Sone.IMAGE_COUNT_COMPARATOR).reverse());
-                       } else {
-                               Collections.sort(sortedSones, Sone.IMAGE_COUNT_COMPARATOR);
-                       }
-               } else {
-                       if ("desc".equals(sortOrder)) {
-                               Collections.sort(sortedSones, Ordering.from(Sone.NICE_NAME_COMPARATOR).reverse());
-                       } else {
-                               Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR);
-                       }
-               }
-               Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
-               templateContext.set("pagination", sonePagination);
-               templateContext.set("knownSones", sonePagination.getItems());
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/LikePage.java b/src/main/java/net/pterodactylus/sone/web/LikePage.java
deleted file mode 100644 (file)
index fc39eff..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Sone - LikePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * Page that lets the user like a {@link Post}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class LikePage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “like post” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public LikePage(Template template, WebInterface webInterface) {
-               super("like.html", template, "Page.Like.Title", webInterface, true);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16);
-                       String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       if ("post".equals(type)) {
-                               currentSone.addLikedPostId(id);
-                       } else if ("reply".equals(type)) {
-                               currentSone.addLikedReplyId(id);
-                       }
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/LockSonePage.java b/src/main/java/net/pterodactylus/sone/web/LockSonePage.java
deleted file mode 100644 (file)
index a0a9574..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Sone - LockSonePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-/**
- * This page lets the user lock a {@link Sone} to prevent it from being
- * inserted.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class LockSonePage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “lock Sone” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public LockSonePage(Template template, WebInterface webInterface) {
-               super("lockSone.html", template, "Page.LockSone.Title", webInterface);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
-               Sone sone = webInterface.getCore().getLocalSone(soneId);
-               if (sone != null) {
-                       webInterface.getCore().lockSone(sone);
-               }
-               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-               throw new RedirectException(returnPage);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/LogoutPage.java b/src/main/java/net/pterodactylus/sone/web/LogoutPage.java
deleted file mode 100644 (file)
index 3ec62a3..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Sone - LogoutPage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import freenet.clients.http.ToadletContext;
-
-/**
- * Logs a user out.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class LogoutPage extends SoneTemplatePage {
-
-       /**
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public LogoutPage(Template template, WebInterface webInterface) {
-               super("logout.html", template, "Page.Logout.Title", webInterface, true);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               setCurrentSone(request.getToadletContext(), null);
-               throw new RedirectException("index.html");
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean isEnabled(ToadletContext toadletContext) {
-               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
-                       return false;
-               }
-               return (getCurrentSoneWithoutCreatingSession(toadletContext) != null) && (webInterface.getCore().getLocalSones().size() != 1);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java
deleted file mode 100644 (file)
index 57ea00f..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Sone - MarkAsKnownPage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import java.util.StringTokenizer;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Reply;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-import com.google.common.base.Optional;
-
-/**
- * Page that lets the user mark a number of {@link Sone}s, {@link Post}s, or
- * {@link Reply Replie}s as known.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class MarkAsKnownPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “mark as known” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public MarkAsKnownPage(Template template, WebInterface webInterface) {
-               super("markAsKnown.html", template, "Page.MarkAsKnown.Title", webInterface);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               String type = request.getHttpRequest().getPartAsStringFailsafe("type", 5);
-               if (!type.equals("sone") && !type.equals("post") && !type.equals("reply")) {
-                       throw new RedirectException("invalid.html");
-               }
-               String ids = request.getHttpRequest().getPartAsStringFailsafe("id", 65536);
-               for (StringTokenizer idTokenizer = new StringTokenizer(ids); idTokenizer.hasMoreTokens();) {
-                       String id = idTokenizer.nextToken();
-                       if (type.equals("post")) {
-                               Optional<Post> post = webInterface.getCore().getPost(id);
-                               if (!post.isPresent()) {
-                                       continue;
-                               }
-                               webInterface.getCore().markPostKnown(post.get());
-                       } else if (type.equals("reply")) {
-                               Optional<PostReply> reply = webInterface.getCore().getPostReply(id);
-                               if (!reply.isPresent()) {
-                                       continue;
-                               }
-                               webInterface.getCore().markReplyKnown(reply.get());
-                       } else {
-                               Optional<Sone> sone = webInterface.getCore().getSone(id);
-                               if (!sone.isPresent()) {
-                                       continue;
-                               }
-                               webInterface.getCore().markSoneKnown(sone.get());
-                       }
-               }
-               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-               throw new RedirectException(returnPage);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/NewPage.java b/src/main/java/net/pterodactylus/sone/web/NewPage.java
deleted file mode 100644 (file)
index 9eab69a..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Sone - NewPage.java - Copyright © 2013–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.notify.PostVisibilityFilter;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-/**
- * Page that displays all new posts and replies. The posts are filtered using
- * {@link PostVisibilityFilter#isPostVisible(Sone, Post)} and sorted by time.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class NewPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “new posts and replies” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public NewPage(Template template, WebInterface webInterface) {
-               super("new.html", template, "Page.New.Title", webInterface);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               /* collect new elements from notifications. */
-               Set<Post> posts = new HashSet<Post>(webInterface.getNewPosts(getCurrentSoneWithoutCreatingSession(request.getToadletContext())));
-               for (PostReply reply : webInterface.getNewReplies(getCurrentSoneWithoutCreatingSession(request.getToadletContext()))) {
-                       posts.add(reply.getPost().get());
-               }
-
-               /* filter and sort them. */
-               List<Post> sortedPosts = new ArrayList<>(posts);
-               Collections.sort(sortedPosts, Post.NEWEST_FIRST);
-
-               /* paginate them. */
-               Pagination<Post> pagination = new Pagination<>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
-               templateContext.set("pagination", pagination);
-               templateContext.set("posts", pagination.getItems());
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java
deleted file mode 100644 (file)
index 7cf7246..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Sone - OptionsPage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import net.pterodactylus.sone.core.Preferences;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent;
-import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * This page lets the user edit the options of the Sone plugin.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class OptionsPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new options page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public OptionsPage(Template template, WebInterface webInterface) {
-               super("options.html", template, "Page.Options.Title", webInterface, false);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               Preferences preferences = webInterface.getCore().getPreferences();
-               Sone currentSone = webInterface.getCurrentSoneWithoutCreatingSession(request.getToadletContext());
-               if (request.getMethod() == Method.POST) {
-                       List<String> fieldErrors = new ArrayList<String>();
-                       if (currentSone != null) {
-                               boolean autoFollow = request.getHttpRequest().isPartSet("auto-follow");
-                               currentSone.getOptions().setAutoFollow(autoFollow);
-                               boolean enableSoneInsertNotifications = request.getHttpRequest().isPartSet("enable-sone-insert-notifications");
-                               currentSone.getOptions().setSoneInsertNotificationEnabled(enableSoneInsertNotifications);
-                               boolean showNotificationNewSones = request.getHttpRequest().isPartSet("show-notification-new-sones");
-                               currentSone.getOptions().setShowNewSoneNotifications(showNotificationNewSones);
-                               boolean showNotificationNewPosts = request.getHttpRequest().isPartSet("show-notification-new-posts");
-                               currentSone.getOptions().setShowNewPostNotifications(showNotificationNewPosts);
-                               boolean showNotificationNewReplies = request.getHttpRequest().isPartSet("show-notification-new-replies");
-                               currentSone.getOptions().setShowNewReplyNotifications(showNotificationNewReplies);
-                               String showCustomAvatars = request.getHttpRequest().getPartAsStringFailsafe("show-custom-avatars", 32);
-                               currentSone.getOptions().setShowCustomAvatars(LoadExternalContent.valueOf(showCustomAvatars));
-                               String loadLinkedImages = request.getHttpRequest().getPartAsStringFailsafe("load-linked-images", 32);
-                               currentSone.getOptions().setLoadLinkedImages(LoadExternalContent.valueOf(loadLinkedImages));
-                               webInterface.getCore().touchConfiguration();
-                       }
-                       Integer insertionDelay = parseInt(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16), null);
-                       if (!preferences.validateInsertionDelay(insertionDelay)) {
-                               fieldErrors.add("insertion-delay");
-                       } else {
-                               preferences.setInsertionDelay(insertionDelay);
-                       }
-                       Integer postsPerPage = parseInt(request.getHttpRequest().getPartAsStringFailsafe("posts-per-page", 4), null);
-                       if (!preferences.validatePostsPerPage(postsPerPage)) {
-                               fieldErrors.add("posts-per-page");
-                       } else {
-                               preferences.setPostsPerPage(postsPerPage);
-                       }
-                       Integer imagesPerPage = parseInt(request.getHttpRequest().getPartAsStringFailsafe("images-per-page", 4), null);
-                       if (!preferences.validateImagesPerPage(imagesPerPage)) {
-                               fieldErrors.add("images-per-page");
-                       } else {
-                               preferences.setImagesPerPage(imagesPerPage);
-                       }
-                       Integer charactersPerPost = parseInt(request.getHttpRequest().getPartAsStringFailsafe("characters-per-post", 10), null);
-                       if (!preferences.validateCharactersPerPost(charactersPerPost)) {
-                               fieldErrors.add("characters-per-post");
-                       } else {
-                               preferences.setCharactersPerPost(charactersPerPost);
-                       }
-                       Integer postCutOffLength = parseInt(request.getHttpRequest().getPartAsStringFailsafe("post-cut-off-length", 10), null);
-                       if (!preferences.validatePostCutOffLength(postCutOffLength)) {
-                               fieldErrors.add("post-cut-off-length");
-                       } else {
-                               preferences.setPostCutOffLength(postCutOffLength);
-                       }
-                       boolean requireFullAccess = request.getHttpRequest().isPartSet("require-full-access");
-                       preferences.setRequireFullAccess(requireFullAccess);
-                       Integer positiveTrust = parseInt(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3), null);
-                       if (!preferences.validatePositiveTrust(positiveTrust)) {
-                               fieldErrors.add("positive-trust");
-                       } else {
-                               preferences.setPositiveTrust(positiveTrust);
-                       }
-                       Integer negativeTrust = parseInt(request.getHttpRequest().getPartAsStringFailsafe("negative-trust", 4), null);
-                       if (!preferences.validateNegativeTrust(negativeTrust)) {
-                               fieldErrors.add("negative-trust");
-                       } else {
-                               preferences.setNegativeTrust(negativeTrust);
-                       }
-                       String trustComment = request.getHttpRequest().getPartAsStringFailsafe("trust-comment", 256);
-                       if (trustComment.trim().length() == 0) {
-                               trustComment = null;
-                       }
-                       preferences.setTrustComment(trustComment);
-                       boolean fcpInterfaceActive = request.getHttpRequest().isPartSet("fcp-interface-active");
-                       preferences.setFcpInterfaceActive(fcpInterfaceActive);
-                       Integer fcpFullAccessRequiredInteger = parseInt(request.getHttpRequest().getPartAsStringFailsafe("fcp-full-access-required", 1), preferences.getFcpFullAccessRequired().ordinal());
-                       FullAccessRequired fcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequiredInteger];
-                       preferences.setFcpFullAccessRequired(fcpFullAccessRequired);
-                       webInterface.getCore().touchConfiguration();
-                       if (fieldErrors.isEmpty()) {
-                               throw new RedirectException(getPath());
-                       }
-                       templateContext.set("fieldErrors", fieldErrors);
-               }
-               if (currentSone != null) {
-                       templateContext.set("auto-follow", currentSone.getOptions().isAutoFollow());
-                       templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().isSoneInsertNotificationEnabled());
-                       templateContext.set("show-notification-new-sones", currentSone.getOptions().isShowNewSoneNotifications());
-                       templateContext.set("show-notification-new-posts", currentSone.getOptions().isShowNewPostNotifications());
-                       templateContext.set("show-notification-new-replies", currentSone.getOptions().isShowNewReplyNotifications());
-                       templateContext.set("show-custom-avatars", currentSone.getOptions().getShowCustomAvatars().name());
-                       templateContext.set("load-linked-images", currentSone.getOptions().getLoadLinkedImages().name());
-               }
-               templateContext.set("insertion-delay", preferences.getInsertionDelay());
-               templateContext.set("posts-per-page", preferences.getPostsPerPage());
-               templateContext.set("images-per-page", preferences.getImagesPerPage());
-               templateContext.set("characters-per-post", preferences.getCharactersPerPost());
-               templateContext.set("post-cut-off-length", preferences.getPostCutOffLength());
-               templateContext.set("require-full-access", preferences.isRequireFullAccess());
-               templateContext.set("positive-trust", preferences.getPositiveTrust());
-               templateContext.set("negative-trust", preferences.getNegativeTrust());
-               templateContext.set("trust-comment", preferences.getTrustComment());
-               templateContext.set("fcp-interface-active", preferences.isFcpInterfaceActive());
-               templateContext.set("fcp-full-access-required", preferences.getFcpFullAccessRequired().ordinal());
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/ReloadingPage.java b/src/main/java/net/pterodactylus/sone/web/ReloadingPage.java
deleted file mode 100644 (file)
index bc18816..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Sone - ReloadingPage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import net.pterodactylus.util.io.StreamCopier;
-import net.pterodactylus.util.web.Page;
-import net.pterodactylus.util.web.Request;
-import net.pterodactylus.util.web.Response;
-
-/**
- * {@link Page} implementation that delivers static files from the filesystem.
- *
- * @param <REQ>
- *            The type of the request
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class ReloadingPage<REQ extends Request> implements Page<REQ> {
-
-       private final String pathPrefix;
-       private final String filesystemPath;
-       private final String mimeType;
-
-       public ReloadingPage(String pathPrefix, String filesystemPathPrefix, String mimeType) {
-               this.pathPrefix = pathPrefix;
-               this.filesystemPath = filesystemPathPrefix;
-               this.mimeType = mimeType;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public String getPath() {
-               return pathPrefix;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean isPrefixPage() {
-               return true;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public Response handleRequest(REQ request, Response response) throws IOException {
-               String path = request.getUri().getPath();
-               int lastSlash = path.lastIndexOf('/');
-               String filename = path.substring(lastSlash + 1);
-               try (InputStream fileInputStream = new FileInputStream(new File(filesystemPath, filename));
-                       OutputStream contentOutputStream = response.getContent()) {
-                       StreamCopier.copy(fileInputStream, contentOutputStream);
-               } catch (FileNotFoundException fnfe1) {
-                       return response.setStatusCode(404).setStatusText("Not found.");
-               }
-               return response.setStatusCode(200).setStatusText("OK").setContentType(mimeType);
-       }
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/RescuePage.java b/src/main/java/net/pterodactylus/sone/web/RescuePage.java
deleted file mode 100644 (file)
index 0f94563..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Sone - RescuePage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.utils.NumberParsers.parseLong;
-
-import net.pterodactylus.sone.core.SoneRescuer;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * Page that lets the user control the rescue mode for a Sone.
- *
- * @see SoneRescuer
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class RescuePage extends SoneTemplatePage {
-
-       /**
-        * Creates a new rescue page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public RescuePage(Template template, WebInterface webInterface) {
-               super("rescue.html", template, "Page.Rescue.Title", webInterface, true);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
-               SoneRescuer soneRescuer = webInterface.getCore().getSoneRescuer(currentSone);
-               if (request.getMethod() == Method.POST) {
-                       if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("fetch", 4))) {
-                               long edition = parseLong(request.getHttpRequest().getPartAsStringFailsafe("edition", 8), -1L);
-                               if (edition > -1) {
-                                       soneRescuer.setEdition(edition);
-                               }
-                               soneRescuer.startNextFetch();
-                       }
-                       throw new RedirectException("rescue.html");
-               }
-               templateContext.set("soneRescuer", soneRescuer);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java
deleted file mode 100644 (file)
index 8b444a7..0000000
+++ /dev/null
@@ -1,658 +0,0 @@
-/*
- * Sone - SearchPage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.primitives.Ints.tryParse;
-import static java.util.logging.Logger.getLogger;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Profile;
-import net.pterodactylus.sone.data.Profile.Field;
-import net.pterodactylus.sone.data.Reply;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.text.StringEscaper;
-import net.pterodactylus.util.text.TextException;
-
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Ordering;
-
-/**
- * This page lets the user search for posts and replies that contain certain
- * words.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class SearchPage extends SoneTemplatePage {
-
-       /** The logger. */
-       private static final Logger logger = getLogger(SearchPage.class.getName());
-
-       /** Short-term cache. */
-       private final LoadingCache<List<Phrase>, Set<Hit<Post>>> hitCache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(new CacheLoader<List<Phrase>, Set<Hit<Post>>>() {
-
-               @Override
-               @SuppressWarnings("synthetic-access")
-               public Set<Hit<Post>> load(List<Phrase> phrases) {
-                       Set<Post> posts = new HashSet<Post>();
-                       for (Sone sone : webInterface.getCore().getSones()) {
-                               posts.addAll(sone.getPosts());
-                       }
-                       return getHits(Collections2.filter(posts, Post.FUTURE_POSTS_FILTER), phrases, new PostStringGenerator());
-               }
-       });
-
-       /**
-        * Creates a new search page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public SearchPage(Template template, WebInterface webInterface) {
-               super("search.html", template, "Page.Search.Title", webInterface);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       @SuppressWarnings("synthetic-access")
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               String query = request.getHttpRequest().getParam("query").trim();
-               if (query.length() == 0) {
-                       throw new RedirectException("index.html");
-               }
-
-               List<Phrase> phrases = parseSearchPhrases(query);
-               if (phrases.isEmpty()) {
-                       throw new RedirectException("index.html");
-               }
-
-               /* check for a couple of shortcuts. */
-               if (phrases.size() == 1) {
-                       String phrase = phrases.get(0).getPhrase();
-
-                       /* is it a Sone ID? */
-                       redirectIfNotNull(getSoneId(phrase), "viewSone.html?sone=");
-
-                       /* is it a post ID? */
-                       redirectIfNotNull(getPostId(phrase), "viewPost.html?post=");
-
-                       /* is it a reply ID? show the post. */
-                       redirectIfNotNull(getReplyPostId(phrase), "viewPost.html?post=");
-
-                       /* is it an album ID? */
-                       redirectIfNotNull(getAlbumId(phrase), "imageBrowser.html?album=");
-
-                       /* is it an image ID? */
-                       redirectIfNotNull(getImageId(phrase), "imageBrowser.html?image=");
-               }
-
-               Collection<Sone> sones = webInterface.getCore().getSones();
-               Collection<Hit<Sone>> soneHits = getHits(sones, phrases, SoneStringGenerator.COMPLETE_GENERATOR);
-
-               Collection<Hit<Post>> postHits = hitCache.getUnchecked(phrases);
-
-               /* now filter. */
-               soneHits = Collections2.filter(soneHits, Hit.POSITIVE_FILTER);
-               postHits = Collections2.filter(postHits, Hit.POSITIVE_FILTER);
-
-               /* now sort. */
-               List<Hit<Sone>> sortedSoneHits = Ordering.from(Hit.DESCENDING_COMPARATOR).sortedCopy(soneHits);
-               List<Hit<Post>> sortedPostHits = Ordering.from(Hit.DESCENDING_COMPARATOR).sortedCopy(postHits);
-
-               /* extract Sones and posts. */
-               List<Sone> resultSones = FluentIterable.from(sortedSoneHits).transform(new HitMapper<Sone>()).toList();
-               List<Post> resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper<Post>()).toList();
-
-               /* pagination. */
-               Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(fromNullable(tryParse(request.getHttpRequest().getParam("sonePage"))).or(0));
-               Pagination<Post> postPagination = new Pagination<Post>(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(fromNullable(tryParse(request.getHttpRequest().getParam("postPage"))).or(0));
-
-               templateContext.set("sonePagination", sonePagination);
-               templateContext.set("soneHits", sonePagination.getItems());
-               templateContext.set("postPagination", postPagination);
-               templateContext.set("postHits", postPagination.getItems());
-       }
-
-       //
-       // PRIVATE METHODS
-       //
-
-       /**
-        * Collects hit information for the given objects. The objects are converted
-        * to a {@link String} using the given {@link StringGenerator}, and the
-        * {@link #calculateScore(List, String) calculated score} is stored together
-        * with the object in a {@link Hit}, and all resulting {@link Hit}s are then
-        * returned.
-        *
-        * @param <T>
-        *            The type of the objects
-        * @param objects
-        *            The objects to search over
-        * @param phrases
-        *            The phrases to search for
-        * @param stringGenerator
-        *            The string generator for the objects
-        * @return The hits for the given phrases
-        */
-       private static <T> Set<Hit<T>> getHits(Collection<T> objects, List<Phrase> phrases, StringGenerator<T> stringGenerator) {
-               Set<Hit<T>> hits = new HashSet<Hit<T>>();
-               for (T object : objects) {
-                       String objectString = stringGenerator.generateString(object);
-                       double score = calculateScore(phrases, objectString);
-                       hits.add(new Hit<T>(object, score));
-               }
-               return hits;
-       }
-
-       /**
-        * Parses the given query into search phrases. The query is split on
-        * whitespace while allowing to group words using single or double quotes.
-        * Isolated phrases starting with a “+” are
-        * {@link Phrase.Optionality#REQUIRED}, phrases with a “-” are
-        * {@link Phrase.Optionality#FORBIDDEN}.
-        *
-        * @param query
-        *            The query to parse
-        * @return The parsed phrases
-        */
-       private static List<Phrase> parseSearchPhrases(String query) {
-               List<String> parsedPhrases;
-               try {
-                       parsedPhrases = StringEscaper.parseLine(query);
-               } catch (TextException te1) {
-                       /* invalid query. */
-                       return Collections.emptyList();
-               }
-
-               List<Phrase> phrases = new ArrayList<Phrase>();
-               for (String phrase : parsedPhrases) {
-                       if (phrase.startsWith("+")) {
-                               if (phrase.length() > 1) {
-                                       phrases.add(new Phrase(phrase.substring(1), Phrase.Optionality.REQUIRED));
-                               } else {
-                                       phrases.add(new Phrase("+", Phrase.Optionality.OPTIONAL));
-                               }
-                       } else if (phrase.startsWith("-")) {
-                               if (phrase.length() > 1) {
-                                       phrases.add(new Phrase(phrase.substring(1), Phrase.Optionality.FORBIDDEN));
-                               } else {
-                                       phrases.add(new Phrase("-", Phrase.Optionality.OPTIONAL));
-                               }
-                       } else {
-                               phrases.add(new Phrase(phrase, Phrase.Optionality.OPTIONAL));
-                       }
-               }
-               return phrases;
-       }
-
-       /**
-        * Calculates the score for the given expression when using the given
-        * phrases.
-        *
-        * @param phrases
-        *            The phrases to search for
-        * @param expression
-        *            The expression to search
-        * @return The score of the expression
-        */
-       private static double calculateScore(List<Phrase> phrases, String expression) {
-               logger.log(Level.FINEST, String.format("Calculating Score for “%s”…", expression));
-               double optionalHits = 0;
-               double requiredHits = 0;
-               int forbiddenHits = 0;
-               int requiredPhrases = 0;
-               for (Phrase phrase : phrases) {
-                       String phraseString = phrase.getPhrase().toLowerCase();
-                       if (phrase.getOptionality() == Phrase.Optionality.REQUIRED) {
-                               ++requiredPhrases;
-                       }
-                       int matches = 0;
-                       int index = 0;
-                       double score = 0;
-                       while (index < expression.length()) {
-                               int position = expression.toLowerCase().indexOf(phraseString, index);
-                               if (position == -1) {
-                                       break;
-                               }
-                               score += Math.pow(1 - position / (double) expression.length(), 2);
-                               index = position + phraseString.length();
-                               logger.log(Level.FINEST, String.format("Got hit at position %d.", position));
-                               ++matches;
-                       }
-                       logger.log(Level.FINEST, String.format("Score: %f", score));
-                       if (matches == 0) {
-                               continue;
-                       }
-                       if (phrase.getOptionality() == Phrase.Optionality.REQUIRED) {
-                               requiredHits += score;
-                       }
-                       if (phrase.getOptionality() == Phrase.Optionality.OPTIONAL) {
-                               optionalHits += score;
-                       }
-                       if (phrase.getOptionality() == Phrase.Optionality.FORBIDDEN) {
-                               forbiddenHits += matches;
-                       }
-               }
-               return requiredHits * 3 + optionalHits + (requiredHits - requiredPhrases) * 5 - (forbiddenHits * 2);
-       }
-
-       /**
-        * Throws a
-        * {@link net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException}
-        * if the given object is not {@code null}, appending the object to the
-        * given target URL.
-        *
-        * @param object
-        *            The object on which to redirect
-        * @param target
-        *            The target of the redirect
-        * @throws RedirectException
-        *             if {@code object} is not {@code null}
-        */
-       private static void redirectIfNotNull(String object, String target) throws RedirectException {
-               if (object != null) {
-                       throw new RedirectException(target + object);
-               }
-       }
-
-       /**
-        * If the given phrase contains a Sone ID (optionally prefixed by
-        * “sone://”), returns said Sone ID, otherwise return {@code null}.
-        *
-        * @param phrase
-        *            The phrase that maybe is a Sone ID
-        * @return The Sone ID, or {@code null}
-        */
-       private String getSoneId(String phrase) {
-               String soneId = phrase.startsWith("sone://") ? phrase.substring(7) : phrase;
-               return (webInterface.getCore().getSone(soneId).isPresent()) ? soneId : null;
-       }
-
-       /**
-        * If the given phrase contains a post ID (optionally prefixed by
-        * “post://”), returns said post ID, otherwise return {@code null}.
-        *
-        * @param phrase
-        *            The phrase that maybe is a post ID
-        * @return The post ID, or {@code null}
-        */
-       private String getPostId(String phrase) {
-               String postId = phrase.startsWith("post://") ? phrase.substring(7) : phrase;
-               return (webInterface.getCore().getPost(postId).isPresent()) ? postId : null;
-       }
-
-       /**
-        * If the given phrase contains a reply ID (optionally prefixed by
-        * “reply://”), returns the ID of the post the reply belongs to, otherwise
-        * return {@code null}.
-        *
-        * @param phrase
-        *            The phrase that maybe is a reply ID
-        * @return The reply’s post ID, or {@code null}
-        */
-       private String getReplyPostId(String phrase) {
-               String replyId = phrase.startsWith("reply://") ? phrase.substring(8) : phrase;
-               Optional<PostReply> postReply = webInterface.getCore().getPostReply(replyId);
-               if (!postReply.isPresent()) {
-                       return null;
-               }
-               return postReply.get().getPostId();
-       }
-
-       /**
-        * If the given phrase contains an album ID (optionally prefixed by
-        * “album://”), returns said album ID, otherwise return {@code null}.
-        *
-        * @param phrase
-        *            The phrase that maybe is an album ID
-        * @return The album ID, or {@code null}
-        */
-       private String getAlbumId(String phrase) {
-               String albumId = phrase.startsWith("album://") ? phrase.substring(8) : phrase;
-               return (webInterface.getCore().getAlbum(albumId) != null) ? albumId : null;
-       }
-
-       /**
-        * If the given phrase contains an image ID (optionally prefixed by
-        * “image://”), returns said image ID, otherwise return {@code null}.
-        *
-        * @param phrase
-        *            The phrase that maybe is an image ID
-        * @return The image ID, or {@code null}
-        */
-       private String getImageId(String phrase) {
-               String imageId = phrase.startsWith("image://") ? phrase.substring(8) : phrase;
-               return (webInterface.getCore().getImage(imageId, false) != null) ? imageId : null;
-       }
-
-       /**
-        * Converts a given object into a {@link String}.
-        *
-        * @param <T>
-        *            The type of the objects
-        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
-        */
-       private static interface StringGenerator<T> {
-
-               /**
-                * Generates a {@link String} for the given object.
-                *
-                * @param object
-                *            The object to generate the {@link String} for
-                * @return The generated {@link String}
-                */
-               public String generateString(T object);
-
-       }
-
-       /**
-        * Generates a {@link String} from a {@link Sone}, concatenating the name of
-        * the Sone and all {@link Profile} {@link Field} values.
-        *
-        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
-        */
-       private static class SoneStringGenerator implements StringGenerator<Sone> {
-
-               /** A static instance of a complete Sone string generator. */
-               public static final SoneStringGenerator COMPLETE_GENERATOR = new SoneStringGenerator(true);
-
-               /**
-                * A static instance of a Sone string generator that will only use the
-                * name of the Sone.
-                */
-               public static final SoneStringGenerator NAME_GENERATOR = new SoneStringGenerator(false);
-
-               /** Whether to generate a string from all data of a Sone. */
-               private final boolean complete;
-
-               /**
-                * Creates a new Sone string generator.
-                *
-                * @param complete
-                *            {@code true} to use the profile’s fields, {@code false} to
-                *            not to use the profile‘s fields
-                */
-               private SoneStringGenerator(boolean complete) {
-                       this.complete = complete;
-               }
-
-               /**
-                * {@inheritDoc}
-                */
-               @Override
-               public String generateString(Sone sone) {
-                       StringBuilder soneString = new StringBuilder();
-                       soneString.append(sone.getName());
-                       Profile soneProfile = sone.getProfile();
-                       if (soneProfile.getFirstName() != null) {
-                               soneString.append(' ').append(soneProfile.getFirstName());
-                       }
-                       if (soneProfile.getMiddleName() != null) {
-                               soneString.append(' ').append(soneProfile.getMiddleName());
-                       }
-                       if (soneProfile.getLastName() != null) {
-                               soneString.append(' ').append(soneProfile.getLastName());
-                       }
-                       if (complete) {
-                               for (Field field : soneProfile.getFields()) {
-                                       soneString.append(' ').append(field.getValue());
-                               }
-                       }
-                       return soneString.toString();
-               }
-
-       }
-
-       /**
-        * Generates a {@link String} from a {@link Post}, concatenating the text of
-        * the post, the text of all {@link Reply}s, and the name of all
-        * {@link Sone}s that have replied.
-        *
-        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
-        */
-       private class PostStringGenerator implements StringGenerator<Post> {
-
-               /**
-                * {@inheritDoc}
-                */
-               @Override
-               public String generateString(Post post) {
-                       StringBuilder postString = new StringBuilder();
-                       postString.append(post.getText());
-                       if (post.getRecipient().isPresent()) {
-                               postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(post.getRecipient().get()));
-                       }
-                       for (PostReply reply : Collections2.filter(webInterface.getCore().getReplies(post.getId()), Reply.FUTURE_REPLY_FILTER)) {
-                               postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(reply.getSone()));
-                               postString.append(' ').append(reply.getText());
-                       }
-                       return postString.toString();
-               }
-
-       }
-
-       /**
-        * A search phrase.
-        *
-        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
-        */
-       private static class Phrase {
-
-               /**
-                * The optionality of a search phrase.
-                *
-                * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’
-                *         Roden</a>
-                */
-               public enum Optionality {
-
-                       /** The phrase is optional. */
-                       OPTIONAL,
-
-                       /** The phrase is required. */
-                       REQUIRED,
-
-                       /** The phrase is forbidden. */
-                       FORBIDDEN
-
-               }
-
-               /** The phrase to search for. */
-               private final String phrase;
-
-               /** The optionality of the phrase. */
-               private final Optionality optionality;
-
-               /**
-                * Creates a new phrase.
-                *
-                * @param phrase
-                *            The phrase to search for
-                * @param optionality
-                *            The optionality of the phrase
-                */
-               public Phrase(String phrase, Optionality optionality) {
-                       this.optionality = optionality;
-                       this.phrase = phrase;
-               }
-
-               /**
-                * Returns the phrase to search for.
-                *
-                * @return The phrase to search for
-                */
-               public String getPhrase() {
-                       return phrase;
-               }
-
-               /**
-                * Returns the optionality of the phrase.
-                *
-                * @return The optionality of the phrase
-                */
-               public Optionality getOptionality() {
-                       return optionality;
-               }
-
-               //
-               // OBJECT METHODS
-               //
-
-               /**
-                * {@inheritDoc}
-                */
-               @Override
-               public int hashCode() {
-                       return phrase.hashCode() ^ ((optionality == Optionality.FORBIDDEN) ? (0xaaaaaaaa) : ((optionality == Optionality.REQUIRED) ? 0x55555555 : 0));
-               }
-
-               /**
-                * {@inheritDoc}
-                */
-               @Override
-               public boolean equals(Object object) {
-                       if (!(object instanceof Phrase)) {
-                               return false;
-                       }
-                       Phrase phrase = (Phrase) object;
-                       return (this.optionality == phrase.optionality) && this.phrase.equals(phrase.phrase);
-               }
-
-       }
-
-       /**
-        * A hit consists of a searched object and the score it got for the phrases
-        * of the search.
-        *
-        * @see SearchPage#calculateScore(List, String)
-        * @param <T>
-        *            The type of the searched object
-        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
-        */
-       private static class Hit<T> {
-
-               /** Filter for {@link Hit}s with a score of more than 0. */
-               public static final Predicate<Hit<?>> POSITIVE_FILTER = new Predicate<Hit<?>>() {
-
-                       @Override
-                       public boolean apply(Hit<?> hit) {
-                               return (hit != null) && (hit.getScore() > 0);
-                       }
-
-               };
-
-               /** Comparator that sorts {@link Hit}s descending by score. */
-               public static final Comparator<Hit<?>> DESCENDING_COMPARATOR = new Comparator<Hit<?>>() {
-
-                       @Override
-                       public int compare(Hit<?> leftHit, Hit<?> rightHit) {
-                               return Double.compare(rightHit.getScore(), leftHit.getScore());
-                       }
-
-               };
-
-               /** The object that was searched. */
-               private final T object;
-
-               /** The score of the object. */
-               private final double score;
-
-               /**
-                * Creates a new hit.
-                *
-                * @param object
-                *            The object that was searched
-                * @param score
-                *            The score of the object
-                */
-               public Hit(T object, double score) {
-                       this.object = object;
-                       this.score = score;
-               }
-
-               /**
-                * Returns the object that was searched.
-                *
-                * @return The object that was searched
-                */
-               public T getObject() {
-                       return object;
-               }
-
-               /**
-                * Returns the score of the object.
-                *
-                * @return The score of the object
-                */
-               public double getScore() {
-                       return score;
-               }
-
-       }
-
-       /**
-        * Extracts the object from a {@link Hit}.
-        *
-        * @param <T>
-        *            The type of the object to extract
-        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
-        */
-       private static class HitMapper<T> implements Function<Hit<T>, T> {
-
-               /**
-                * {@inheritDoc}
-                */
-               @Override
-               public T apply(Hit<T> input) {
-                       return input.getObject();
-               }
-
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
deleted file mode 100644 (file)
index bece45d..0000000
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * Sone - SoneTemplatePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Nonnull;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.main.SonePlugin;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.sone.web.page.FreenetTemplatePage;
-import net.pterodactylus.util.notify.Notification;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-import freenet.clients.http.SessionManager.Session;
-import freenet.clients.http.ToadletContext;
-import freenet.support.api.HTTPRequest;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-/**
- * Base page for the Sone web interface.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class SoneTemplatePage extends FreenetTemplatePage {
-
-       /** The Sone core. */
-       protected final WebInterface webInterface;
-
-       /** The page title l10n key. */
-       private final String pageTitleKey;
-
-       /** Whether to require a login. */
-       private final boolean requireLogin;
-
-       /**
-        * Creates a new template page for Sone that does not require the user to be
-        * logged in.
-        *
-        * @param path
-        *            The path of the page
-        * @param template
-        *            The template to render
-        * @param pageTitleKey
-        *            The l10n key of the page title
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public SoneTemplatePage(String path, Template template, String pageTitleKey, WebInterface webInterface) {
-               this(path, template, pageTitleKey, webInterface, false);
-       }
-
-       /**
-        * Creates a new template page for Sone.
-        *
-        * @param path
-        *            The path of the page
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        * @param requireLogin
-        *            Whether this page requires a login
-        */
-       public SoneTemplatePage(String path, Template template, WebInterface webInterface, boolean requireLogin) {
-               this(path, template, null, webInterface, requireLogin);
-       }
-
-       /**
-        * Creates a new template page for Sone.
-        *
-        * @param path
-        *            The path of the page
-        * @param template
-        *            The template to render
-        * @param pageTitleKey
-        *            The l10n key of the page title
-        * @param webInterface
-        *            The Sone web interface
-        * @param requireLogin
-        *            Whether this page requires a login
-        */
-       public SoneTemplatePage(String path, Template template, String pageTitleKey, WebInterface webInterface, boolean requireLogin) {
-               super(path, webInterface.getTemplateContextFactory(), template, "noPermission.html");
-               this.pageTitleKey = pageTitleKey;
-               this.webInterface = webInterface;
-               this.requireLogin = requireLogin;
-       }
-
-       //
-       // PROTECTED METHODS
-       //
-
-       /**
-        * Returns the currently logged in Sone.
-        *
-        * @param toadletContext
-        *            The toadlet context
-        * @return The currently logged in Sone, or {@code null} if no Sone is
-        *         currently logged in
-        */
-       protected Sone getCurrentSone(ToadletContext toadletContext) {
-               return webInterface.getCurrentSoneCreatingSession(toadletContext);
-       }
-
-       protected Sone getCurrentSoneWithoutCreatingSession(ToadletContext toadletContext) {
-               return webInterface.getCurrentSoneWithoutCreatingSession(toadletContext);
-       }
-
-       /**
-        * Sets the currently logged in Sone.
-        *
-        * @param toadletContext
-        *            The toadlet context
-        * @param sone
-        *            The Sone to set as currently logged in
-        */
-       protected void setCurrentSone(ToadletContext toadletContext, Sone sone) {
-               webInterface.setCurrentSone(toadletContext, sone);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected String getPageTitle(FreenetRequest request) {
-               if (pageTitleKey != null) {
-                       return webInterface.getL10n().getString(pageTitleKey);
-               }
-               return "";
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected List<Map<String, String>> getAdditionalLinkNodes(FreenetRequest request) {
-               return ImmutableList.<Map<String, String>> builder().add(ImmutableMap.<String, String> builder().put("rel", "search").put("type", "application/opensearchdescription+xml").put("title", "Sone").put("href", "http://" + request.getHttpRequest().getHeader("host") + "/Sone/OpenSearch.xml").build()).build();
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected Collection<String> getStyleSheets() {
-               return Arrays.asList("css/sone.css");
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected String getShortcutIcon() {
-               return "images/icon.png";
-       }
-
-       /**
-        * Returns whether this page requires the user to log in.
-        *
-        * @return {@code true} if the user is required to be logged in to use this
-        *         page, {@code false} otherwise
-        */
-       protected boolean requiresLogin() {
-               return requireLogin;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected final void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               super.processTemplate(request, templateContext);
-               Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
-               templateContext.set("preferences", webInterface.getCore().getPreferences());
-               templateContext.set("currentSone", currentSone);
-               templateContext.set("localSones", webInterface.getCore().getLocalSones());
-               templateContext.set("request", request);
-               templateContext.set("currentVersion", SonePlugin.getPluginVersion());
-               templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
-               templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition());
-               templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
-               templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
-               List<Notification> notifications = new ArrayList<Notification>(webInterface.getNotifications(currentSone));
-               Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
-               templateContext.set("notifications", notifications);
-               templateContext.set("notificationHash", notifications.hashCode());
-               handleRequest(request, templateContext);
-       }
-
-       protected void handleRequest(@Nonnull FreenetRequest request, @Nonnull TemplateContext templateContext) throws RedirectException {
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected String getRedirectTarget(FreenetRequest request) {
-               if (requiresLogin() && (getCurrentSoneWithoutCreatingSession(request.getToadletContext()) == null)) {
-                       HTTPRequest httpRequest = request.getHttpRequest();
-                       String originalUrl = httpRequest.getPath();
-                       if (httpRequest.hasParameters()) {
-                               StringBuilder requestParameters = new StringBuilder();
-                               for (String parameterName : httpRequest.getParameterNames()) {
-                                       if (requestParameters.length() > 0) {
-                                               requestParameters.append("&");
-                                       }
-                                       String[] parameterValues = httpRequest.getMultipleParam(parameterName);
-                                       for (String parameterValue : parameterValues) {
-                                               requestParameters.append(urlEncode(parameterName)).append("=").append(urlEncode(parameterValue));
-                                       }
-                               }
-                               originalUrl += "?" + requestParameters.toString();
-                       }
-                       return "login.html?target=" + urlEncode(originalUrl);
-               }
-               return null;
-       }
-
-       private static String urlEncode(String value) {
-               try {
-                       return URLEncoder.encode(value, "UTF-8");
-               } catch (UnsupportedEncodingException uee1) {
-                                                       /* A JVM without UTF-8? I don’t think so. */
-                       throw new RuntimeException(uee1);
-               }
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected boolean isFullAccessOnly() {
-               return webInterface.getCore().getPreferences().isRequireFullAccess();
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean isEnabled(ToadletContext toadletContext) {
-               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
-                       return false;
-               }
-               if (requiresLogin()) {
-                       return getCurrentSoneWithoutCreatingSession(toadletContext) != null;
-               }
-               return true;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/TrustPage.java b/src/main/java/net/pterodactylus/sone/web/TrustPage.java
deleted file mode 100644 (file)
index 5b0bfbb..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Sone - TrustPage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import com.google.common.base.Optional;
-
-import net.pterodactylus.sone.core.Core;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * Page that lets the user trust another Sone. This will assign a configurable
- * amount of trust to an identity.
- *
- * @see Core#trustSone(Sone, Sone)
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class TrustPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “trust Sone” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public TrustPage(Template template, WebInterface webInterface) {
-               super("trust.html", template, "Page.Trust.Title", webInterface, true);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-                       String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       Optional<Sone> sone = webInterface.getCore().getSone(identity);
-                       if (sone.isPresent()) {
-                               webInterface.getCore().trustSone(currentSone, sone.get());
-                       }
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java b/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java
deleted file mode 100644 (file)
index 9cc266e..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Sone - UnbookmarkPage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import java.util.Set;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-import com.google.common.base.Optional;
-
-/**
- * Page that lets the user unbookmark a post.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UnbookmarkPage extends SoneTemplatePage {
-
-       /**
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public UnbookmarkPage(Template template, WebInterface webInterface) {
-               super("unbookmark.html", template, "Page.Unbookmark.Title", webInterface);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       String id = request.getHttpRequest().getPartAsStringFailsafe("post", 36);
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-                       Optional<Post> post = webInterface.getCore().getPost(id);
-                       if (post.isPresent()) {
-                               webInterface.getCore().unbookmarkPost(post.get());
-                       }
-                       throw new RedirectException(returnPage);
-               }
-               String id = request.getHttpRequest().getParam("post");
-               if (id.equals("allNotLoaded")) {
-                       Set<Post> posts = webInterface.getCore().getBookmarkedPosts();
-                       for (Post post : posts) {
-                               if (!post.isLoaded()) {
-                                       webInterface.getCore().unbookmarkPost(post);
-                               }
-                       }
-                       throw new RedirectException("bookmarks.html");
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java
deleted file mode 100644 (file)
index bff4013..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Sone - UnfollowSonePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * This page lets the user unfollow another Sone.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UnfollowSonePage extends SoneTemplatePage {
-
-       /**
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public UnfollowSonePage(Template template, WebInterface webInterface) {
-               super("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, true);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       String soneIds = request.getHttpRequest().getPartAsStringFailsafe("sone", 2000);
-                       for (String soneId : soneIds.split("[ ,]+")) {
-                               webInterface.getCore().unfollowSone(currentSone, soneId);
-                       }
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java
deleted file mode 100644 (file)
index a17502d..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Sone - UnlikePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * Page that lets the user unlike a {@link Post}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UnlikePage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “unlike post” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public UnlikePage(Template template, WebInterface webInterface) {
-               super("unlike.html", template, "Page.Unlike.Title", webInterface, true);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16);
-                       String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       if ("post".equals(type)) {
-                               currentSone.removeLikedPostId(id);
-                       } else if ("reply".equals(type)) {
-                               currentSone.removeLikedReplyId(id);
-                       }
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java
deleted file mode 100644 (file)
index 7c36a88..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Sone - UnlockSonePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-/**
- * This page lets the user unlock a {@link Sone} to allow its insertion.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UnlockSonePage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “unlock Sone” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public UnlockSonePage(Template template, WebInterface webInterface) {
-               super("unlockSone.html", template, "Page.UnlockSone.Title", webInterface);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
-               Sone sone = webInterface.getCore().getLocalSone(soneId);
-               if (sone != null) {
-                       webInterface.getCore().unlockSone(sone);
-               }
-               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-               throw new RedirectException(returnPage);
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/UntrustPage.java b/src/main/java/net/pterodactylus/sone/web/UntrustPage.java
deleted file mode 100644 (file)
index cba3635..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Sone - UntrustPage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import com.google.common.base.Optional;
-
-import net.pterodactylus.sone.core.Core;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-/**
- * Page that lets the user untrust another Sone. This will remove all trust
- * assignments for an identity.
- *
- * @see Core#untrustSone(Sone, Sone)
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UntrustPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “untrust Sone” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public UntrustPage(Template template, WebInterface webInterface) {
-               super("untrust.html", template, "Page.Untrust.Title", webInterface, true);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
-                       String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       Optional<Sone> sone = webInterface.getCore().getSone(identity);
-                       if (sone.isPresent()) {
-                               webInterface.getCore().untrustSone(currentSone, sone.get());
-                       }
-                       throw new RedirectException(returnPage);
-               }
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java b/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java
deleted file mode 100644 (file)
index 467ceda..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Sone - UploadImagePage.java - Copyright © 2011–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static com.google.common.base.Optional.fromNullable;
-import static java.util.logging.Logger.getLogger;
-
-import java.awt.Image;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.stream.ImageInputStream;
-
-import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.sone.data.Image.Modifier.ImageTitleMustNotBeEmpty;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.data.TemporaryImage;
-import net.pterodactylus.sone.text.TextFilter;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.io.Closer;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-import net.pterodactylus.util.web.Method;
-
-import com.google.common.io.ByteStreams;
-
-import freenet.support.api.Bucket;
-import freenet.support.api.HTTPUploadedFile;
-
-/**
- * Page implementation that lets the user upload an image.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UploadImagePage extends SoneTemplatePage {
-
-       private static final Logger logger = getLogger(UploadImagePage.class.getName());
-       private static final String UNKNOWN_MIME_TYPE = "application/octet-stream";
-
-       /**
-        * Creates a new “upload image” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public UploadImagePage(Template template, WebInterface webInterface) {
-               super("uploadImage.html", template, "Page.UploadImage.Title", webInterface, true);
-       }
-
-       //
-       // SONETEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               if (request.getMethod() == Method.POST) {
-                       Sone currentSone = getCurrentSone(request.getToadletContext());
-                       String parentId = request.getHttpRequest().getPartAsStringFailsafe("parent", 36);
-                       Album parent = webInterface.getCore().getAlbum(parentId);
-                       if (parent == null) {
-                               throw new RedirectException("noPermission.html");
-                       }
-                       if (!currentSone.equals(parent.getSone())) {
-                               throw new RedirectException("noPermission.html");
-                       }
-                       String name = request.getHttpRequest().getPartAsStringFailsafe("title", 200).trim();
-                       if (name.length() == 0) {
-                               throw new RedirectException("emptyImageTitle.html");
-                       }
-                       String description = request.getHttpRequest().getPartAsStringFailsafe("description", 4000);
-                       HTTPUploadedFile uploadedFile = request.getHttpRequest().getUploadedFile("image");
-                       Bucket fileBucket = uploadedFile.getData();
-                       InputStream imageInputStream = null;
-                       ByteArrayOutputStream imageDataOutputStream = null;
-                       try {
-                               imageInputStream = fileBucket.getInputStream();
-                               /* TODO - check length */
-                               imageDataOutputStream = new ByteArrayOutputStream((int) fileBucket.size());
-                               ByteStreams.copy(imageInputStream, imageDataOutputStream);
-                       } catch (IOException ioe1) {
-                               logger.log(Level.WARNING, "Could not read uploaded image!", ioe1);
-                               return;
-                       } finally {
-                               fileBucket.free();
-                               Closer.close(imageInputStream);
-                               Closer.close(imageDataOutputStream);
-                       }
-                       byte[] imageData = imageDataOutputStream.toByteArray();
-                       ByteArrayInputStream imageDataInputStream = null;
-                       Image uploadedImage = null;
-                       try {
-                               imageDataInputStream = new ByteArrayInputStream(imageData);
-                               uploadedImage = ImageIO.read(imageDataInputStream);
-                               if (uploadedImage == null) {
-                                       templateContext.set("messages", webInterface.getL10n().getString("Page.UploadImage.Error.InvalidImage"));
-                                       return;
-                               }
-                               String mimeType = getMimeType(imageData);
-                               TemporaryImage temporaryImage = webInterface.getCore().createTemporaryImage(mimeType, imageData);
-                               net.pterodactylus.sone.data.Image image = webInterface.getCore().createImage(currentSone, parent, temporaryImage);
-                               image.modify().setTitle(name).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).setWidth(uploadedImage.getWidth(null)).setHeight(uploadedImage.getHeight(null)).update();
-                       } catch (IOException ioe1) {
-                               logger.log(Level.WARNING, "Could not read uploaded image!", ioe1);
-                               return;
-                       } catch (ImageTitleMustNotBeEmpty itmnbe) {
-                               throw new RedirectException("emptyImageTitle.html");
-                       } finally {
-                               Closer.close(imageDataInputStream);
-                               Closer.flush(uploadedImage);
-                       }
-                       throw new RedirectException("imageBrowser.html?album=" + parent.getId());
-               }
-       }
-
-       //
-       // PRIVATE METHODS
-       //
-
-       /**
-        * Tries to detect the MIME type of the encoded image.
-        *
-        * @param imageData
-        *            The encoded image
-        * @return The MIME type of the image, or “application/octet-stream” if the
-        *         image type could not be detected
-        */
-       private static String getMimeType(byte[] imageData) {
-               ByteArrayInputStream imageDataInputStream = new ByteArrayInputStream(imageData);
-               try {
-                       ImageInputStream imageInputStream = ImageIO.createImageInputStream(imageDataInputStream);
-                       Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(imageInputStream);
-                       if (imageReaders.hasNext()) {
-                               return fromNullable(imageReaders.next().getOriginatingProvider().getMIMETypes())
-                                               .or(new String[] { UNKNOWN_MIME_TYPE })[0];
-                       }
-               } catch (IOException ioe1) {
-                       logger.log(Level.FINE, "Could not detect MIME type for image.", ioe1);
-               }
-               return UNKNOWN_MIME_TYPE;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java
deleted file mode 100644 (file)
index 56bac8d..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Sone - ViewPostPage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import java.net.URI;
-
-import com.google.common.base.Optional;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.template.SoneAccessor;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-/**
- * This page lets the user view a post and all its replies.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class ViewPostPage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “view post” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public ViewPostPage(Template template, WebInterface webInterface) {
-               super("viewPost.html", template, "Page.ViewPost.Title", webInterface, false);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected String getPageTitle(FreenetRequest request) {
-               String postId = request.getHttpRequest().getParam("post");
-               Optional<Post> post = webInterface.getCore().getPost(postId);
-               String title = "";
-               if (post.isPresent()) {
-                       title = post.get().getText().substring(0, Math.min(20, post.get().getText().length())) + "…";
-                       title += " - " + SoneAccessor.getNiceName(post.get().getSone()) + " - ";
-               }
-               title += webInterface.getL10n().getString("Page.ViewPost.Title");
-               return title;
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               String postId = request.getHttpRequest().getParam("post");
-               boolean raw = request.getHttpRequest().getParam("raw").equals("true");
-               Optional<Post> post = webInterface.getCore().getPost(postId);
-               templateContext.set("post", post.orNull());
-               templateContext.set("raw", raw);
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean isLinkExcepted(URI link) {
-               return true;
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
deleted file mode 100644 (file)
index f2c9c91..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Sone - ViewSonePage.java - Copyright © 2010–2016 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web;
-
-import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.template.SoneAccessor;
-import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.template.Template;
-import net.pterodactylus.util.template.TemplateContext;
-
-import com.google.common.base.Optional;
-
-/**
- * Lets the user browser another Sone.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class ViewSonePage extends SoneTemplatePage {
-
-       /**
-        * Creates a new “view Sone” page.
-        *
-        * @param template
-        *            The template to render
-        * @param webInterface
-        *            The Sone web interface
-        */
-       public ViewSonePage(Template template, WebInterface webInterface) {
-               super("viewSone.html", template, webInterface, false);
-       }
-
-       //
-       // TEMPLATEPAGE METHODS
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected String getPageTitle(FreenetRequest request) {
-               String soneId = request.getHttpRequest().getParam("sone");
-               Optional<Sone> sone = webInterface.getCore().getSone(soneId);
-               if (sone.isPresent()) {
-                       String soneName = SoneAccessor.getNiceName(sone.get());
-                       return soneName + " - " + webInterface.getL10n().getString("Page.ViewSone.Title");
-               }
-               return webInterface.getL10n().getString("Page.ViewSone.Page.TitleWithoutSone");
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
-               String soneId = request.getHttpRequest().getParam("sone");
-               Optional<Sone> sone = webInterface.getCore().getSone(soneId);
-               templateContext.set("sone", sone.orNull());
-               templateContext.set("soneId", soneId);
-               if (!sone.isPresent()) {
-                       return;
-               }
-               List<Post> sonePosts = sone.get().getPosts();
-               sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.get().getId()));
-               Collections.sort(sonePosts, Post.NEWEST_FIRST);
-               Pagination<Post> postPagination = new Pagination<Post>(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("postPage"), 0));
-               templateContext.set("postPagination", postPagination);
-               templateContext.set("posts", postPagination.getItems());
-               Set<PostReply> replies = sone.get().getReplies();
-               final Map<Post, List<PostReply>> repliedPosts = new HashMap<Post, List<PostReply>>();
-               for (PostReply reply : replies) {
-                       Optional<Post> post = reply.getPost();
-                       if (!post.isPresent() || repliedPosts.containsKey(post.get()) || sone.get().equals(post.get().getSone()) || (sone.get().getId().equals(post.get().getRecipientId().orNull()))) {
-                               continue;
-                       }
-                       repliedPosts.put(post.get(), webInterface.getCore().getReplies(post.get().getId()));
-               }
-               List<Post> posts = new ArrayList<Post>(repliedPosts.keySet());
-               Collections.sort(posts, new Comparator<Post>() {
-
-                       @Override
-                       public int compare(Post leftPost, Post rightPost) {
-                               return (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, repliedPosts.get(rightPost).get(0).getTime() - repliedPosts.get(leftPost).get(0).getTime()));
-                       }
-
-               });
-
-               Pagination<Post> repliedPostPagination = new Pagination<Post>(posts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("repliedPostPage"), 0));
-               templateContext.set("repliedPostPagination", repliedPostPagination);
-               templateContext.set("repliedPosts", repliedPostPagination.getItems());
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public boolean isLinkExcepted(URI link) {
-               return true;
-       }
-
-}
index 6ce38d4..ee309df 100644 (file)
@@ -140,6 +140,49 @@ import net.pterodactylus.sone.web.ajax.UntrustAjaxPage;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.sone.web.page.PageToadlet;
 import net.pterodactylus.sone.web.page.PageToadletFactory;
+import net.pterodactylus.sone.web.pages.AboutPage;
+import net.pterodactylus.sone.web.pages.BookmarkPage;
+import net.pterodactylus.sone.web.pages.BookmarksPage;
+import net.pterodactylus.sone.web.pages.CreateAlbumPage;
+import net.pterodactylus.sone.web.pages.CreatePostPage;
+import net.pterodactylus.sone.web.pages.CreateReplyPage;
+import net.pterodactylus.sone.web.pages.CreateSonePage;
+import net.pterodactylus.sone.web.pages.DeleteAlbumPage;
+import net.pterodactylus.sone.web.pages.DeleteImagePage;
+import net.pterodactylus.sone.web.pages.DeletePostPage;
+import net.pterodactylus.sone.web.pages.DeleteProfileFieldPage;
+import net.pterodactylus.sone.web.pages.DeleteReplyPage;
+import net.pterodactylus.sone.web.pages.DeleteSonePage;
+import net.pterodactylus.sone.web.pages.DismissNotificationPage;
+import net.pterodactylus.sone.web.pages.DistrustPage;
+import net.pterodactylus.sone.web.pages.EditAlbumPage;
+import net.pterodactylus.sone.web.pages.EditImagePage;
+import net.pterodactylus.sone.web.pages.EditProfileFieldPage;
+import net.pterodactylus.sone.web.pages.EditProfilePage;
+import net.pterodactylus.sone.web.pages.FollowSonePage;
+import net.pterodactylus.sone.web.pages.GetImagePage;
+import net.pterodactylus.sone.web.pages.ImageBrowserPage;
+import net.pterodactylus.sone.web.pages.IndexPage;
+import net.pterodactylus.sone.web.pages.KnownSonesPage;
+import net.pterodactylus.sone.web.pages.LikePage;
+import net.pterodactylus.sone.web.pages.LockSonePage;
+import net.pterodactylus.sone.web.pages.LoginPage;
+import net.pterodactylus.sone.web.pages.LogoutPage;
+import net.pterodactylus.sone.web.pages.MarkAsKnownPage;
+import net.pterodactylus.sone.web.pages.NewPage;
+import net.pterodactylus.sone.web.pages.OptionsPage;
+import net.pterodactylus.sone.web.pages.RescuePage;
+import net.pterodactylus.sone.web.pages.SearchPage;
+import net.pterodactylus.sone.web.pages.SoneTemplatePage;
+import net.pterodactylus.sone.web.pages.TrustPage;
+import net.pterodactylus.sone.web.pages.UnbookmarkPage;
+import net.pterodactylus.sone.web.pages.UnfollowSonePage;
+import net.pterodactylus.sone.web.pages.UnlikePage;
+import net.pterodactylus.sone.web.pages.UnlockSonePage;
+import net.pterodactylus.sone.web.pages.UntrustPage;
+import net.pterodactylus.sone.web.pages.UploadImagePage;
+import net.pterodactylus.sone.web.pages.ViewPostPage;
+import net.pterodactylus.sone.web.pages.ViewSonePage;
 import net.pterodactylus.util.notify.Notification;
 import net.pterodactylus.util.notify.NotificationManager;
 import net.pterodactylus.util.notify.TemplateNotification;
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/EditImagePage.java b/src/main/java/net/pterodactylus/sone/web/pages/EditImagePage.java
new file mode 100644 (file)
index 0000000..34f404e
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Sone - EditImagePage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.text.TextFilter;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+/**
+ * Page that lets the user edit title and description of an {@link Image}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class EditImagePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “edit image” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public EditImagePage(Template template, WebInterface webInterface) {
+               super("editImage.html", template, "Page.EditImage.Title", webInterface, true);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               if (request.getMethod() == Method.POST) {
+                       String imageId = request.getHttpRequest().getPartAsStringFailsafe("image", 36);
+                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+                       Image image = webInterface.getCore().getImage(imageId, false);
+                       if (image == null) {
+                               throw new RedirectException("invalid.html");
+                       }
+                       if (!image.getSone().isLocal()) {
+                               throw new RedirectException("noPermission.html");
+                       }
+                       if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveLeft", 4))) {
+                               image.getAlbum().moveImageUp(image);
+                       } else if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveRight", 4))) {
+                               image.getAlbum().moveImageDown(image);
+                       } else {
+                               String title = request.getHttpRequest().getPartAsStringFailsafe("title", 100).trim();
+                               String description = request.getHttpRequest().getPartAsStringFailsafe("description", 1024).trim();
+                               if (title.length() == 0) {
+                                       throw new RedirectException("emptyImageTitle.html");
+                               }
+                               image.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
+                       }
+                       webInterface.getCore().touchConfiguration();
+                       throw new RedirectException(returnPage);
+               }
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/EditProfileFieldPage.java b/src/main/java/net/pterodactylus/sone/web/pages/EditProfileFieldPage.java
new file mode 100644 (file)
index 0000000..2bfdddf
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Sone - EditProfileFieldPage.java - Copyright © 2011–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+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.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+/**
+ * Page that lets the user edit the name of a profile field.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class EditProfileFieldPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “edit profile field” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public EditProfileFieldPage(Template template, WebInterface webInterface) {
+               super("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, true);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               Sone currentSone = getCurrentSone(request.getToadletContext());
+               Profile profile = currentSone.getProfile();
+
+               /* get parameters from request. */
+               String fieldId = request.getHttpRequest().getParam("field");
+               Field field = profile.getFieldById(fieldId);
+               if (field == null) {
+                       throw new RedirectException("invalid.html");
+               }
+
+               /* process the POST request. */
+               if (request.getMethod() == Method.POST) {
+                       if (request.getHttpRequest().getPartAsStringFailsafe("cancel", 4).equals("true")) {
+                               throw new RedirectException("editProfile.html#profile-fields");
+                       }
+                       fieldId = request.getHttpRequest().getPartAsStringFailsafe("field", 36);
+                       field = profile.getFieldById(fieldId);
+                       if (field == null) {
+                               throw new RedirectException("invalid.html");
+                       }
+                       String name = request.getHttpRequest().getPartAsStringFailsafe("name", 256);
+                       Field existingField = profile.getFieldByName(name);
+                       if ((existingField != null) && (!field.equals(existingField))) {
+                               templateContext.set("duplicateFieldName", true);
+                       } else {
+                               if (!name.equals(field.getName())) {
+                                       field.setName(name);
+                                       currentSone.setProfile(profile);
+                               }
+                               throw new RedirectException("editProfile.html#profile-fields");
+                       }
+               }
+
+               /* store current values in template. */
+               templateContext.set("field", field);
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/EditProfilePage.java b/src/main/java/net/pterodactylus/sone/web/pages/EditProfilePage.java
new file mode 100644 (file)
index 0000000..b17a22e
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * Sone - EditProfilePage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import static net.pterodactylus.sone.text.TextFilter.filter;
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
+import java.util.List;
+
+import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Profile.DuplicateField;
+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.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+import freenet.clients.http.ToadletContext;
+
+/**
+ * This page lets the user edit her profile.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class EditProfilePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “edit profile” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public EditProfilePage(Template template, WebInterface webInterface) {
+               super("editProfile.html", template, "Page.EditProfile.Title", webInterface, true);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               ToadletContext toadletContenxt = request.getToadletContext();
+               Sone currentSone = getCurrentSone(toadletContenxt);
+               Profile profile = currentSone.getProfile();
+               String firstName = profile.getFirstName();
+               String middleName = profile.getMiddleName();
+               String lastName = profile.getLastName();
+               Integer birthDay = profile.getBirthDay();
+               Integer birthMonth = profile.getBirthMonth();
+               Integer birthYear = profile.getBirthYear();
+               String avatarId = profile.getAvatar();
+               List<Field> fields = profile.getFields();
+               if (request.getMethod() == Method.POST) {
+                       if (request.getHttpRequest().getPartAsStringFailsafe("save-profile", 4).equals("true")) {
+                               firstName = request.getHttpRequest().getPartAsStringFailsafe("first-name", 256).trim();
+                               middleName = request.getHttpRequest().getPartAsStringFailsafe("middle-name", 256).trim();
+                               lastName = request.getHttpRequest().getPartAsStringFailsafe("last-name", 256).trim();
+                               birthDay = parseInt(request.getHttpRequest().getPartAsStringFailsafe("birth-day", 256).trim(), null);
+                               birthMonth = parseInt(request.getHttpRequest().getPartAsStringFailsafe("birth-month", 256).trim(), null);
+                               birthYear = parseInt(request.getHttpRequest().getPartAsStringFailsafe("birth-year", 256).trim(), null);
+                               avatarId = request.getHttpRequest().getPartAsStringFailsafe("avatarId", 36);
+                               profile.setFirstName(firstName.length() > 0 ? firstName : null);
+                               profile.setMiddleName(middleName.length() > 0 ? middleName : null);
+                               profile.setLastName(lastName.length() > 0 ? lastName : null);
+                               profile.setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear);
+                               profile.setAvatar(webInterface.getCore().getImage(avatarId, false));
+                               for (Field field : fields) {
+                                       String value = request.getHttpRequest().getPartAsStringFailsafe("field-" + field.getId(), 400);
+                                       String filteredValue = filter(request.getHttpRequest().getHeader("Host"), value);
+                                       field.setValue(filteredValue);
+                               }
+                               currentSone.setProfile(profile);
+                               webInterface.getCore().touchConfiguration();
+                               throw new RedirectException("editProfile.html");
+                       } else if (request.getHttpRequest().getPartAsStringFailsafe("add-field", 4).equals("true")) {
+                               String fieldName = request.getHttpRequest().getPartAsStringFailsafe("field-name", 256).trim();
+                               try {
+                                       profile.addField(fieldName);
+                                       currentSone.setProfile(profile);
+                                       webInterface.getCore().touchConfiguration();
+                                       throw new RedirectException("editProfile.html#profile-fields");
+                               } catch (DuplicateField df1) {
+                                       templateContext.set("fieldName", fieldName);
+                                       templateContext.set("duplicateFieldName", true);
+                               }
+                       } else {
+                               String id = getFieldId(request, "delete-field-");
+                               if (id != null) {
+                                       throw new RedirectException("deleteProfileField.html?field=" + id);
+                               }
+                               id = getFieldId(request, "move-up-field-");
+                               if (id != null) {
+                                       Field field = profile.getFieldById(id);
+                                       if (field == null) {
+                                               throw new RedirectException("invalid.html");
+                                       }
+                                       profile.moveFieldUp(field);
+                                       currentSone.setProfile(profile);
+                                       throw new RedirectException("editProfile.html#profile-fields");
+                               }
+                               id = getFieldId(request, "move-down-field-");
+                               if (id != null) {
+                                       Field field = profile.getFieldById(id);
+                                       if (field == null) {
+                                               throw new RedirectException("invalid.html");
+                                       }
+                                       profile.moveFieldDown(field);
+                                       currentSone.setProfile(profile);
+                                       throw new RedirectException("editProfile.html#profile-fields");
+                               }
+                               id = getFieldId(request, "edit-field-");
+                               if (id != null) {
+                                       throw new RedirectException("editProfileField.html?field=" + id);
+                               }
+                       }
+               }
+               templateContext.set("firstName", firstName);
+               templateContext.set("middleName", middleName);
+               templateContext.set("lastName", lastName);
+               templateContext.set("birthDay", birthDay);
+               templateContext.set("birthMonth", birthMonth);
+               templateContext.set("birthYear", birthYear);
+               templateContext.set("avatarId", avatarId);
+               templateContext.set("fields", fields);
+       }
+
+       //
+       // PRIVATE METHODS
+       //
+
+       /**
+        * Searches for a part whose names starts with the given {@code String} and
+        * extracts the ID from the located name.
+        *
+        * @param request
+        *            The request to get the parts from
+        * @param partNameStart
+        *            The start of the name of the requested part
+        * @return The parsed ID, or {@code null} if there was no part matching the
+        *         given string
+        */
+       private static String getFieldId(FreenetRequest request, String partNameStart) {
+               for (String partName : request.getHttpRequest().getParts()) {
+                       if (partName.startsWith(partNameStart)) {
+                               return partName.substring(partNameStart.length());
+                       }
+               }
+               return null;
+       }
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/FollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/pages/FollowSonePage.java
new file mode 100644 (file)
index 0000000..9bfb790
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Sone - FollowSonePage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+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.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+/**
+ * This page lets the user follow another Sone.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class FollowSonePage extends SoneTemplatePage {
+
+       /**
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public FollowSonePage(Template template, WebInterface webInterface) {
+               super("followSone.html", template, "Page.FollowSone.Title", webInterface, true);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               if (request.getMethod() == Method.POST) {
+                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+                       Sone currentSone = getCurrentSone(request.getToadletContext());
+                       String soneIds = request.getHttpRequest().getPartAsStringFailsafe("sone", 1200);
+                       for (String soneId : soneIds.split("[ ,]+")) {
+                               Optional<Sone> sone = webInterface.getCore().getSone(soneId);
+                               if (sone.isPresent()) {
+                                       webInterface.getCore().followSone(currentSone, soneId);
+                                       webInterface.getCore().markSoneKnown(sone.get());
+                               }
+                       }
+                       throw new RedirectException(returnPage);
+               }
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/GetImagePage.java b/src/main/java/net/pterodactylus/sone/web/pages/GetImagePage.java
new file mode 100644 (file)
index 0000000..bcf0eda
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Sone - GetImagePage.java - Copyright © 2011–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import java.io.IOException;
+import java.net.URI;
+
+import net.pterodactylus.sone.data.TemporaryImage;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetPage;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.web.Response;
+
+/**
+ * Page that delivers a {@link TemporaryImage} to the browser.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class GetImagePage implements FreenetPage {
+
+       /** The Sone web interface. */
+       private final WebInterface webInterface;
+
+       /**
+        * Creates a new “get image” page.
+        *
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public GetImagePage(WebInterface webInterface) {
+               this.webInterface = webInterface;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public String getPath() {
+               return "getImage.html";
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean isPrefixPage() {
+               return false;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public Response handleRequest(FreenetRequest request, Response response) throws IOException {
+               String imageId = request.getHttpRequest().getParam("image");
+               TemporaryImage temporaryImage = webInterface.getCore().getTemporaryImage(imageId);
+               if (temporaryImage == null) {
+                       return response.setStatusCode(404).setStatusText("Not found.").setContentType("text/html; charset=utf-8");
+               }
+               String contentType= temporaryImage.getMimeType();
+               return response.setStatusCode(200).setStatusText("OK").setContentType(contentType).addHeader("Content-Disposition", "attachment; filename=" + temporaryImage.getId() + "." + contentType.substring(contentType.lastIndexOf('/') + 1)).write(temporaryImage.getImageData());
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean isLinkExcepted(URI link) {
+               return false;
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/ImageBrowserPage.java b/src/main/java/net/pterodactylus/sone/web/pages/ImageBrowserPage.java
new file mode 100644 (file)
index 0000000..2e53761
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Sone - ImageBrowserPage.java - Copyright © 2011–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import static com.google.common.collect.FluentIterable.from;
+import static net.pterodactylus.sone.data.Album.FLATTENER;
+import static net.pterodactylus.sone.data.Album.NOT_EMPTY;
+import static net.pterodactylus.sone.data.Album.TITLE_COMPARATOR;
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import com.google.common.base.Optional;
+
+import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+
+/**
+ * The image browser page is the entry page for the image management.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ImageBrowserPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new image browser page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public ImageBrowserPage(Template template, WebInterface webInterface) {
+               super("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               String albumId = request.getHttpRequest().getParam("album", null);
+               if (albumId != null) {
+                       Album album = webInterface.getCore().getAlbum(albumId);
+                       templateContext.set("albumRequested", true);
+                       templateContext.set("album", album);
+                       templateContext.set("page", request.getHttpRequest().getParam("page"));
+                       return;
+               }
+               String imageId = request.getHttpRequest().getParam("image", null);
+               if (imageId != null) {
+                       Image image = webInterface.getCore().getImage(imageId, false);
+                       templateContext.set("imageRequested", true);
+                       templateContext.set("image", image);
+                       return;
+               }
+               String soneId = request.getHttpRequest().getParam("sone", null);
+               if (soneId != null) {
+                       Optional<Sone> sone = webInterface.getCore().getSone(soneId);
+                       templateContext.set("soneRequested", true);
+                       templateContext.set("sone", sone.orNull());
+                       return;
+               }
+               String mode = request.getHttpRequest().getParam("mode", null);
+               if ("gallery".equals(mode)) {
+                       templateContext.set("galleryRequested", true);
+                       List<Album> albums = new ArrayList<Album>();
+                       for (Sone sone : webInterface.getCore().getSones()) {
+                               albums.addAll(from(sone.getRootAlbum().getAlbums()).transformAndConcat(FLATTENER).filter(NOT_EMPTY).toList());
+                       }
+                       Collections.sort(albums, TITLE_COMPARATOR);
+                       Pagination<Album> albumPagination = new Pagination<Album>(albums, 12).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
+                       templateContext.set("albumPagination", albumPagination);
+                       templateContext.set("albums", albumPagination.getItems());
+                       return;
+               }
+               Sone sone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
+               templateContext.set("soneRequested", true);
+               templateContext.set("sone", sone);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean isLinkExcepted(URI link) {
+               return true;
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/pages/IndexPage.java
new file mode 100644 (file)
index 0000000..5946a57
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Sone - IndexPage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.notify.PostVisibilityFilter;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Collections2;
+
+/**
+ * The index page shows the main page of Sone. This page will contain the posts
+ * of all friends of the current user.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class IndexPage extends SoneTemplatePage {
+
+       private final PostVisibilityFilter postVisibilityFilter;
+
+       public IndexPage(Template template, WebInterface webInterface, PostVisibilityFilter postVisibilityFilter) {
+               super("index.html", template, "Page.Index.Title", webInterface, true);
+               this.postVisibilityFilter = postVisibilityFilter;
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               final Sone currentSone = getCurrentSone(request.getToadletContext());
+               Collection<Post> allPosts = new ArrayList<Post>();
+               allPosts.addAll(currentSone.getPosts());
+               for (String friendSoneId : currentSone.getFriends()) {
+                       Optional<Sone> friendSone = webInterface.getCore().getSone(friendSoneId);
+                       if (!friendSone.isPresent()) {
+                               continue;
+                       }
+                       allPosts.addAll(friendSone.get().getPosts());
+               }
+               for (Sone sone : webInterface.getCore().getSones()) {
+                       for (Post post : sone.getPosts()) {
+                               if (currentSone.equals(post.getRecipient().orNull()) && !allPosts.contains(post)) {
+                                       allPosts.add(post);
+                               }
+                       }
+               }
+               allPosts = Collections2.filter(allPosts, postVisibilityFilter.isVisible(currentSone));
+               List<Post> sortedPosts = new ArrayList<Post>(allPosts);
+               Collections.sort(sortedPosts, Post.NEWEST_FIRST);
+               Pagination<Post> pagination = new Pagination<Post>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
+               templateContext.set("pagination", pagination);
+               templateContext.set("posts", pagination.getItems());
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/pages/KnownSonesPage.java
new file mode 100644 (file)
index 0000000..5aef1f9
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Sone - KnownSonesPage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Ordering;
+
+/**
+ * This page shows all known Sones.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class KnownSonesPage extends SoneTemplatePage {
+
+       private static final String defaultSortField = "activity";
+       private static final String defaultSortOrder = "desc";
+
+       /**
+        * Creates a “known Sones” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public KnownSonesPage(Template template, WebInterface webInterface) {
+               super("knownSones.html", template, "Page.KnownSones.Title", webInterface, false);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               String sortField = request.getHttpRequest().getParam("sort", defaultSortField);
+               String sortOrder = request.getHttpRequest().getParam("order", defaultSortOrder);
+               String filter = request.getHttpRequest().getParam("filter");
+               templateContext.set("sort", sortField);
+               templateContext.set("order", sortOrder);
+               templateContext.set("filter", filter);
+               final Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
+               Collection<Sone> knownSones = Collections2.filter(webInterface.getCore().getSones(), Sone.EMPTY_SONE_FILTER);
+               if ((currentSone != null) && "followed".equals(filter)) {
+                       knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
+
+                               @Override
+                               public boolean apply(Sone sone) {
+                                       return currentSone.hasFriend(sone.getId());
+                               }
+                       });
+               } else if ((currentSone != null) && "not-followed".equals(filter)) {
+                       knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
+
+                               @Override
+                               public boolean apply(Sone sone) {
+                                       return !currentSone.hasFriend(sone.getId());
+                               }
+                       });
+               } else if ("new".equals(filter)) {
+                       knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
+
+                               /**
+                                * {@inheritDoc}
+                                */
+                               @Override
+                               public boolean apply(Sone sone) {
+                                       return !sone.isKnown();
+                               }
+                       });
+               } else if ("not-new".equals(filter)) {
+                       knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
+
+                               /**
+                                * {@inheritDoc}
+                                */
+                               @Override
+                               public boolean apply(Sone sone) {
+                                       return sone.isKnown();
+                               }
+                       });
+               } else if ("own".equals(filter)) {
+                       knownSones = Collections2.filter(knownSones, Sone.LOCAL_SONE_FILTER);
+               } else if ("not-own".equals(filter)) {
+                       knownSones = Collections2.filter(knownSones, Predicates.not(Sone.LOCAL_SONE_FILTER));
+               }
+               List<Sone> sortedSones = new ArrayList<Sone>(knownSones);
+               if ("activity".equals(sortField)) {
+                       if ("asc".equals(sortOrder)) {
+                               Collections.sort(sortedSones, Ordering.from(Sone.LAST_ACTIVITY_COMPARATOR).reverse());
+                       } else {
+                               Collections.sort(sortedSones, Sone.LAST_ACTIVITY_COMPARATOR);
+                       }
+               } else if ("posts".equals(sortField)) {
+                       if ("asc".equals(sortOrder)) {
+                               Collections.sort(sortedSones, Ordering.from(Sone.POST_COUNT_COMPARATOR).reverse());
+                       } else {
+                               Collections.sort(sortedSones, Sone.POST_COUNT_COMPARATOR);
+                       }
+               } else if ("images".equals(sortField)) {
+                       if ("asc".equals(sortOrder)) {
+                               Collections.sort(sortedSones, Ordering.from(Sone.IMAGE_COUNT_COMPARATOR).reverse());
+                       } else {
+                               Collections.sort(sortedSones, Sone.IMAGE_COUNT_COMPARATOR);
+                       }
+               } else {
+                       if ("desc".equals(sortOrder)) {
+                               Collections.sort(sortedSones, Ordering.from(Sone.NICE_NAME_COMPARATOR).reverse());
+                       } else {
+                               Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR);
+                       }
+               }
+               Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
+               templateContext.set("pagination", sonePagination);
+               templateContext.set("knownSones", sonePagination.getItems());
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/LikePage.java b/src/main/java/net/pterodactylus/sone/web/pages/LikePage.java
new file mode 100644 (file)
index 0000000..529b620
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Sone - LikePage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+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.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+/**
+ * Page that lets the user like a {@link Post}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class LikePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “like post” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public LikePage(Template template, WebInterface webInterface) {
+               super("like.html", template, "Page.Like.Title", webInterface, true);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               if (request.getMethod() == Method.POST) {
+                       String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16);
+                       String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
+                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+                       Sone currentSone = getCurrentSone(request.getToadletContext());
+                       if ("post".equals(type)) {
+                               currentSone.addLikedPostId(id);
+                       } else if ("reply".equals(type)) {
+                               currentSone.addLikedReplyId(id);
+                       }
+                       throw new RedirectException(returnPage);
+               }
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/LockSonePage.java b/src/main/java/net/pterodactylus/sone/web/pages/LockSonePage.java
new file mode 100644 (file)
index 0000000..8300711
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Sone - LockSonePage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+
+/**
+ * This page lets the user lock a {@link Sone} to prevent it from being
+ * inserted.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class LockSonePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “lock Sone” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public LockSonePage(Template template, WebInterface webInterface) {
+               super("lockSone.html", template, "Page.LockSone.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
+               Sone sone = webInterface.getCore().getLocalSone(soneId);
+               if (sone != null) {
+                       webInterface.getCore().lockSone(sone);
+               }
+               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+               throw new RedirectException(returnPage);
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/LogoutPage.java b/src/main/java/net/pterodactylus/sone/web/pages/LogoutPage.java
new file mode 100644 (file)
index 0000000..1249086
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Sone - LogoutPage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import freenet.clients.http.ToadletContext;
+
+/**
+ * Logs a user out.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class LogoutPage extends SoneTemplatePage {
+
+       /**
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public LogoutPage(Template template, WebInterface webInterface) {
+               super("logout.html", template, "Page.Logout.Title", webInterface, true);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               setCurrentSone(request.getToadletContext(), null);
+               throw new RedirectException("index.html");
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean isEnabled(ToadletContext toadletContext) {
+               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
+                       return false;
+               }
+               return (getCurrentSoneWithoutCreatingSession(toadletContext) != null) && (webInterface.getCore().getLocalSones().size() != 1);
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/MarkAsKnownPage.java b/src/main/java/net/pterodactylus/sone/web/pages/MarkAsKnownPage.java
new file mode 100644 (file)
index 0000000..4eb7a95
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Sone - MarkAsKnownPage.java - Copyright © 2011–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import java.util.StringTokenizer;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
+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.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+
+import com.google.common.base.Optional;
+
+/**
+ * Page that lets the user mark a number of {@link Sone}s, {@link Post}s, or
+ * {@link Reply Replie}s as known.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class MarkAsKnownPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “mark as known” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public MarkAsKnownPage(Template template, WebInterface webInterface) {
+               super("markAsKnown.html", template, "Page.MarkAsKnown.Title", webInterface);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               String type = request.getHttpRequest().getPartAsStringFailsafe("type", 5);
+               if (!type.equals("sone") && !type.equals("post") && !type.equals("reply")) {
+                       throw new RedirectException("invalid.html");
+               }
+               String ids = request.getHttpRequest().getPartAsStringFailsafe("id", 65536);
+               for (StringTokenizer idTokenizer = new StringTokenizer(ids); idTokenizer.hasMoreTokens();) {
+                       String id = idTokenizer.nextToken();
+                       if (type.equals("post")) {
+                               Optional<Post> post = webInterface.getCore().getPost(id);
+                               if (!post.isPresent()) {
+                                       continue;
+                               }
+                               webInterface.getCore().markPostKnown(post.get());
+                       } else if (type.equals("reply")) {
+                               Optional<PostReply> reply = webInterface.getCore().getPostReply(id);
+                               if (!reply.isPresent()) {
+                                       continue;
+                               }
+                               webInterface.getCore().markReplyKnown(reply.get());
+                       } else {
+                               Optional<Sone> sone = webInterface.getCore().getSone(id);
+                               if (!sone.isPresent()) {
+                                       continue;
+                               }
+                               webInterface.getCore().markSoneKnown(sone.get());
+                       }
+               }
+               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+               throw new RedirectException(returnPage);
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/NewPage.java b/src/main/java/net/pterodactylus/sone/web/pages/NewPage.java
new file mode 100644 (file)
index 0000000..411f40f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Sone - NewPage.java - Copyright © 2013–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.notify.PostVisibilityFilter;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+
+/**
+ * Page that displays all new posts and replies. The posts are filtered using
+ * {@link PostVisibilityFilter#isPostVisible(Sone, Post)} and sorted by time.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class NewPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “new posts and replies” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public NewPage(Template template, WebInterface webInterface) {
+               super("new.html", template, "Page.New.Title", webInterface);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               /* collect new elements from notifications. */
+               Set<Post> posts = new HashSet<Post>(webInterface.getNewPosts(getCurrentSoneWithoutCreatingSession(request.getToadletContext())));
+               for (PostReply reply : webInterface.getNewReplies(getCurrentSoneWithoutCreatingSession(request.getToadletContext()))) {
+                       posts.add(reply.getPost().get());
+               }
+
+               /* filter and sort them. */
+               List<Post> sortedPosts = new ArrayList<>(posts);
+               Collections.sort(sortedPosts, Post.NEWEST_FIRST);
+
+               /* paginate them. */
+               Pagination<Post> pagination = new Pagination<>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(parseInt(request.getHttpRequest().getParam("page"), 0));
+               templateContext.set("pagination", pagination);
+               templateContext.set("posts", pagination.getItems());
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/pages/OptionsPage.java
new file mode 100644 (file)
index 0000000..7b65c33
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * Sone - OptionsPage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.pterodactylus.sone.core.Preferences;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.SoneOptions.LoadExternalContent;
+import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+/**
+ * This page lets the user edit the options of the Sone plugin.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class OptionsPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new options page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public OptionsPage(Template template, WebInterface webInterface) {
+               super("options.html", template, "Page.Options.Title", webInterface, false);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               Preferences preferences = webInterface.getCore().getPreferences();
+               Sone currentSone = webInterface.getCurrentSoneWithoutCreatingSession(request.getToadletContext());
+               if (request.getMethod() == Method.POST) {
+                       List<String> fieldErrors = new ArrayList<String>();
+                       if (currentSone != null) {
+                               boolean autoFollow = request.getHttpRequest().isPartSet("auto-follow");
+                               currentSone.getOptions().setAutoFollow(autoFollow);
+                               boolean enableSoneInsertNotifications = request.getHttpRequest().isPartSet("enable-sone-insert-notifications");
+                               currentSone.getOptions().setSoneInsertNotificationEnabled(enableSoneInsertNotifications);
+                               boolean showNotificationNewSones = request.getHttpRequest().isPartSet("show-notification-new-sones");
+                               currentSone.getOptions().setShowNewSoneNotifications(showNotificationNewSones);
+                               boolean showNotificationNewPosts = request.getHttpRequest().isPartSet("show-notification-new-posts");
+                               currentSone.getOptions().setShowNewPostNotifications(showNotificationNewPosts);
+                               boolean showNotificationNewReplies = request.getHttpRequest().isPartSet("show-notification-new-replies");
+                               currentSone.getOptions().setShowNewReplyNotifications(showNotificationNewReplies);
+                               String showCustomAvatars = request.getHttpRequest().getPartAsStringFailsafe("show-custom-avatars", 32);
+                               currentSone.getOptions().setShowCustomAvatars(LoadExternalContent.valueOf(showCustomAvatars));
+                               String loadLinkedImages = request.getHttpRequest().getPartAsStringFailsafe("load-linked-images", 32);
+                               currentSone.getOptions().setLoadLinkedImages(LoadExternalContent.valueOf(loadLinkedImages));
+                               webInterface.getCore().touchConfiguration();
+                       }
+                       Integer insertionDelay = parseInt(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16), null);
+                       if (!preferences.validateInsertionDelay(insertionDelay)) {
+                               fieldErrors.add("insertion-delay");
+                       } else {
+                               preferences.setInsertionDelay(insertionDelay);
+                       }
+                       Integer postsPerPage = parseInt(request.getHttpRequest().getPartAsStringFailsafe("posts-per-page", 4), null);
+                       if (!preferences.validatePostsPerPage(postsPerPage)) {
+                               fieldErrors.add("posts-per-page");
+                       } else {
+                               preferences.setPostsPerPage(postsPerPage);
+                       }
+                       Integer imagesPerPage = parseInt(request.getHttpRequest().getPartAsStringFailsafe("images-per-page", 4), null);
+                       if (!preferences.validateImagesPerPage(imagesPerPage)) {
+                               fieldErrors.add("images-per-page");
+                       } else {
+                               preferences.setImagesPerPage(imagesPerPage);
+                       }
+                       Integer charactersPerPost = parseInt(request.getHttpRequest().getPartAsStringFailsafe("characters-per-post", 10), null);
+                       if (!preferences.validateCharactersPerPost(charactersPerPost)) {
+                               fieldErrors.add("characters-per-post");
+                       } else {
+                               preferences.setCharactersPerPost(charactersPerPost);
+                       }
+                       Integer postCutOffLength = parseInt(request.getHttpRequest().getPartAsStringFailsafe("post-cut-off-length", 10), null);
+                       if (!preferences.validatePostCutOffLength(postCutOffLength)) {
+                               fieldErrors.add("post-cut-off-length");
+                       } else {
+                               preferences.setPostCutOffLength(postCutOffLength);
+                       }
+                       boolean requireFullAccess = request.getHttpRequest().isPartSet("require-full-access");
+                       preferences.setRequireFullAccess(requireFullAccess);
+                       Integer positiveTrust = parseInt(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3), null);
+                       if (!preferences.validatePositiveTrust(positiveTrust)) {
+                               fieldErrors.add("positive-trust");
+                       } else {
+                               preferences.setPositiveTrust(positiveTrust);
+                       }
+                       Integer negativeTrust = parseInt(request.getHttpRequest().getPartAsStringFailsafe("negative-trust", 4), null);
+                       if (!preferences.validateNegativeTrust(negativeTrust)) {
+                               fieldErrors.add("negative-trust");
+                       } else {
+                               preferences.setNegativeTrust(negativeTrust);
+                       }
+                       String trustComment = request.getHttpRequest().getPartAsStringFailsafe("trust-comment", 256);
+                       if (trustComment.trim().length() == 0) {
+                               trustComment = null;
+                       }
+                       preferences.setTrustComment(trustComment);
+                       boolean fcpInterfaceActive = request.getHttpRequest().isPartSet("fcp-interface-active");
+                       preferences.setFcpInterfaceActive(fcpInterfaceActive);
+                       Integer fcpFullAccessRequiredInteger = parseInt(request.getHttpRequest().getPartAsStringFailsafe("fcp-full-access-required", 1), preferences.getFcpFullAccessRequired().ordinal());
+                       FullAccessRequired fcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequiredInteger];
+                       preferences.setFcpFullAccessRequired(fcpFullAccessRequired);
+                       webInterface.getCore().touchConfiguration();
+                       if (fieldErrors.isEmpty()) {
+                               throw new RedirectException(getPath());
+                       }
+                       templateContext.set("fieldErrors", fieldErrors);
+               }
+               if (currentSone != null) {
+                       templateContext.set("auto-follow", currentSone.getOptions().isAutoFollow());
+                       templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().isSoneInsertNotificationEnabled());
+                       templateContext.set("show-notification-new-sones", currentSone.getOptions().isShowNewSoneNotifications());
+                       templateContext.set("show-notification-new-posts", currentSone.getOptions().isShowNewPostNotifications());
+                       templateContext.set("show-notification-new-replies", currentSone.getOptions().isShowNewReplyNotifications());
+                       templateContext.set("show-custom-avatars", currentSone.getOptions().getShowCustomAvatars().name());
+                       templateContext.set("load-linked-images", currentSone.getOptions().getLoadLinkedImages().name());
+               }
+               templateContext.set("insertion-delay", preferences.getInsertionDelay());
+               templateContext.set("posts-per-page", preferences.getPostsPerPage());
+               templateContext.set("images-per-page", preferences.getImagesPerPage());
+               templateContext.set("characters-per-post", preferences.getCharactersPerPost());
+               templateContext.set("post-cut-off-length", preferences.getPostCutOffLength());
+               templateContext.set("require-full-access", preferences.isRequireFullAccess());
+               templateContext.set("positive-trust", preferences.getPositiveTrust());
+               templateContext.set("negative-trust", preferences.getNegativeTrust());
+               templateContext.set("trust-comment", preferences.getTrustComment());
+               templateContext.set("fcp-interface-active", preferences.isFcpInterfaceActive());
+               templateContext.set("fcp-full-access-required", preferences.getFcpFullAccessRequired().ordinal());
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/ReloadingPage.java b/src/main/java/net/pterodactylus/sone/web/pages/ReloadingPage.java
new file mode 100644 (file)
index 0000000..a36c3fd
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Sone - ReloadingPage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import net.pterodactylus.util.io.StreamCopier;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.Request;
+import net.pterodactylus.util.web.Response;
+
+/**
+ * {@link Page} implementation that delivers static files from the filesystem.
+ *
+ * @param <REQ>
+ *            The type of the request
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ReloadingPage<REQ extends Request> implements Page<REQ> {
+
+       private final String pathPrefix;
+       private final String filesystemPath;
+       private final String mimeType;
+
+       public ReloadingPage(String pathPrefix, String filesystemPathPrefix, String mimeType) {
+               this.pathPrefix = pathPrefix;
+               this.filesystemPath = filesystemPathPrefix;
+               this.mimeType = mimeType;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public String getPath() {
+               return pathPrefix;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean isPrefixPage() {
+               return true;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public Response handleRequest(REQ request, Response response) throws IOException {
+               String path = request.getUri().getPath();
+               int lastSlash = path.lastIndexOf('/');
+               String filename = path.substring(lastSlash + 1);
+               try (InputStream fileInputStream = new FileInputStream(new File(filesystemPath, filename));
+                       OutputStream contentOutputStream = response.getContent()) {
+                       StreamCopier.copy(fileInputStream, contentOutputStream);
+               } catch (FileNotFoundException fnfe1) {
+                       return response.setStatusCode(404).setStatusText("Not found.");
+               }
+               return response.setStatusCode(200).setStatusText("OK").setContentType(mimeType);
+       }
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/RescuePage.java b/src/main/java/net/pterodactylus/sone/web/pages/RescuePage.java
new file mode 100644 (file)
index 0000000..93ef9e1
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Sone - RescuePage.java - Copyright © 2011–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import static net.pterodactylus.sone.utils.NumberParsers.parseLong;
+
+import net.pterodactylus.sone.core.SoneRescuer;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+/**
+ * Page that lets the user control the rescue mode for a Sone.
+ *
+ * @see SoneRescuer
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class RescuePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new rescue page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public RescuePage(Template template, WebInterface webInterface) {
+               super("rescue.html", template, "Page.Rescue.Title", webInterface, true);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
+               SoneRescuer soneRescuer = webInterface.getCore().getSoneRescuer(currentSone);
+               if (request.getMethod() == Method.POST) {
+                       if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("fetch", 4))) {
+                               long edition = parseLong(request.getHttpRequest().getPartAsStringFailsafe("edition", 8), -1L);
+                               if (edition > -1) {
+                                       soneRescuer.setEdition(edition);
+                               }
+                               soneRescuer.startNextFetch();
+                       }
+                       throw new RedirectException("rescue.html");
+               }
+               templateContext.set("soneRescuer", soneRescuer);
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/pages/SearchPage.java
new file mode 100644 (file)
index 0000000..ed6c507
--- /dev/null
@@ -0,0 +1,659 @@
+/*
+ * Sone - SearchPage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import static com.google.common.base.Optional.fromNullable;
+import static com.google.common.primitives.Ints.tryParse;
+import static java.util.logging.Logger.getLogger;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Profile.Field;
+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.collection.Pagination;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.text.StringEscaper;
+import net.pterodactylus.util.text.TextException;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Ordering;
+
+/**
+ * This page lets the user search for posts and replies that contain certain
+ * words.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SearchPage extends SoneTemplatePage {
+
+       /** The logger. */
+       private static final Logger logger = getLogger(SearchPage.class.getName());
+
+       /** Short-term cache. */
+       private final LoadingCache<List<Phrase>, Set<Hit<Post>>> hitCache = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(new CacheLoader<List<Phrase>, Set<Hit<Post>>>() {
+
+               @Override
+               @SuppressWarnings("synthetic-access")
+               public Set<Hit<Post>> load(List<Phrase> phrases) {
+                       Set<Post> posts = new HashSet<Post>();
+                       for (Sone sone : webInterface.getCore().getSones()) {
+                               posts.addAll(sone.getPosts());
+                       }
+                       return getHits(Collections2.filter(posts, Post.FUTURE_POSTS_FILTER), phrases, new PostStringGenerator());
+               }
+       });
+
+       /**
+        * Creates a new search page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public SearchPage(Template template, WebInterface webInterface) {
+               super("search.html", template, "Page.Search.Title", webInterface);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       @SuppressWarnings("synthetic-access")
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               String query = request.getHttpRequest().getParam("query").trim();
+               if (query.length() == 0) {
+                       throw new RedirectException("index.html");
+               }
+
+               List<Phrase> phrases = parseSearchPhrases(query);
+               if (phrases.isEmpty()) {
+                       throw new RedirectException("index.html");
+               }
+
+               /* check for a couple of shortcuts. */
+               if (phrases.size() == 1) {
+                       String phrase = phrases.get(0).getPhrase();
+
+                       /* is it a Sone ID? */
+                       redirectIfNotNull(getSoneId(phrase), "viewSone.html?sone=");
+
+                       /* is it a post ID? */
+                       redirectIfNotNull(getPostId(phrase), "viewPost.html?post=");
+
+                       /* is it a reply ID? show the post. */
+                       redirectIfNotNull(getReplyPostId(phrase), "viewPost.html?post=");
+
+                       /* is it an album ID? */
+                       redirectIfNotNull(getAlbumId(phrase), "imageBrowser.html?album=");
+
+                       /* is it an image ID? */
+                       redirectIfNotNull(getImageId(phrase), "imageBrowser.html?image=");
+               }
+
+               Collection<Sone> sones = webInterface.getCore().getSones();
+               Collection<Hit<Sone>> soneHits = getHits(sones, phrases, SoneStringGenerator.COMPLETE_GENERATOR);
+
+               Collection<Hit<Post>> postHits = hitCache.getUnchecked(phrases);
+
+               /* now filter. */
+               soneHits = Collections2.filter(soneHits, Hit.POSITIVE_FILTER);
+               postHits = Collections2.filter(postHits, Hit.POSITIVE_FILTER);
+
+               /* now sort. */
+               List<Hit<Sone>> sortedSoneHits = Ordering.from(Hit.DESCENDING_COMPARATOR).sortedCopy(soneHits);
+               List<Hit<Post>> sortedPostHits = Ordering.from(Hit.DESCENDING_COMPARATOR).sortedCopy(postHits);
+
+               /* extract Sones and posts. */
+               List<Sone> resultSones = FluentIterable.from(sortedSoneHits).transform(new HitMapper<Sone>()).toList();
+               List<Post> resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper<Post>()).toList();
+
+               /* pagination. */
+               Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(fromNullable(tryParse(request.getHttpRequest().getParam("sonePage"))).or(0));
+               Pagination<Post> postPagination = new Pagination<Post>(resultPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(fromNullable(tryParse(request.getHttpRequest().getParam("postPage"))).or(0));
+
+               templateContext.set("sonePagination", sonePagination);
+               templateContext.set("soneHits", sonePagination.getItems());
+               templateContext.set("postPagination", postPagination);
+               templateContext.set("postHits", postPagination.getItems());
+       }
+
+       //
+       // PRIVATE METHODS
+       //
+
+       /**
+        * Collects hit information for the given objects. The objects are converted
+        * to a {@link String} using the given {@link StringGenerator}, and the
+        * {@link #calculateScore(List, String) calculated score} is stored together
+        * with the object in a {@link Hit}, and all resulting {@link Hit}s are then
+        * returned.
+        *
+        * @param <T>
+        *            The type of the objects
+        * @param objects
+        *            The objects to search over
+        * @param phrases
+        *            The phrases to search for
+        * @param stringGenerator
+        *            The string generator for the objects
+        * @return The hits for the given phrases
+        */
+       private static <T> Set<Hit<T>> getHits(Collection<T> objects, List<Phrase> phrases, StringGenerator<T> stringGenerator) {
+               Set<Hit<T>> hits = new HashSet<Hit<T>>();
+               for (T object : objects) {
+                       String objectString = stringGenerator.generateString(object);
+                       double score = calculateScore(phrases, objectString);
+                       hits.add(new Hit<T>(object, score));
+               }
+               return hits;
+       }
+
+       /**
+        * Parses the given query into search phrases. The query is split on
+        * whitespace while allowing to group words using single or double quotes.
+        * Isolated phrases starting with a “+” are
+        * {@link Phrase.Optionality#REQUIRED}, phrases with a “-” are
+        * {@link Phrase.Optionality#FORBIDDEN}.
+        *
+        * @param query
+        *            The query to parse
+        * @return The parsed phrases
+        */
+       private static List<Phrase> parseSearchPhrases(String query) {
+               List<String> parsedPhrases;
+               try {
+                       parsedPhrases = StringEscaper.parseLine(query);
+               } catch (TextException te1) {
+                       /* invalid query. */
+                       return Collections.emptyList();
+               }
+
+               List<Phrase> phrases = new ArrayList<Phrase>();
+               for (String phrase : parsedPhrases) {
+                       if (phrase.startsWith("+")) {
+                               if (phrase.length() > 1) {
+                                       phrases.add(new Phrase(phrase.substring(1), Phrase.Optionality.REQUIRED));
+                               } else {
+                                       phrases.add(new Phrase("+", Phrase.Optionality.OPTIONAL));
+                               }
+                       } else if (phrase.startsWith("-")) {
+                               if (phrase.length() > 1) {
+                                       phrases.add(new Phrase(phrase.substring(1), Phrase.Optionality.FORBIDDEN));
+                               } else {
+                                       phrases.add(new Phrase("-", Phrase.Optionality.OPTIONAL));
+                               }
+                       } else {
+                               phrases.add(new Phrase(phrase, Phrase.Optionality.OPTIONAL));
+                       }
+               }
+               return phrases;
+       }
+
+       /**
+        * Calculates the score for the given expression when using the given
+        * phrases.
+        *
+        * @param phrases
+        *            The phrases to search for
+        * @param expression
+        *            The expression to search
+        * @return The score of the expression
+        */
+       private static double calculateScore(List<Phrase> phrases, String expression) {
+               logger.log(Level.FINEST, String.format("Calculating Score for “%s”…", expression));
+               double optionalHits = 0;
+               double requiredHits = 0;
+               int forbiddenHits = 0;
+               int requiredPhrases = 0;
+               for (Phrase phrase : phrases) {
+                       String phraseString = phrase.getPhrase().toLowerCase();
+                       if (phrase.getOptionality() == Phrase.Optionality.REQUIRED) {
+                               ++requiredPhrases;
+                       }
+                       int matches = 0;
+                       int index = 0;
+                       double score = 0;
+                       while (index < expression.length()) {
+                               int position = expression.toLowerCase().indexOf(phraseString, index);
+                               if (position == -1) {
+                                       break;
+                               }
+                               score += Math.pow(1 - position / (double) expression.length(), 2);
+                               index = position + phraseString.length();
+                               logger.log(Level.FINEST, String.format("Got hit at position %d.", position));
+                               ++matches;
+                       }
+                       logger.log(Level.FINEST, String.format("Score: %f", score));
+                       if (matches == 0) {
+                               continue;
+                       }
+                       if (phrase.getOptionality() == Phrase.Optionality.REQUIRED) {
+                               requiredHits += score;
+                       }
+                       if (phrase.getOptionality() == Phrase.Optionality.OPTIONAL) {
+                               optionalHits += score;
+                       }
+                       if (phrase.getOptionality() == Phrase.Optionality.FORBIDDEN) {
+                               forbiddenHits += matches;
+                       }
+               }
+               return requiredHits * 3 + optionalHits + (requiredHits - requiredPhrases) * 5 - (forbiddenHits * 2);
+       }
+
+       /**
+        * Throws a
+        * {@link net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException}
+        * if the given object is not {@code null}, appending the object to the
+        * given target URL.
+        *
+        * @param object
+        *            The object on which to redirect
+        * @param target
+        *            The target of the redirect
+        * @throws RedirectException
+        *             if {@code object} is not {@code null}
+        */
+       private static void redirectIfNotNull(String object, String target) throws RedirectException {
+               if (object != null) {
+                       throw new RedirectException(target + object);
+               }
+       }
+
+       /**
+        * If the given phrase contains a Sone ID (optionally prefixed by
+        * “sone://”), returns said Sone ID, otherwise return {@code null}.
+        *
+        * @param phrase
+        *            The phrase that maybe is a Sone ID
+        * @return The Sone ID, or {@code null}
+        */
+       private String getSoneId(String phrase) {
+               String soneId = phrase.startsWith("sone://") ? phrase.substring(7) : phrase;
+               return (webInterface.getCore().getSone(soneId).isPresent()) ? soneId : null;
+       }
+
+       /**
+        * If the given phrase contains a post ID (optionally prefixed by
+        * “post://”), returns said post ID, otherwise return {@code null}.
+        *
+        * @param phrase
+        *            The phrase that maybe is a post ID
+        * @return The post ID, or {@code null}
+        */
+       private String getPostId(String phrase) {
+               String postId = phrase.startsWith("post://") ? phrase.substring(7) : phrase;
+               return (webInterface.getCore().getPost(postId).isPresent()) ? postId : null;
+       }
+
+       /**
+        * If the given phrase contains a reply ID (optionally prefixed by
+        * “reply://”), returns the ID of the post the reply belongs to, otherwise
+        * return {@code null}.
+        *
+        * @param phrase
+        *            The phrase that maybe is a reply ID
+        * @return The reply’s post ID, or {@code null}
+        */
+       private String getReplyPostId(String phrase) {
+               String replyId = phrase.startsWith("reply://") ? phrase.substring(8) : phrase;
+               Optional<PostReply> postReply = webInterface.getCore().getPostReply(replyId);
+               if (!postReply.isPresent()) {
+                       return null;
+               }
+               return postReply.get().getPostId();
+       }
+
+       /**
+        * If the given phrase contains an album ID (optionally prefixed by
+        * “album://”), returns said album ID, otherwise return {@code null}.
+        *
+        * @param phrase
+        *            The phrase that maybe is an album ID
+        * @return The album ID, or {@code null}
+        */
+       private String getAlbumId(String phrase) {
+               String albumId = phrase.startsWith("album://") ? phrase.substring(8) : phrase;
+               return (webInterface.getCore().getAlbum(albumId) != null) ? albumId : null;
+       }
+
+       /**
+        * If the given phrase contains an image ID (optionally prefixed by
+        * “image://”), returns said image ID, otherwise return {@code null}.
+        *
+        * @param phrase
+        *            The phrase that maybe is an image ID
+        * @return The image ID, or {@code null}
+        */
+       private String getImageId(String phrase) {
+               String imageId = phrase.startsWith("image://") ? phrase.substring(8) : phrase;
+               return (webInterface.getCore().getImage(imageId, false) != null) ? imageId : null;
+       }
+
+       /**
+        * Converts a given object into a {@link String}.
+        *
+        * @param <T>
+        *            The type of the objects
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private static interface StringGenerator<T> {
+
+               /**
+                * Generates a {@link String} for the given object.
+                *
+                * @param object
+                *            The object to generate the {@link String} for
+                * @return The generated {@link String}
+                */
+               public String generateString(T object);
+
+       }
+
+       /**
+        * Generates a {@link String} from a {@link Sone}, concatenating the name of
+        * the Sone and all {@link Profile} {@link Field} values.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private static class SoneStringGenerator implements StringGenerator<Sone> {
+
+               /** A static instance of a complete Sone string generator. */
+               public static final SoneStringGenerator COMPLETE_GENERATOR = new SoneStringGenerator(true);
+
+               /**
+                * A static instance of a Sone string generator that will only use the
+                * name of the Sone.
+                */
+               public static final SoneStringGenerator NAME_GENERATOR = new SoneStringGenerator(false);
+
+               /** Whether to generate a string from all data of a Sone. */
+               private final boolean complete;
+
+               /**
+                * Creates a new Sone string generator.
+                *
+                * @param complete
+                *            {@code true} to use the profile’s fields, {@code false} to
+                *            not to use the profile‘s fields
+                */
+               private SoneStringGenerator(boolean complete) {
+                       this.complete = complete;
+               }
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public String generateString(Sone sone) {
+                       StringBuilder soneString = new StringBuilder();
+                       soneString.append(sone.getName());
+                       Profile soneProfile = sone.getProfile();
+                       if (soneProfile.getFirstName() != null) {
+                               soneString.append(' ').append(soneProfile.getFirstName());
+                       }
+                       if (soneProfile.getMiddleName() != null) {
+                               soneString.append(' ').append(soneProfile.getMiddleName());
+                       }
+                       if (soneProfile.getLastName() != null) {
+                               soneString.append(' ').append(soneProfile.getLastName());
+                       }
+                       if (complete) {
+                               for (Field field : soneProfile.getFields()) {
+                                       soneString.append(' ').append(field.getValue());
+                               }
+                       }
+                       return soneString.toString();
+               }
+
+       }
+
+       /**
+        * Generates a {@link String} from a {@link Post}, concatenating the text of
+        * the post, the text of all {@link Reply}s, and the name of all
+        * {@link Sone}s that have replied.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private class PostStringGenerator implements StringGenerator<Post> {
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public String generateString(Post post) {
+                       StringBuilder postString = new StringBuilder();
+                       postString.append(post.getText());
+                       if (post.getRecipient().isPresent()) {
+                               postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(post.getRecipient().get()));
+                       }
+                       for (PostReply reply : Collections2.filter(webInterface.getCore().getReplies(post.getId()), Reply.FUTURE_REPLY_FILTER)) {
+                               postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(reply.getSone()));
+                               postString.append(' ').append(reply.getText());
+                       }
+                       return postString.toString();
+               }
+
+       }
+
+       /**
+        * A search phrase.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private static class Phrase {
+
+               /**
+                * The optionality of a search phrase.
+                *
+                * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’
+                *         Roden</a>
+                */
+               public enum Optionality {
+
+                       /** The phrase is optional. */
+                       OPTIONAL,
+
+                       /** The phrase is required. */
+                       REQUIRED,
+
+                       /** The phrase is forbidden. */
+                       FORBIDDEN
+
+               }
+
+               /** The phrase to search for. */
+               private final String phrase;
+
+               /** The optionality of the phrase. */
+               private final Optionality optionality;
+
+               /**
+                * Creates a new phrase.
+                *
+                * @param phrase
+                *            The phrase to search for
+                * @param optionality
+                *            The optionality of the phrase
+                */
+               public Phrase(String phrase, Optionality optionality) {
+                       this.optionality = optionality;
+                       this.phrase = phrase;
+               }
+
+               /**
+                * Returns the phrase to search for.
+                *
+                * @return The phrase to search for
+                */
+               public String getPhrase() {
+                       return phrase;
+               }
+
+               /**
+                * Returns the optionality of the phrase.
+                *
+                * @return The optionality of the phrase
+                */
+               public Optionality getOptionality() {
+                       return optionality;
+               }
+
+               //
+               // OBJECT METHODS
+               //
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public int hashCode() {
+                       return phrase.hashCode() ^ ((optionality == Optionality.FORBIDDEN) ? (0xaaaaaaaa) : ((optionality == Optionality.REQUIRED) ? 0x55555555 : 0));
+               }
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public boolean equals(Object object) {
+                       if (!(object instanceof Phrase)) {
+                               return false;
+                       }
+                       Phrase phrase = (Phrase) object;
+                       return (this.optionality == phrase.optionality) && this.phrase.equals(phrase.phrase);
+               }
+
+       }
+
+       /**
+        * A hit consists of a searched object and the score it got for the phrases
+        * of the search.
+        *
+        * @see SearchPage#calculateScore(List, String)
+        * @param <T>
+        *            The type of the searched object
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private static class Hit<T> {
+
+               /** Filter for {@link Hit}s with a score of more than 0. */
+               public static final Predicate<Hit<?>> POSITIVE_FILTER = new Predicate<Hit<?>>() {
+
+                       @Override
+                       public boolean apply(Hit<?> hit) {
+                               return (hit != null) && (hit.getScore() > 0);
+                       }
+
+               };
+
+               /** Comparator that sorts {@link Hit}s descending by score. */
+               public static final Comparator<Hit<?>> DESCENDING_COMPARATOR = new Comparator<Hit<?>>() {
+
+                       @Override
+                       public int compare(Hit<?> leftHit, Hit<?> rightHit) {
+                               return Double.compare(rightHit.getScore(), leftHit.getScore());
+                       }
+
+               };
+
+               /** The object that was searched. */
+               private final T object;
+
+               /** The score of the object. */
+               private final double score;
+
+               /**
+                * Creates a new hit.
+                *
+                * @param object
+                *            The object that was searched
+                * @param score
+                *            The score of the object
+                */
+               public Hit(T object, double score) {
+                       this.object = object;
+                       this.score = score;
+               }
+
+               /**
+                * Returns the object that was searched.
+                *
+                * @return The object that was searched
+                */
+               public T getObject() {
+                       return object;
+               }
+
+               /**
+                * Returns the score of the object.
+                *
+                * @return The score of the object
+                */
+               public double getScore() {
+                       return score;
+               }
+
+       }
+
+       /**
+        * Extracts the object from a {@link Hit}.
+        *
+        * @param <T>
+        *            The type of the object to extract
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private static class HitMapper<T> implements Function<Hit<T>, T> {
+
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public T apply(Hit<T> input) {
+                       return input.getObject();
+               }
+
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/pages/SoneTemplatePage.java
new file mode 100644 (file)
index 0000000..46c8318
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+ * Sone - SoneTemplatePage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.main.SonePlugin;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.sone.web.page.FreenetTemplatePage;
+import net.pterodactylus.util.notify.Notification;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+
+import freenet.clients.http.SessionManager.Session;
+import freenet.clients.http.ToadletContext;
+import freenet.support.api.HTTPRequest;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Base page for the Sone web interface.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SoneTemplatePage extends FreenetTemplatePage {
+
+       /** The Sone core. */
+       protected final WebInterface webInterface;
+
+       /** The page title l10n key. */
+       private final String pageTitleKey;
+
+       /** Whether to require a login. */
+       private final boolean requireLogin;
+
+       /**
+        * Creates a new template page for Sone that does not require the user to be
+        * logged in.
+        *
+        * @param path
+        *            The path of the page
+        * @param template
+        *            The template to render
+        * @param pageTitleKey
+        *            The l10n key of the page title
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public SoneTemplatePage(String path, Template template, String pageTitleKey, WebInterface webInterface) {
+               this(path, template, pageTitleKey, webInterface, false);
+       }
+
+       /**
+        * Creates a new template page for Sone.
+        *
+        * @param path
+        *            The path of the page
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        * @param requireLogin
+        *            Whether this page requires a login
+        */
+       public SoneTemplatePage(String path, Template template, WebInterface webInterface, boolean requireLogin) {
+               this(path, template, null, webInterface, requireLogin);
+       }
+
+       /**
+        * Creates a new template page for Sone.
+        *
+        * @param path
+        *            The path of the page
+        * @param template
+        *            The template to render
+        * @param pageTitleKey
+        *            The l10n key of the page title
+        * @param webInterface
+        *            The Sone web interface
+        * @param requireLogin
+        *            Whether this page requires a login
+        */
+       public SoneTemplatePage(String path, Template template, String pageTitleKey, WebInterface webInterface, boolean requireLogin) {
+               super(path, webInterface.getTemplateContextFactory(), template, "noPermission.html");
+               this.pageTitleKey = pageTitleKey;
+               this.webInterface = webInterface;
+               this.requireLogin = requireLogin;
+       }
+
+       //
+       // PROTECTED METHODS
+       //
+
+       /**
+        * Returns the currently logged in Sone.
+        *
+        * @param toadletContext
+        *            The toadlet context
+        * @return The currently logged in Sone, or {@code null} if no Sone is
+        *         currently logged in
+        */
+       protected Sone getCurrentSone(ToadletContext toadletContext) {
+               return webInterface.getCurrentSoneCreatingSession(toadletContext);
+       }
+
+       protected Sone getCurrentSoneWithoutCreatingSession(ToadletContext toadletContext) {
+               return webInterface.getCurrentSoneWithoutCreatingSession(toadletContext);
+       }
+
+       /**
+        * Sets the currently logged in Sone.
+        *
+        * @param toadletContext
+        *            The toadlet context
+        * @param sone
+        *            The Sone to set as currently logged in
+        */
+       protected void setCurrentSone(ToadletContext toadletContext, Sone sone) {
+               webInterface.setCurrentSone(toadletContext, sone);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected String getPageTitle(FreenetRequest request) {
+               if (pageTitleKey != null) {
+                       return webInterface.getL10n().getString(pageTitleKey);
+               }
+               return "";
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected List<Map<String, String>> getAdditionalLinkNodes(FreenetRequest request) {
+               return ImmutableList.<Map<String, String>> builder().add(ImmutableMap.<String, String> builder().put("rel", "search").put("type", "application/opensearchdescription+xml").put("title", "Sone").put("href", "http://" + request.getHttpRequest().getHeader("host") + "/Sone/OpenSearch.xml").build()).build();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected Collection<String> getStyleSheets() {
+               return Arrays.asList("css/sone.css");
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected String getShortcutIcon() {
+               return "images/icon.png";
+       }
+
+       /**
+        * Returns whether this page requires the user to log in.
+        *
+        * @return {@code true} if the user is required to be logged in to use this
+        *         page, {@code false} otherwise
+        */
+       protected boolean requiresLogin() {
+               return requireLogin;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected final void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               super.processTemplate(request, templateContext);
+               Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
+               templateContext.set("preferences", webInterface.getCore().getPreferences());
+               templateContext.set("currentSone", currentSone);
+               templateContext.set("localSones", webInterface.getCore().getLocalSones());
+               templateContext.set("request", request);
+               templateContext.set("currentVersion", SonePlugin.getPluginVersion());
+               templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
+               templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition());
+               templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
+               templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
+               List<Notification> notifications = new ArrayList<Notification>(webInterface.getNotifications(currentSone));
+               Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
+               templateContext.set("notifications", notifications);
+               templateContext.set("notificationHash", notifications.hashCode());
+               handleRequest(request, templateContext);
+       }
+
+       protected void handleRequest(@Nonnull FreenetRequest request, @Nonnull TemplateContext templateContext) throws RedirectException {
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected String getRedirectTarget(FreenetRequest request) {
+               if (requiresLogin() && (getCurrentSoneWithoutCreatingSession(request.getToadletContext()) == null)) {
+                       HTTPRequest httpRequest = request.getHttpRequest();
+                       String originalUrl = httpRequest.getPath();
+                       if (httpRequest.hasParameters()) {
+                               StringBuilder requestParameters = new StringBuilder();
+                               for (String parameterName : httpRequest.getParameterNames()) {
+                                       if (requestParameters.length() > 0) {
+                                               requestParameters.append("&");
+                                       }
+                                       String[] parameterValues = httpRequest.getMultipleParam(parameterName);
+                                       for (String parameterValue : parameterValues) {
+                                               requestParameters.append(urlEncode(parameterName)).append("=").append(urlEncode(parameterValue));
+                                       }
+                               }
+                               originalUrl += "?" + requestParameters.toString();
+                       }
+                       return "login.html?target=" + urlEncode(originalUrl);
+               }
+               return null;
+       }
+
+       private static String urlEncode(String value) {
+               try {
+                       return URLEncoder.encode(value, "UTF-8");
+               } catch (UnsupportedEncodingException uee1) {
+                                                       /* A JVM without UTF-8? I don’t think so. */
+                       throw new RuntimeException(uee1);
+               }
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected boolean isFullAccessOnly() {
+               return webInterface.getCore().getPreferences().isRequireFullAccess();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean isEnabled(ToadletContext toadletContext) {
+               if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
+                       return false;
+               }
+               if (requiresLogin()) {
+                       return getCurrentSoneWithoutCreatingSession(toadletContext) != null;
+               }
+               return true;
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/TrustPage.java b/src/main/java/net/pterodactylus/sone/web/pages/TrustPage.java
new file mode 100644 (file)
index 0000000..55929d7
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Sone - TrustPage.java - Copyright © 2011–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import com.google.common.base.Optional;
+
+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.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+/**
+ * Page that lets the user trust another Sone. This will assign a configurable
+ * amount of trust to an identity.
+ *
+ * @see Core#trustSone(Sone, Sone)
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class TrustPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “trust Sone” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public TrustPage(Template template, WebInterface webInterface) {
+               super("trust.html", template, "Page.Trust.Title", webInterface, true);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               if (request.getMethod() == Method.POST) {
+                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+                       String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
+                       Sone currentSone = getCurrentSone(request.getToadletContext());
+                       Optional<Sone> sone = webInterface.getCore().getSone(identity);
+                       if (sone.isPresent()) {
+                               webInterface.getCore().trustSone(currentSone, sone.get());
+                       }
+                       throw new RedirectException(returnPage);
+               }
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/UnbookmarkPage.java b/src/main/java/net/pterodactylus/sone/web/pages/UnbookmarkPage.java
new file mode 100644 (file)
index 0000000..6fa037f
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Sone - UnbookmarkPage.java - Copyright © 2011–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import java.util.Set;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+import com.google.common.base.Optional;
+
+/**
+ * Page that lets the user unbookmark a post.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class UnbookmarkPage extends SoneTemplatePage {
+
+       /**
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public UnbookmarkPage(Template template, WebInterface webInterface) {
+               super("unbookmark.html", template, "Page.Unbookmark.Title", webInterface);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               if (request.getMethod() == Method.POST) {
+                       String id = request.getHttpRequest().getPartAsStringFailsafe("post", 36);
+                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+                       Optional<Post> post = webInterface.getCore().getPost(id);
+                       if (post.isPresent()) {
+                               webInterface.getCore().unbookmarkPost(post.get());
+                       }
+                       throw new RedirectException(returnPage);
+               }
+               String id = request.getHttpRequest().getParam("post");
+               if (id.equals("allNotLoaded")) {
+                       Set<Post> posts = webInterface.getCore().getBookmarkedPosts();
+                       for (Post post : posts) {
+                               if (!post.isLoaded()) {
+                                       webInterface.getCore().unbookmarkPost(post);
+                               }
+                       }
+                       throw new RedirectException("bookmarks.html");
+               }
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/UnfollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/pages/UnfollowSonePage.java
new file mode 100644 (file)
index 0000000..ec377e2
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Sone - UnfollowSonePage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages;
+
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+
+/**
+ * This page lets the user unfollow another Sone.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class UnfollowSonePage extends SoneTemplatePage {
+
+       /**
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public UnfollowSonePage(Template template, WebInterface webInterface) {
+               super("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, true);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               if (request.getMethod() == Method.POST) {
+                       String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
+                       Sone currentSone = getCurrentSone(request.getToadletContext());
+                       String soneIds = request.getHttpRequest().getPartAsStringFailsafe("sone", 2000);
+                       for (String soneId : soneIds.split("[ ,]+")) {
+                               webInterface.getCore().unfollowSone(currentSone, soneId);
+                       }
+                       throw new RedirectException(returnPage);
+               }
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/pages/UnlikePage.java b/src/main/java/net/pterodactylus/sone/web/pages/UnlikePage.java
new file mode 100644 (file)
index 0000000..9e61c4f
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Sone - UnlikePage.java - Copyright © 2010–2016 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied&nb