X-Git-Url: http://git.nikiroo.be/?p=gofetch.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FBasicSupport.java;h=a748262857debc001dcb07cd557a7563a007e3d7;hp=972852333fed4707ecd9ed2812e45c7f2ee00f8b;hb=a71d4075a8591b0655277b1a0e606ee48d228869;hpb=1ab7ff0acbc00ddcf6b27a3bebd1e351fdbe96a2 diff --git a/src/be/nikiroo/gofetch/support/BasicSupport.java b/src/be/nikiroo/gofetch/support/BasicSupport.java index 9728523..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. */ - static protected 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) { @@ -273,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); @@ -346,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 *