Fix loading of local Sones without posts and replies.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / ConfigurationSoneParser.java
index 3d384c1..f592c1e 100644 (file)
@@ -33,18 +33,19 @@ import net.pterodactylus.util.config.Configuration;
 public class ConfigurationSoneParser {
 
        private final Configuration configuration;
-       private final Sone sone;
+       private final String soneId;
        private final String sonePrefix;
        private final Map<String, Album> albums = new HashMap<String, Album>();
        private final List<Album> topLevelAlbums = new ArrayList<Album>();
+       private final Map<String, Image> images = new HashMap<String, Image>();
 
-       public ConfigurationSoneParser(Configuration configuration, Sone sone) {
+       public ConfigurationSoneParser(Configuration configuration, String soneId) {
                this.configuration = configuration;
-               this.sone = sone;
-               sonePrefix = "Sone/" + sone.getId();
+               this.soneId = soneId;
+               sonePrefix = "Sone/" + soneId;
        }
 
-       public Profile parseProfile() {
+       public Profile parseProfile(Sone sone) {
                Profile profile = new Profile(sone);
                profile.setFirstName(getString("/Profile/FirstName", null));
                profile.setMiddleName(getString("/Profile/MiddleName", null));
@@ -99,7 +100,7 @@ public class ConfigurationSoneParser {
                        }
                        PostBuilder postBuilder = postBuilderFactory.newPostBuilder()
                                        .withId(postId)
-                                       .from(sone.getId())
+                                       .from(soneId)
                                        .withTime(postTime)
                                        .withText(postText);
                        String postRecipientId =
@@ -138,7 +139,7 @@ public class ConfigurationSoneParser {
                        PostReplyBuilder postReplyBuilder = postReplyBuilderFactory
                                        .newPostReplyBuilder()
                                        .withId(replyId)
-                                       .from(sone.getId())
+                                       .from(soneId)
                                        .to(postId)
                                        .withTime(replyTime)
                                        .withText(replyText);
@@ -188,7 +189,7 @@ public class ConfigurationSoneParser {
        }
 
        public List<Album> parseTopLevelAlbums(
-                       AlbumBuilderFactory albumBuilderFactory) {
+                       AlbumBuilderFactory albumBuilderFactory, Sone sone) {
                int albumCounter = 0;
                while (true) {
                        String albumPrefix = "/Albums/" + albumCounter++;
@@ -232,7 +233,7 @@ public class ConfigurationSoneParser {
                return unmodifiableMap(albums);
        }
 
-       public void parseImages(ImageBuilderFactory imageBuilderFactory) {
+       public void parseImages(ImageBuilderFactory imageBuilderFactory, Sone sone) {
                int imageCounter = 0;
                while (true) {
                        String imagePrefix = "/Images/" + imageCounter++;
@@ -270,9 +271,14 @@ public class ConfigurationSoneParser {
                                        .setHeight(height)
                                        .update();
                        album.addImage(image);
+                       images.put(image.getId(), image);
                }
        }
 
+       public Map<String, Image> getImages() {
+               return images;
+       }
+
        private boolean albumAttributesAreInvalid(String albumId, String key,
                        String title, String description, Long creationTime,
                        Integer width, Integer height) {