Parse avatar ID from downloaded Sone.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneDownloader.java
index 014e252..d8b924f 100644 (file)
@@ -219,8 +219,10 @@ public class SoneDownloader extends AbstractService {
         * @param soneInputStream
         *            The input stream to parse the Sone from
         * @return The parsed Sone
+        * @throws SoneException
+        *             if a parse error occurs, or the protocol is invalid
         */
-       public Sone parseSone(Sone originalSone, InputStream soneInputStream) {
+       public Sone parseSone(Sone originalSone, InputStream soneInputStream) throws SoneException {
                /* TODO - impose a size limit? */
 
                Document document;
@@ -330,6 +332,8 @@ public class SoneDownloader extends AbstractService {
                Integer profileBirthYear = Numbers.safeParseInteger(profileXml.getValue("birth-year", null));
                Profile profile = new Profile().setFirstName(profileFirstName).setMiddleName(profileMiddleName).setLastName(profileLastName);
                profile.setBirthDay(profileBirthDay).setBirthMonth(profileBirthMonth).setBirthYear(profileBirthYear);
+               /* avatar is processed after images are loaded. */
+               String avatarId = profileXml.getValue("avatar", null);
 
                /* parse profile fields. */
                SimpleXML profileFieldsXml = profileXml.getNode("fields");
@@ -493,6 +497,11 @@ public class SoneDownloader extends AbstractService {
                        }
                }
 
+               /* process avatar. */
+               if (avatarId != null) {
+                       sone.setAvatar(core.getImage(avatarId, false));
+               }
+
                /* okay, apparently everything was parsed correctly. Now import. */
                /* atomic setter operation on the Sone. */
                synchronized (sone) {