2 * Sone - ImportSonePage.java - Copyright © 2010 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.web;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
25 import net.pterodactylus.sone.data.Sone;
26 import net.pterodactylus.sone.web.page.Page.Request.Method;
27 import net.pterodactylus.util.logging.Logging;
28 import net.pterodactylus.util.template.Template;
29 import freenet.support.api.Bucket;
30 import freenet.support.io.Closer;
33 * The “import Sone” page lets the user import a Sone from a previous backup.
35 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
37 public class ImportSonePage extends SoneTemplatePage {
40 private static final Logger logger = Logging.getLogger(ImportSonePage.class);
43 * Creates a new “import Sone” page.
46 * The template to render
48 * The Sone web interface
50 public ImportSonePage(Template template, WebInterface webInterface) {
51 super("importSone.html", template, "Page.ImportSone.Title", webInterface, false);
55 // TEMPLATEPAGE METHODS
62 protected void processTemplate(net.pterodactylus.sone.web.page.Page.Request request, Template template) throws RedirectException {
63 super.processTemplate(request, template);
64 template.set("errorParsingSone", false);
65 if (request.getMethod() == Method.POST) {
66 Bucket soneBucket = request.getHttpRequest().getPart("sone-file");
67 InputStream soneInputStream = null;
69 soneInputStream = soneBucket.getInputStream();
70 Sone sone = webInterface.core().loadSone(soneInputStream);
72 throw new RedirectException("viewSone.html?sone=" + sone.getId());
74 } catch (IOException ioe1) {
75 logger.log(Level.INFO, "Could not load sone from posted XML file.", ioe1);
77 Closer.close(soneInputStream);
80 template.set("errorParsingSone", true);