Add profile backup function.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 18 Oct 2010 11:26:49 +0000 (13:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 18 Oct 2010 11:26:49 +0000 (13:26 +0200)
src/main/java/net/pterodactylus/sone/web/BackupProfilePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/backup.xml [new file with mode: 0644]
src/main/resources/templates/editProfile.html

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 (file)
index 0000000..c39bd8a
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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;
+       }
+
+}
index b2fc56b..b443ce7 100644 (file)
@@ -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)));
index 3b1413b..adf9c7e 100644 (file)
@@ -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 (file)
index 0000000..7e04792
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<sone>
+
+       <name></name>
+       <requestUri></requestUri>
+       <insertUri></insertUri>
+
+</sone>
index a15d6db..a1d80d2 100644 (file)
 
        </form>
 
+       <h1><%= Page.EditProfile.Backup.Title|l10n|html></h1>
+
+       <div><%= Page.EditProfile.Backup.Description|l10n|html></div>
+
+       <form action="backupProfile.html" method="post">
+               <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+               <button type="submit"><%= Page.EditProfile.Backup.Button.DownloadBackup|l10n|html></button>
+       </form>
+
 </div>