X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneParser.java;h=1f3056538458efe737a3c48cdcd9c76340e1a6e9;hb=04709e23f38e9d447337682ba27201da5dc19bd9;hp=fdbd9aeca7ac294c11a6ec92491c18cd4fe1d402;hpb=c4ae226ec5052116cefc542ae2017036a7bc6332;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/core/SoneParser.java b/src/main/java/net/pterodactylus/sone/core/SoneParser.java
index fdbd9ae..1f30565 100644
--- a/src/main/java/net/pterodactylus/sone/core/SoneParser.java
+++ b/src/main/java/net/pterodactylus/sone/core/SoneParser.java
@@ -14,6 +14,8 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.inject.Inject;
+
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
@@ -23,6 +25,7 @@ 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.Database;
import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostReplyBuilder;
import net.pterodactylus.sone.database.SoneBuilder;
@@ -33,17 +36,16 @@ import org.w3c.dom.Document;
/**
* Parses a {@link Sone} from an XML {@link InputStream}.
- *
- * @author David âBombeâ Roden
*/
public class SoneParser {
private static final Logger logger = getLogger(SoneParser.class.getName());
private static final int MAX_PROTOCOL_VERSION = 0;
- private final Core core;
+ private final Database database;
- public SoneParser(Core core) {
- this.core = core;
+ @Inject
+ public SoneParser(Database database) {
+ this.database = database;
}
public Sone parseSone(Sone originalSone, InputStream soneInputStream) throws SoneException {
@@ -60,7 +62,7 @@ public class SoneParser {
return null;
}
- SoneBuilder soneBuilder = core.soneBuilder().from(originalSone.getIdentity());
+ SoneBuilder soneBuilder = database.newSoneBuilder().from(originalSone.getIdentity());
if (originalSone.isLocal()) {
soneBuilder = soneBuilder.local();
}
@@ -164,7 +166,7 @@ public class SoneParser {
/* parse posts. */
SimpleXML postsXml = soneXml.getNode("posts");
- Set posts = new HashSet();
+ Set posts = new HashSet<>();
if (postsXml == null) {
/* TODO - mark Sone as bad. */
logger.log(Level.WARNING, String.format("Downloaded Sone %s has no posts!", sone));
@@ -180,7 +182,7 @@ public class SoneParser {
return null;
}
try {
- PostBuilder postBuilder = core.postBuilder();
+ PostBuilder postBuilder = database.newPostBuilder();
/* TODO - parse time correctly. */
postBuilder.withId(postId).from(sone.getId()).withTime(Long.parseLong(postTime)).withText(postText);
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
@@ -197,7 +199,7 @@ public class SoneParser {
/* parse replies. */
SimpleXML repliesXml = soneXml.getNode("replies");
- Set replies = new HashSet();
+ Set replies = new HashSet<>();
if (repliesXml == null) {
/* TODO - mark Sone as bad. */
logger.log(Level.WARNING, String.format("Downloaded Sone %s has no replies!", sone));
@@ -213,7 +215,7 @@ public class SoneParser {
return null;
}
try {
- PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
+ PostReplyBuilder postReplyBuilder = database.newPostReplyBuilder();
/* TODO - parse time correctly. */
postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
replies.add(postReplyBuilder.build());
@@ -227,7 +229,7 @@ public class SoneParser {
/* parse liked post IDs. */
SimpleXML likePostIdsXml = soneXml.getNode("post-likes");
- Set likedPostIds = new HashSet();
+ Set likedPostIds = new HashSet<>();
if (likePostIdsXml == null) {
/* TODO - mark Sone as bad. */
logger.log(Level.WARNING, String.format("Downloaded Sone %s has no post likes!", sone));
@@ -240,7 +242,7 @@ public class SoneParser {
/* parse liked reply IDs. */
SimpleXML likeReplyIdsXml = soneXml.getNode("reply-likes");
- Set likedReplyIds = new HashSet();
+ Set likedReplyIds = new HashSet<>();
if (likeReplyIdsXml == null) {
/* TODO - mark Sone as bad. */
logger.log(Level.WARNING, String.format("Downloaded Sone %s has no reply likes!", sone));
@@ -253,8 +255,8 @@ public class SoneParser {
/* parse albums. */
SimpleXML albumsXml = soneXml.getNode("albums");
- Map allImages = new HashMap();
- List topLevelAlbums = new ArrayList();
+ Map allImages = new HashMap<>();
+ List topLevelAlbums = new ArrayList<>();
if (albumsXml != null) {
for (SimpleXML albumXml : albumsXml.getNodes("album")) {
String id = albumXml.getValue("id", null);
@@ -267,13 +269,13 @@ public class SoneParser {
}
Album parent = null;
if (parentId != null) {
- parent = core.getAlbum(parentId);
+ parent = database.getAlbum(parentId);
if (parent == null) {
logger.log(Level.WARNING, String.format("Downloaded Sone %s has album with invalid parent!", sone));
return null;
}
}
- Album album = core.albumBuilder()
+ Album album = database.newAlbumBuilder()
.withId(id)
.by(sone)
.build()
@@ -307,7 +309,7 @@ public class SoneParser {
logger.log(Level.WARNING, String.format("Downloaded Sone %s contains image %s with invalid dimensions (%s, %s)!", sone, imageId, imageWidthString, imageHeightString));
return null;
}
- Image image = core.imageBuilder().withId(imageId).build().modify().setSone(sone).setKey(imageKey).setCreationTime(creationTime).update();
+ Image image = database.newImageBuilder().withId(imageId).build().modify().setSone(sone).setKey(imageKey).setCreationTime(creationTime).update();
image = image.modify().setTitle(imageTitle).setDescription(imageDescription).update();
image = image.modify().setWidth(imageWidth).setHeight(imageHeight).update();
album.addImage(image);