package de.jeha.kame.crawler.core;

import de.jeha.kame.crawler.core.types.CrawlResult;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jenshadlich@googlemail.com
 */
public class LinkExtractor {

    public List<String> get(CrawlResult crawlResult) {

        final List<String> links = new ArrayList<>();

        if (!crawlResult.hasContent()) {
            throw new IllegalStateException("content must not be null");
        }

        Document document = Jsoup.parse(crawlResult.getContent());

        for (Element e : document.select("a[href]")) {
            final String href = e.attr("href");

            if ("#".equals(href)) {
                continue;
            }
            if (href != null && href.startsWith("#")) {
                continue;
            }

            links.add(e.attr("href"));
        }

        return links;
    }
}

@@ -359,63 +359,8 @@
  %7B%0A%0A
-        final List%3CString%3E links = new ArrayList%3C%3E();%0A%0A
     
@@ -429,13 +429,16 @@
 egal
-State
+Argument
 Exce
@@ -547,24 +547,165 @@
 ontent());%0A%0A
+        return get(document);%0A    %7D%0A%0A    public List%3CString%3E get(Document document) %7B%0A        final List%3CString%3E links = new ArrayList%3C%3E();%0A%0A
         for 
@@ -1047,10 +1047,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

add method to directly get links from jsoup document