From: David ‘Bombe’ Roden Date: Wed, 12 Jan 2011 13:39:49 +0000 (+0100) Subject: Parse profile fields from inserted Sone. X-Git-Tag: 0.4^2~9^2~37 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d0df7ca3e6bf932312fbdffdc72ecc6708c2094e;p=Sone.git Parse profile fields from inserted Sone. --- diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 4328f02..9b80438 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -310,6 +310,26 @@ public class SoneDownloader extends AbstractService { Profile profile = new Profile().setFirstName(profileFirstName).setMiddleName(profileMiddleName).setLastName(profileLastName); profile.setBirthDay(profileBirthDay).setBirthMonth(profileBirthMonth).setBirthYear(profileBirthYear); + /* parse profile fields. */ + SimpleXML profileFieldsXml = profileXml.getNode("fields"); + if (profileFieldsXml != null) { + for (SimpleXML fieldXml : profileFieldsXml.getNodes("field")) { + String fieldName = fieldXml.getValue("field-name", null); + String fieldValue = fieldXml.getValue("field-value", null); + if ((fieldName == null) || (fieldValue == null)) { + logger.log(Level.WARNING, "Downloaded profile field for Sone %s with missing data! Name: %s, Value: %s", new Object[] { sone, fieldName, fieldValue }); + return null; + } + try { + profile.addField(fieldName); + } catch (IllegalArgumentException iae1) { + logger.log(Level.WARNING, "Duplicate field: " + fieldName, iae1); + return null; + } + profile.setField(fieldName, fieldValue); + } + } + /* parse posts. */ SimpleXML postsXml = soneXml.getNode("posts"); Set posts = new HashSet();