Do not exit when failing to download a typ
[gofetch.git] / src / be / nikiroo / gofetch / Fetcher.java
index 9dbf0e10bf60d52daad2081f9c615d27dc19973d..bd5a4543fda92a92da61d665205fb5744364b217 100644 (file)
@@ -42,8 +42,8 @@ public class Fetcher {
         *            the sub directory and (pre-)selector to use for the resources
         *            (<b>will</b> have an impact on the files' content)
         * @param type
-        *            the type of news to get (or the special keyword ALL to get all
-        *            of the supported sources)
+        *            the type of news to get (or NULL to get all of the supported
+        *            sources)
         * @param maxStories
         *            the maximum number of stories to show on the resume page
         * @param hostname
@@ -81,7 +81,12 @@ public class Fetcher {
                        BasicSupport support = BasicSupport.getSupport(type);
 
                        if (type == this.type || this.type == null) {
-                               list(support);
+                               try {
+                                       list(support);
+                               } catch (Exception e) {
+                                       new Exception("Failed to process support: " + type, e)
+                                                       .printStackTrace();
+                               }
                        }
 
                        gopherBuilder.append(getLink(support.getDescription(),
@@ -188,19 +193,23 @@ public class Fetcher {
                List<String> gopherLines = new ArrayList<String>();
                List<String> htmlLines = new ArrayList<String>();
                for (i = 0; i < headers.length; i++) {
-                       gopherLines
-                                       .add(IOUtils.readSmallFile(new File(varDir, headers[i])));
-                       htmlLines.add(IOUtils.readSmallFile(new File(varDir, headers[i]
-                                       + ".html")));
+                       File gopherFile = new File(varDir, headers[i]);
+                       File htmlFile = new File(varDir, headers[i] + ".html");
+
+                       if (gopherFile.exists())
+                               gopherLines.add(IOUtils.readSmallFile(gopherFile));
+                       if (htmlFile.exists())
+                               htmlLines.add(IOUtils.readSmallFile(htmlFile));
 
                        boolean enoughStories = (i > 0 && i % maxStories == 0);
                        boolean last = i == headers.length - 1;
                        if (enoughStories || last) {
                                if (!last) {
                                        gopherLines.add(getLink("More", support.getSelector()
-                                                       + "gophermap_" + (page + 1), false, false));
+                                                       + "gophermap_" + (page + 1), true, false));
+
                                        htmlLines.add(getLink("More", "index_" + (page + 1)
-                                                       + ".html", false, true));
+                                                       + ".html", true, true));
                                }
 
                                write(gopherLines, varDir, "gophermap", "", page);
@@ -228,13 +237,18 @@ public class Fetcher {
        }
 
        /**
+        * Create a link.
         * 
         * @param name
+        *            the link name (what the user will see)
         * @param ref
+        *            the actual link reference (the target)
         * @param menu
-        *            menu (gophermap, i) mode
+        *            menu (gophermap, i) mode -- not used in html mode
         * @param html
-        * @return
+        *            TRUE for html mode, FALSE for gopher mode
+        * 
+        * @return the ready-to-use link in a {@link String}
         */
        private String getLink(String name, String ref, boolean menu, boolean html) {
                if (!html) {