package com.dreiri.stolpersteine.activities.bio;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

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

import android.app.Activity;
import android.webkit.WebView;

public class HTMLContentLoader {

    private WebView browser;
    
    public HTMLContentLoader(WebView browser) {
        this.browser = browser;
    }
    
    public void loadContent(final Activity activity, final String url, final String cssQuery) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Document document = Jsoup.parse(new URL(url).openStream(), "utf-8", url);
                    Elements elements = document.select(cssQuery);
                    String content = elements.toString();
                    DataLoaderRunnable dataLoaderRunnable = new DataLoaderRunnable(browser, content);
                    activity.runOnUiThread(dataLoaderRunnable);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
    
    private class DataLoaderRunnable implements Runnable {
        
        private WebView browser;
        private String data;
        private String mimeType = "text/html; charset=UTF-8";
        
        public DataLoaderRunnable(WebView browser, String data) {
            this.browser = browser;
            this.data = data;
        }
        
        @Override
        public void run() {
            browser.loadData(data, mimeType, null);
        }
        
    }

}

@@ -130,16 +130,80 @@
 net.URL;
+%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0Aimport
@@ -931,24 +931,87 @@
 toString();%0A
+                    content = removeHTMLTagHyperlink(content);%0A
             
@@ -1855,32 +1855,32 @@
 ull);%0A        %7D%0A
-
         %0A    %7D%0A%0A
@@ -1877,12 +1877,412 @@
   %0A    %7D
+%0A    %0A    private String removeHTMLTagHyperlink(String content) %7B%0A        Pattern pattern = Pattern.compile(%22%3Ca%5C%5Cs.+?%3E(.+?)%3C/a%3E%22);%0A        Matcher matcher = pattern.matcher(content);%0A        StringBuffer sb = new StringBuffer();%0A        while (matcher.find()) %7B%0A            matcher.appendReplacement(sb, matcher.group(1));%0A        %7D%0A        matcher.appendTail(sb);%0A        return sb.toString();%0A    %7D
 %0A%0A%7D%0A

Remove hyperlink HTML tag for text view.