- Set<Post> posts = new HashSet<Post>();
- for (SimpleXML postXml : postsXml.getNodes("post")) {
- String postId = postXml.getValue("id", 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;
- }
- try {
- posts.add(new Post(postId, sone, Long.parseLong(postTime), postText));
- } 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;
- }
- }
+ /**
+ * Parses a Sone from the given input stream and creates a new Sone from the
+ * parsed data.
+ *
+ * @param originalSone
+ * The Sone to update
+ * @param soneInputStream
+ * The input stream to parse the Sone from
+ * @return The parsed Sone
+ * @throws SoneException
+ * if a parse error occurs, or the protocol is invalid
+ */
+ public Sone parseSone(Sone originalSone, InputStream soneInputStream) throws SoneException {
+ return new SoneParser(core).parseSone(originalSone, soneInputStream);
+ }