+ /* parse profile. */
+ String profileFirstName = profileXml.getValue("first-name", null);
+ String profileMiddleName = profileXml.getValue("middle-name", null);
+ String profileLastName = profileXml.getValue("last-name", null);
+ Integer profileBirthDay = Numbers.safeParseInteger(profileXml.getValue("birth-day", null));
+ Integer profileBirthMonth = Numbers.safeParseInteger(profileXml.getValue("birth-month", null));
+ 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);
+
+ /* parse posts. */
+ SimpleXML postsXml = soneXml.getNode("posts");
+ Set<Post> posts = new HashSet<Post>();
+ if (postsXml == null) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, "Downloaded Sone %s has no posts!", new Object[] { sone });
+ } else {
+ for (SimpleXML postXml : postsXml.getNodes("post")) {
+ String postId = postXml.getValue("id", null);
+ String postRecipientId = postXml.getValue("recipient", null);
+ String postTime = postXml.getValue("time", null);
+ String postText = postXml.getValue("text", null);
+ if ((postId == null) || (postTime == null) || (postText == null)) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, "Downloaded post for Sone %s with missing data! ID: %s, Time: %s, Text: %s", new Object[] { sone, postId, postTime, postText });
+ return null;
+ }
+ try {
+ Post post = core.getPost(postId).setSone(sone).setTime(Long.parseLong(postTime)).setText(postText);
+ if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
+ post.setRecipient(core.getSone(postRecipientId));
+ }
+ posts.add(post);
+ } catch (NumberFormatException nfe1) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, "Downloaded post for Sone %s with invalid time: %s", new Object[] { sone, postTime });
+ return null;
+ }
+ }
+ }
+
+ /* parse replies. */
+ SimpleXML repliesXml = soneXml.getNode("replies");
+ Set<Reply> replies = new HashSet<Reply>();
+ if (repliesXml == null) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, "Downloaded Sone %s has no replies!", new Object[] { sone });
+ } else {
+ for (SimpleXML replyXml : repliesXml.getNodes("reply")) {
+ String replyId = replyXml.getValue("id", null);
+ String replyPostId = replyXml.getValue("post-id", null);
+ String replyTime = replyXml.getValue("time", null);
+ String replyText = replyXml.getValue("text", null);
+ if ((replyId == null) || (replyPostId == null) || (replyTime == null) || (replyText == null)) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, "Downloaded reply for Sone %s with missing data! ID: %s, Post: %s, Time: %s, Text: %s", new Object[] { sone, replyId, replyPostId, replyTime, replyText });
+ return null;
+ }
+ try {
+ replies.add(core.getReply(replyId).setSone(sone).setPost(core.getPost(replyPostId)).setTime(Long.parseLong(replyTime)).setText(replyText));
+ } catch (NumberFormatException nfe1) {
+ /* TODO - mark Sone as bad. */
+ logger.log(Level.WARNING, "Downloaded reply for Sone %s with invalid time: %s", new Object[] { sone, replyTime });
+ return null;
+ }