package com.githang.gradledoc.chapter;

import android.util.Log;

import com.githang.gradledoc.datasource.AbstractResponse;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * User: Geek_Soledad(msdx.android@qq.com)
 * Date: 2014-11-29
 * Time: 21:36
 * FIXME
 */
public abstract class ChapterHandler implements AbstractResponse {
    @Override
    public void onSuccess(String response) {
        Document doc = Jsoup.parse(response);
        Element chapter = doc.select("div.chapter").first();
        String title = chapter.select("div.titlepage").select("h1").text();
        chapter.removeClass("titlepage");
        Elements preElems = chapter.select("pre");
        for(Element elem : preElems) {
            elem.html(elem.html().replaceAll("\n", "<br/>").replaceAll(" ", "&nbsp;"));
        }

        onResult(title, chapter.html());
    }

    public abstract void onResult(String title, String doc);

    @Override
    public void onFailure(String response, Throwable e) {

    }

    @Override
    public void onFinish() {

    }
}

@@ -39,36 +39,8 @@
 %0D%0A%0D%0A
-import android.util.Log;%0D%0A%0D%0A
 impo
@@ -680,24 +680,233 @@
 tlepage%22);%0D%0A
+        handlerPreTag(chapter);%0D%0A%0D%0A        onResult(title, chapter.html());%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * %E5%A4%84%E7%90%86%E4%BB%A3%E7%A0%81%E6%98%BE%E7%A4%BA%E9%97%AE%E9%A2%98.%0D%0A     * @param chapter %E7%AB%A0%E8%8A%82%E5%86%85%E5%AE%B9%E7%9A%84html%E5%85%83%E7%B4%A0%E3%80%82%0D%0A     */%0D%0A    private void handlerPreTag(Element chapter) %7B%0D%0A
         Elem
@@ -941,24 +941,24 @@
 ct(%22pre%22);%0D%0A
-
         for(
@@ -1088,52 +1088,8 @@
   %7D%0D
-%0A%0D%0A        onResult(title, chapter.html());%0D
 %0A   
@@ -1090,24 +1090,26 @@
 %7D%0D%0A    %7D%0D%0A%0D%0A
+%0D%0A
     public a

Refactor codes.