X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FRescuePage.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FRescuePage.java;h=40b03f122a3b9728aa3af55ac0a8824eb44925e6;hb=bb2c8cb2d47a77bcef2d299ad4bf8e16f22a6198;hp=0000000000000000000000000000000000000000;hpb=3c7c28dad396ea710bec838550ffd54718d7999a;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/RescuePage.java b/src/main/java/net/pterodactylus/sone/web/RescuePage.java new file mode 100644 index 0000000..40b03f1 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/RescuePage.java @@ -0,0 +1,72 @@ +/* + * Sone - RescuePage.java - Copyright © 2011 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 net.pterodactylus.sone.core.SoneRescuer; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.number.Numbers; +import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; + +/** + * Page that lets the user control the rescue mode for a Sone. + * + * @see SoneRescuer + * @author David ‘Bombe’ Roden + */ +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 processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); + Sone currentSone = getCurrentSone(request.getToadletContext(), false); + SoneRescuer soneRescuer = webInterface.getCore().getSoneRescuer(currentSone); + if (request.getMethod() == Method.POST) { + if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("fetch", 4))) { + long edition = Numbers.safeParseLong(request.getHttpRequest().getPartAsStringFailsafe("edition", 8), -1L); + if (edition > -1) { + soneRescuer.setEdition(edition); + } + soneRescuer.startNextFetch(); + } + throw new RedirectException("rescue.html"); + } + templateContext.set("soneRescuer", soneRescuer); + } + +}