From 4448c88ba0401366f4566eb42a850ded674f8ceb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 10 Apr 2011 12:40:29 +0200 Subject: [PATCH] Implement album structure loading. --- .../java/net/pterodactylus/sone/core/Core.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 4e3df64..6a90c7a 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1319,6 +1319,40 @@ public class Core implements IdentityListener, UpdateListener { friends.add(friendId); } + /* load albums. */ + Map albums = new HashMap(); + List topLevelAlbums = new ArrayList(); + while (true) { + String albumPrefix = sonePrefix + "/Albums/" + albums.size(); + String albumId = configuration.getStringValue(albumPrefix + "/ID").getValue(null); + if (albumId == null) { + break; + } + String albumName = configuration.getStringValue(albumPrefix + "/Name").getValue(null); + String albumDescription = configuration.getStringValue(albumPrefix + "/Description").getValue(null); + String albumParentId = configuration.getStringValue(albumPrefix + "/Parent").getValue(null); + if ((albumName == null) || (albumDescription == null)) { + logger.log(Level.WARNING, "Invalid album found, aborting load!"); + return; + } + Album album = new Album(albumId).setSone(sone).setName(albumName).setDescription(albumDescription); + albums.put(albumId, album); + if (albumParentId != null) { + Album parentAlbum = albums.get(albumParentId); + if (parentAlbum == null) { + logger.log(Level.WARNING, "Invalid parent album ID: " + albumParentId); + return; + } + parentAlbum.addAlbum(album); + } else { + topLevelAlbums.add(album); + } + } + + /* load options. */ + sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption(false)); + sone.getOptions().getBooleanOption("AutoFollow").set(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(null)); + /* if we’re still here, Sone was loaded successfully. */ synchronized (sone) { sone.setTime(soneTime); @@ -1328,6 +1362,7 @@ public class Core implements IdentityListener, UpdateListener { sone.setLikePostIds(likedPostIds); sone.setLikeReplyIds(likedReplyIds); sone.setFriends(friends); + sone.setAlbums(topLevelAlbums); soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint); } synchronized (newSones) { -- 2.7.4