From d0df7ca3e6bf932312fbdffdc72ecc6708c2094e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 12 Jan 2011 14:39:49 +0100 Subject: [PATCH] Parse profile fields from inserted Sone. --- .../net/pterodactylus/sone/core/SoneDownloader.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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(); -- 2.7.4