X-Git-Url: http://git.nikiroo.be/?p=gofetch.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FBasicSupport.java;h=dcd5e6ea295ad11f18372035d7b9033b1b7c5ba0;hp=a748262857debc001dcb07cd557a7563a007e3d7;hb=9cf08a99ce4a796a2294fa1f14315aa16d97c3ce;hpb=c5850b2b4c929bf7fe77cc069ebfcc5c00ba9265 diff --git a/src/be/nikiroo/gofetch/support/BasicSupport.java b/src/be/nikiroo/gofetch/support/BasicSupport.java index a748262..dcd5e6e 100644 --- a/src/be/nikiroo/gofetch/support/BasicSupport.java +++ b/src/be/nikiroo/gofetch/support/BasicSupport.java @@ -8,7 +8,9 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import org.jsoup.helper.DataUtil; @@ -32,14 +34,31 @@ import be.nikiroo.utils.StringUtils; */ public abstract class BasicSupport { /** - * The downloader to use for all websites via {@link BasicSupport#open(URL)} + * The downloader to use for all web sites via + * {@link BasicSupport#open(URL)} */ static private Downloader downloader = new Downloader("gofetcher"); static private String preselector; + /** + * The optional cookies to use to get the site data. + */ + private Map cookies = new HashMap(); + private Type type; + /** + * Login on the web site (this method does nothing by default, but can be + * overridden if needed). + * + * @throws IOException + * in case of I/O error + * + */ + public void login() throws IOException { + } + /** * The website textual description, to add in the dispatcher page. *

@@ -82,6 +101,7 @@ public abstract class BasicSupport { public List list() throws IOException { List list = new ArrayList(); + login(); for (Entry entry : getUrls()) { URL url = entry.getKey(); String defaultCateg = entry.getValue(); @@ -312,7 +332,8 @@ public abstract class BasicSupport { } /** - * Return the full article if available. + * Return the full article if available (this is the article to retrieve + * from the newly downloaded page at {@link Story#getUrlInternal()}). * * @param doc * the (full article) document to work on @@ -362,7 +383,7 @@ public abstract class BasicSupport { * in case of I/O error */ protected InputStream open(URL url) throws IOException { - return downloader.open(url); + return downloader.open(url, url, cookies, null, null, null); } /** @@ -503,6 +524,18 @@ public abstract class BasicSupport { this.type = type; } + /** + * Add a cookie for all site connections. + * + * @param name + * the cookie name + * @param value + * the value + */ + protected void addCookie(String name, String value) { + cookies.put(name, value); + } + /** * The {@link String} to append to the selector (the selector will be * constructed as "this string" then "/type/". @@ -552,6 +585,9 @@ public abstract class BasicSupport { case PHORONIX: support = new Phoronix(); break; + case SEPT_SUR_SEPT: + support = new SeptSurSept(); + break; } if (support != null) {