Rename fetch action methods
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneParser.java
index 5851b18..fdbd9ae 100644 (file)
@@ -20,6 +20,8 @@ import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Profile.DuplicateField;
+import net.pterodactylus.sone.data.Profile.EmptyFieldName;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.database.PostBuilder;
 import net.pterodactylus.sone.database.PostReplyBuilder;
@@ -36,7 +38,7 @@ import org.w3c.dom.Document;
  */
 public class SoneParser {
 
-       private static final Logger logger = getLogger("Sone.Parser");
+       private static final Logger logger = getLogger(SoneParser.class.getName());
        private static final int MAX_PROTOCOL_VERSION = 0;
        private final Core core;
 
@@ -150,8 +152,11 @@ public class SoneParser {
                                }
                                try {
                                        profile.addField(fieldName.trim()).setValue(fieldValue);
-                               } catch (IllegalArgumentException iae1) {
-                                       logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName), iae1);
+                               } catch (EmptyFieldName efn1) {
+                                       logger.log(Level.WARNING, "Empty field name!", efn1);
+                                       return null;
+                               } catch (DuplicateField df1) {
+                                       logger.log(Level.WARNING, String.format("Duplicate field: %s", fieldName), df1);
                                        return null;
                                }
                        }
@@ -256,7 +261,6 @@ public class SoneParser {
                                String parentId = albumXml.getValue("parent", null);
                                String title = albumXml.getValue("title", null);
                                String description = albumXml.getValue("description", "");
-                               String albumImageId = albumXml.getValue("album-image", null);
                                if ((id == null) || (title == null)) {
                                        logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid album!", sone));
                                        return null;
@@ -310,7 +314,6 @@ public class SoneParser {
                                                allImages.put(imageId, image);
                                        }
                                }
-                               album.modify().setAlbumImage(albumImageId).update();
                        }
                }
 
@@ -320,16 +323,13 @@ public class SoneParser {
                }
 
                /* okay, apparently everything was parsed correctly. Now import. */
-               /* atomic setter operation on the Sone. */
-               synchronized (sone) {
-                       sone.setProfile(profile);
-                       sone.setPosts(posts);
-                       sone.setReplies(replies);
-                       sone.setLikePostIds(likedPostIds);
-                       sone.setLikeReplyIds(likedReplyIds);
-                       for (Album album : topLevelAlbums) {
-                               sone.getRootAlbum().addAlbum(album);
-                       }
+               sone.setProfile(profile);
+               sone.setPosts(posts);
+               sone.setReplies(replies);
+               sone.setLikePostIds(likedPostIds);
+               sone.setLikeReplyIds(likedReplyIds);
+               for (Album album : topLevelAlbums) {
+                       sone.getRootAlbum().addAlbum(album);
                }
 
                return sone;