X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FBasicSupport.java;h=4067979d4dc1b3f1657189be91d85ec8cec345c0;hb=86d03b2e4fe0a2b53b83e981388394f3c5965f27;hp=f3348e366f1ceeece3c6bec39ea01f031ffe8c95;hpb=202173602397b0793542c7a90f9d86013e153067;p=gofetch.git diff --git a/src/be/nikiroo/gofetch/support/BasicSupport.java b/src/be/nikiroo/gofetch/support/BasicSupport.java index f3348e3..4067979 100644 --- a/src/be/nikiroo/gofetch/support/BasicSupport.java +++ b/src/be/nikiroo/gofetch/support/BasicSupport.java @@ -1,12 +1,8 @@ package be.nikiroo.gofetch.support; import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; import java.util.List; -import java.util.zip.GZIPInputStream; import org.jsoup.helper.StringUtil; import org.jsoup.nodes.Element; @@ -17,10 +13,13 @@ import org.jsoup.select.NodeTraversor; import org.jsoup.select.NodeVisitor; import be.nikiroo.gofetch.data.Story; +import be.nikiroo.utils.Downloader; public abstract class BasicSupport { + protected static Downloader downloader = new Downloader("gofetcher"); + public enum Type { - SLASHDOT, PIPEDOT, LWN, LEMONDE, + SLASHDOT, PIPEDOT, LWN, LEMONDE, REGISTER, TOOLINUX, } /** @@ -179,6 +178,12 @@ public abstract class BasicSupport { case LEMONDE: support = new LeMonde(); break; + case REGISTER: + support = new TheRegister(); + break; + case TOOLINUX: + support = new TooLinux(); + break; } if (support != null) { @@ -193,18 +198,6 @@ public abstract class BasicSupport { return preselector + "/" + type + "/"; } - // TODO: check Downloader.java? - static protected InputStream open(URL url) throws IOException { - URLConnection conn = url.openConnection(); - conn.connect(); - InputStream in = conn.getInputStream(); - if ("gzip".equals(conn.getContentEncoding())) { - in = new GZIPInputStream(in); - } - - return in; - } - /** * Get the first {@link Element} of the given class, or an empty span * {@link Element} if none found. @@ -263,6 +256,7 @@ public abstract class BasicSupport { final StringBuilder currentLine = new StringBuilder(); final List quoted = new ArrayList(); final List ignoredNodes = new ArrayList(); + final List footnotes = new ArrayList(); if (element != null) { new NodeTraversor(new NodeVisitor() { @@ -320,6 +314,11 @@ public abstract class BasicSupport { if (block && currentLine.length() > 0) { currentLine.append("\n"); } + + if (!element.absUrl("href").trim().isEmpty()) { + footnotes.add(element.absUrl("href")); + currentLine.append("[" + footnotes.size() + "]"); + } } else if (node instanceof TextNode) { TextNode textNode = (TextNode) node; String line = StringUtil.normaliseWhitespace(textNode @@ -356,6 +355,16 @@ public abstract class BasicSupport { lines.set(i, lines.get(i).replace(" ", " ").trim()); } + if (footnotes.size() > 0) { + lines.add(""); + lines.add(""); + lines.add(""); + lines.add(""); + for (int i = 0; i < footnotes.size(); i++) { + lines.add("[" + (i + 1) + "] " + footnotes.get(i)); + } + } + return lines; } }