package com.czbix.v2ex.parser;

import com.czbix.v2ex.model.Topic;
import com.czbix.v2ex.model.TopicWithComments;
import com.google.common.collect.Lists;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class TopicParser {
    public static TopicWithComments parseDoc(Document doc, Topic topic) {
        final Topic.Builder topicBuilder = topic.toBuilder();

        parseContent(topicBuilder, doc.select(".topic_content").get(0));

        // TODO:
        return new TopicWithComments(topicBuilder.createTopic(), Lists.<String>newArrayList());
    }

    private static void parseContent(Topic.Builder builder, Element ele) {
        builder.setContent(ele.html());
    }
}

@@ -212,16 +212,50 @@
 Element;
+%0Aimport org.jsoup.select.Elements;
 %0A%0Apublic
@@ -479,15 +479,8 @@
 nt%22)
-.get(0)
 );%0A%0A
@@ -670,15 +670,108 @@
 ment
+s
  ele
-) %7B
+ments) %7B%0A        if (elements.size() != 1) return;%0A        final Element ele = elements.get(0);
 %0A   

fix bug when topic have not content