X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2FFetcher.java;h=bd5a4543fda92a92da61d665205fb5744364b217;hb=e570bb42dfb90f4c31429069ac7095514ff3ee2f;hp=ea11894de37e7d6a19eb8a7f283e51ceb17089ae;hpb=411d3399b3c2e4c8c6760258cb82c14e022da7a2;p=gofetch.git diff --git a/src/be/nikiroo/gofetch/Fetcher.java b/src/be/nikiroo/gofetch/Fetcher.java index ea11894..bd5a454 100644 --- a/src/be/nikiroo/gofetch/Fetcher.java +++ b/src/be/nikiroo/gofetch/Fetcher.java @@ -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,11 +81,16 @@ 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(), - support.getSelector(), false)); + support.getSelector(), true, false)); String ref = support.getSelector(); while (ref.startsWith("/")) { @@ -93,13 +98,14 @@ public class Fetcher { } ref = "../" + ref + "/index.html"; - htmlBuilder.append(getLink(support.getDescription(), ref, true)); + htmlBuilder.append(getLink(support.getDescription(), ref, true, + true)); } File gopherCache = new File(dir, preselector); gopherCache.mkdirs(); File htmlIndex = new File(gopherCache, "index.html"); - gopherCache = new File(gopherCache, ".cache"); + gopherCache = new File(gopherCache, "gophermap"); Output gopher = new Gopher(null, hostname, preselector, port); Output html = new Html(null, hostname, preselector, port); @@ -187,22 +193,26 @@ 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() - + ".cache_" + (page + 1), false)); + + "gophermap_" + (page + 1), true, false)); + htmlLines.add(getLink("More", "index_" + (page + 1) - + ".html", true)); + + ".html", true, true)); } - write(gopherLines, varDir, ".cache", "", page); + write(gopherLines, varDir, "gophermap", "", page); write(htmlLines, varDir, "index", ".html", page); gopherLines = new ArrayList(); htmlLines = new ArrayList(); @@ -226,10 +236,24 @@ public class Fetcher { } } - private String getLink(String name, String ref, boolean html) { + /** + * 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 -- not used in html mode + * @param html + * 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) { - return new StringBuilder().append("1" + name).append("\t") - .append("1" + ref) // + return new StringBuilder().append((menu ? "1" : "0") + name) + .append("\t").append(ref) // .append("\t").append(hostname) // .append("\t").append(Integer.toString(port)) // .append("\r\n").toString();