X-Git-Url: https://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2FFetcher.java;h=6c86c136266b53f8c79e0d73cc3626fd7b9da495;hb=3e62b034c1981ae6329f06b3f8c0ee25c3683789;hp=e53bfaf3c41d72bd566dd47ef9ec9fdd40b9d015;hpb=1647310f0abec346d291df8bbb3317da5cc65144;p=gofetch.git
diff --git a/src/be/nikiroo/gofetch/Fetcher.java b/src/be/nikiroo/gofetch/Fetcher.java
index e53bfaf..6c86c13 100644
--- a/src/be/nikiroo/gofetch/Fetcher.java
+++ b/src/be/nikiroo/gofetch/Fetcher.java
@@ -14,7 +14,7 @@ import be.nikiroo.gofetch.output.Gopher;
import be.nikiroo.gofetch.output.Html;
import be.nikiroo.gofetch.output.Output;
import be.nikiroo.gofetch.support.BasicSupport;
-import be.nikiroo.gofetch.support.BasicSupport.Type;
+import be.nikiroo.gofetch.support.Type;
import be.nikiroo.utils.IOUtils;
/**
@@ -42,8 +42,8 @@ public class Fetcher {
* the sub directory and (pre-)selector to use for the resources
* (will 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(),
@@ -93,8 +98,8 @@ public class Fetcher {
}
ref = "../" + ref + "/index.html";
- htmlBuilder.append(getLink(support.getDescription(),
- ref, true, true));
+ htmlBuilder.append(getLink(support.getDescription(), ref, true,
+ true));
}
File gopherCache = new File(dir, preselector);
@@ -142,12 +147,20 @@ public class Fetcher {
// Get comments (and update stories if needed):
int i = 1;
+ List fetchedStories = new ArrayList(stories.size());
for (Story story : stories) {
- System.err.println(String.format("%02d/%02d", i, stories.size())
+ System.err.print(String.format("%02d/%02d", i, stories.size())
+ " Fetching full story " + story.getId() + "...");
- support.fetch(story);
+ try {
+ support.fetch(story);
+ fetchedStories.add(story);
+ System.err.println();
+ } catch (IOException e) {
+ System.err.println(" Failed to get story!");
+ }
i++;
}
+ stories = fetchedStories;
Output gopher = new Gopher(support.getType(), hostname, preselector,
port);
@@ -188,28 +201,23 @@ public class Fetcher {
List gopherLines = new ArrayList();
List htmlLines = new ArrayList();
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),
- true,
- false));
-
- htmlLines.add(getLink("More",
- "index_"
- + (page + 1)
- + ".html",
- true,
- true));
+ gopherLines.add(getLink("More", support.getSelector()
+ + "gophermap_" + (page + 1), true, false));
+
+ htmlLines.add(getLink("More", "index_" + (page + 1)
+ + ".html", true, true));
}
write(gopherLines, varDir, "gophermap", "", page);
@@ -237,13 +245,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) {