Add URL footnotes
[gofetch.git] / src / be / nikiroo / gofetch / support / BasicSupport.java
index 615c72d6b0cbd81c4f59d8472878ea07ef4b730a..4067979d4dc1b3f1657189be91d85ec8cec345c0 100644 (file)
@@ -19,7 +19,7 @@ public abstract class BasicSupport {
        protected static Downloader downloader = new Downloader("gofetcher");
 
        public enum Type {
-               SLASHDOT, PIPEDOT, LWN, LEMONDE,
+               SLASHDOT, PIPEDOT, LWN, LEMONDE, REGISTER, TOOLINUX,
        }
 
        /**
@@ -178,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) {
@@ -250,6 +256,7 @@ public abstract class BasicSupport {
                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() {
@@ -307,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
@@ -343,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;
        }
 }