From: David ‘Bombe’ Roden Date: Wed, 12 Jan 2011 12:02:23 +0000 (+0100) Subject: Load and save profile fields. X-Git-Tag: 0.4^2~9^2~41 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=110f9baa87db5758cc6fee3951d8096f569e6166;p=Sone.git Load and save profile fields. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 78df9ef..7cbce1b 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -1033,6 +1034,22 @@ public class Core implements IdentityListener, UpdateListener { profile.setBirthMonth(configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null)); profile.setBirthYear(configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null)); + /* load profile fields. */ + while (true) { + String fieldPrefix = sonePrefix + "/Profile/Fields/" + profile.getFieldNames().size(); + String fieldName = configuration.getStringValue(fieldPrefix + "/Name").getValue(null); + if (fieldName == null) { + break; + } + String fieldValue = configuration.getStringValue(fieldPrefix + "/Value").getValue(null); + if (fieldValue == null) { + logger.log(Level.WARNING, "Invalid profile field found, aborting load!"); + return; + } + profile.addField(fieldName); + profile.setField(fieldName, fieldValue); + } + /* load posts. */ Set posts = new HashSet(); while (true) { @@ -1165,6 +1182,15 @@ public class Core implements IdentityListener, UpdateListener { configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth()); configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear()); + /* save profile fields. */ + int fieldCounter = 0; + for (Entry profileField : profile.getFields().entrySet()) { + String fieldPrefix = sonePrefix + "/Profile/Fields/" + fieldCounter++; + configuration.getStringValue(fieldPrefix + "/Name").setValue(profileField.getKey()); + configuration.getStringValue(fieldPrefix + "/Value").setValue(profileField.getValue()); + } + configuration.getStringValue(sonePrefix + "/Profile/Fields/" + fieldCounter + "/Name").setValue(null); + /* save posts. */ int postCounter = 0; for (Post post : sone.getPosts()) {