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;
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,
}
/**
case LEMONDE:
support = new LeMonde();
break;
+ case REGISTER:
+ support = new TheRegister();
+ break;
+ case TOOLINUX:
+ support = new TooLinux();
+ break;
}
if (support != null) {
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.
final StringBuilder currentLine = new StringBuilder();
final List<Integer> quoted = new ArrayList<Integer>();
final List<Node> ignoredNodes = new ArrayList<Node>();
+ final List<String> footnotes = new ArrayList<String>();
if (element != null) {
new NodeTraversor(new NodeVisitor() {
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
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;
}
}