X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FEditProfileFieldPage.java;h=a71abdc013b84dcc2d1704fd9b94336e78184e09;hb=0a4b6fc252003c71f4bdef09560e87982838d9c8;hp=9958a2d856a4ddd410554b80a3b128b000537af0;hpb=480691a26222e035e53bda56029524e160fdf898;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 9958a2d..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–2012 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 @@ -25,6 +25,8 @@ 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. * @@ -48,9 +50,6 @@ public class EditProfileFieldPage extends SoneTemplatePage { // SONETEMPLATEPAGE METHODS // - /** - * {@inheritDoc} - */ @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); @@ -59,8 +58,8 @@ public class EditProfileFieldPage extends SoneTemplatePage { /* 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"); } @@ -71,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"); } @@ -85,7 +84,7 @@ public class EditProfileFieldPage extends SoneTemplatePage { } /* store current values in template. */ - templateContext.set("field", field); + templateContext.set("field", field.get()); } }