X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FEditProfileFieldPage.java;h=a71abdc013b84dcc2d1704fd9b94336e78184e09;hb=2e03e9dddbea4b81aacaf1aa316f5c3ccffd4bf9;hp=219bdc52253962c087e691bc9856981d4414975e;hpb=9e4db46b86d084eba9029906e779ec1d96f78ac4;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java index 219bdc5..a71abdc 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java @@ -1,5 +1,5 @@ /* - * Sone - EditProfileFieldPage.java - Copyright © 2011 David Roden + * Sone - EditProfileFieldPage.java - Copyright © 2011–2013 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 @@ -20,9 +20,12 @@ 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.Page.Request.Method; +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 edit the name of a profile field. @@ -47,19 +50,16 @@ public class EditProfileFieldPage extends SoneTemplatePage { // SONETEMPLATEPAGE METHODS // - /** - * {@inheritDoc} - */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); 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) { + Optional field = profile.getFieldById(fieldId); + if (!field.isPresent()) { throw new RedirectException("invalid.html"); } @@ -70,13 +70,13 @@ public class EditProfileFieldPage extends SoneTemplatePage { } fieldId = request.getHttpRequest().getPartAsStringFailsafe("field", 36); field = profile.getFieldById(fieldId); - if (field == null) { + if (!field.isPresent()) { throw new RedirectException("invalid.html"); } String name = request.getHttpRequest().getPartAsStringFailsafe("name", 256); - Field existingField = profile.getFieldByName(name); - if ((existingField == null) || (existingField.equals(field))) { - field.setName(name); + Optional existingField = profile.getFieldByName(name); + if (!existingField.isPresent() || existingField.equals(field)) { + profile.renameField(field.get(), name); currentSone.setProfile(profile); throw new RedirectException("editProfile.html#profile-fields"); } @@ -84,7 +84,7 @@ public class EditProfileFieldPage extends SoneTemplatePage { } /* store current values in template. */ - templateContext.set("field", field); + templateContext.set("field", field.get()); } }