From 3d0dbd535f8efee946c17454a22bd24d954946d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 18 Oct 2010 13:26:49 +0200 Subject: [PATCH] Add profile backup function. --- .../pterodactylus/sone/web/BackupProfilePage.java | 78 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 4 ++ src/main/resources/i18n/sone.en.properties | 5 ++ src/main/resources/templates/backup.xml | 8 +++ src/main/resources/templates/editProfile.html | 9 +++ 5 files changed, 104 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sone/web/BackupProfilePage.java create mode 100644 src/main/resources/templates/backup.xml diff --git a/src/main/java/net/pterodactylus/sone/web/BackupProfilePage.java b/src/main/java/net/pterodactylus/sone/web/BackupProfilePage.java new file mode 100644 index 0000000..c39bd8a --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/BackupProfilePage.java @@ -0,0 +1,78 @@ +/* + * Sone - BackupProfilePage.java - Copyright © 2010 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 . + */ + +package net.pterodactylus.sone.web; + +import java.io.StringWriter; + +import net.pterodactylus.util.io.Closer; +import net.pterodactylus.util.template.Template; + +/** + * This page lets the user store a backup file containing the settings of the + * logged in Sone. + * + * @author David ‘Bombe’ Roden + */ +public class BackupProfilePage extends SoneTemplatePage { + + /** + * Creates a new “backup profile” page. + * + * @param template + * The template to render + * @param webInterface + * The Sone web interface + */ + public BackupProfilePage(Template template, WebInterface webInterface) { + super("backupProfile.html", template, "Page.BackupProfile.Title", webInterface); + } + + // + // TEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public Response handleRequest(Request request) { + StringWriter stringWriter = new StringWriter(); + try { + template.render(stringWriter); + } finally { + Closer.close(stringWriter); + } + + Response response = new Response(200, "OK", "text/xml; charset=utf-8", stringWriter.toString()); + response.setHeader("Content-Disposition", "attachment; filename=Sone_" + getCurrentSone(request.getToadletContext()).getName() + ".xml"); + return response; + } + + // + // SONETEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected boolean requiresLogin() { + return true; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index b2fc56b..b443ce7 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -179,6 +179,9 @@ public class WebInterface extends AbstractService { Template editProfileTemplate = templateFactory.createTemplate(createReader("/templates/editProfile.html")); editProfileTemplate.set("formPassword", formPassword); + Template backupProfileTemplate = templateFactory.createTemplate(createReader("/templates/backup.xml")); + backupProfileTemplate.set("formPassword", formPassword); + Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html")); viewSoneTemplate.set("formPassword", formPassword); @@ -204,6 +207,7 @@ public class WebInterface extends AbstractService { pageToadlets.add(pageToadletFactory.createPageToadlet(new AddSonePage(addSoneTemplate, this), "AddSone")); pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones")); pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile")); + pageToadlets.add(pageToadletFactory.createPageToadlet(new BackupProfilePage(backupProfileTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this))); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 3b1413b..adf9c7e 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -76,6 +76,11 @@ Page.EditProfile.Label.MiddleName=Middle name(s): Page.EditProfile.Label.LastName=Last name: Page.EditProfile.Page.Status.Changed=Your changes have been saved and will be inserted shortly. Page.EditProfile.Button.Save=Save Profile +Page.EditProfile.Backup.Title=Backup +Page.EditProfile.Backup.Description=Various unforeseen events can make it necessary to install a clean version of Sone. With a profile backup you can restore your Sone at a later point from any installation of Sone and by downloading all your posts and replies from Freenet again. +Page.EditProfile.Backup.Button.DownloadBackup=Download Backup + +Page.BackupProfile.Title=Backup Profile - Sone Page.CreatePost.Title=Create Post - Sone Page.CreatePost.Page.Title=Create Post diff --git a/src/main/resources/templates/backup.xml b/src/main/resources/templates/backup.xml new file mode 100644 index 0000000..7e04792 --- /dev/null +++ b/src/main/resources/templates/backup.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/main/resources/templates/editProfile.html b/src/main/resources/templates/editProfile.html index a15d6db..a1d80d2 100644 --- a/src/main/resources/templates/editProfile.html +++ b/src/main/resources/templates/editProfile.html @@ -33,4 +33,13 @@ +

<%= Page.EditProfile.Backup.Title|l10n|html>

+ +
<%= Page.EditProfile.Backup.Description|l10n|html>
+ +
+ + +
+ -- 2.7.4