X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FBasicSupport.java;h=a748262857debc001dcb07cd557a7563a007e3d7;hb=a71d4075a8591b0655277b1a0e606ee48d228869;hp=a59ae313fb1f1fda8979020d7e6315d81ba6592e;hpb=3e62b034c1981ae6329f06b3f8c0ee25c3683789;p=gofetch.git diff --git a/src/be/nikiroo/gofetch/support/BasicSupport.java b/src/be/nikiroo/gofetch/support/BasicSupport.java index a59ae31..a748262 100644 --- a/src/be/nikiroo/gofetch/support/BasicSupport.java +++ b/src/be/nikiroo/gofetch/support/BasicSupport.java @@ -31,8 +31,10 @@ import be.nikiroo.utils.StringUtils; * @author niki */ public abstract class BasicSupport { - /** The downloader to use for all websites. */ - protected static Downloader downloader = new Downloader("gofetcher"); + /** + * The downloader to use for all websites via {@link BasicSupport#open(URL)} + */ + static private Downloader downloader = new Downloader("gofetcher"); static private String preselector; @@ -55,7 +57,7 @@ public abstract class BasicSupport { * @return the selector */ public String getSelector() { - return getSelector(type); + return getSelector(getType()); } /** @@ -87,7 +89,7 @@ public abstract class BasicSupport { defaultCateg = ""; } - InputStream in = downloader.open(url); + InputStream in = open(url); Document doc = DataUtil.load(in, "UTF-8", url.toString()); List articles = getArticles(doc); for (Element article : articles) { @@ -106,7 +108,11 @@ public abstract class BasicSupport { continue; } - if (id.isEmpty()) { + if (!id.isEmpty()) { + while (id.length() < 10) { + id = "0" + id; + } + } else { id = date.replace(":", "_").replace("+", "_"); } @@ -269,7 +275,7 @@ public abstract class BasicSupport { String fullContent = ""; URL url = new URL(story.getUrlInternal()); - InputStream in = downloader.open(url); + InputStream in = open(url); try { Document doc = DataUtil.load(in, "UTF-8", url.toString()); Element article = getFullArticle(doc); @@ -342,6 +348,23 @@ public abstract class BasicSupport { */ abstract protected ElementProcessor getElementProcessorFullArticle(); + /** + * Open a network resource. + *

+ * You need to close the returned {@link InputStream} when done. + * + * @param url + * the source to open + * + * @return the content + * + * @throws IOException + * in case of I/O error + */ + protected InputStream open(URL url) throws IOException { + return downloader.open(url); + } + /** * Convert the comment elements into {@link Comment}s * @@ -526,6 +549,9 @@ public abstract class BasicSupport { case ERE_NUMERIQUE: support = new EreNumerique(); break; + case PHORONIX: + support = new Phoronix(); + break; } if (support != null) {