1 package be
.nikiroo
.gofetch
.support
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import java
.net
.URLConnection
;
8 import java
.util
.zip
.GZIPInputStream
;
10 import be
.nikiroo
.gofetch
.data
.Story
;
12 public abstract class BasicSupport
{
14 SLASHDOT
, PIPEDOT
, LWN
,
17 static private String preselector
;
21 abstract public List
<Story
> list() throws IOException
;
24 * Fetch the full article content as well as all the comments associated to
25 * this {@link Story}, if any (can be empty, but not NULL).
28 * the story to fetch the comments of
31 * in case of I/O error
33 abstract public void fetch(Story story
) throws IOException
;
35 abstract public String
getDescription();
37 public String
getSelector() {
38 return getSelector(type
);
41 public Type
getType() {
45 protected void setType(Type type
) {
51 * the preselector to set
53 static public void setPreselector(String preselector
) {
54 BasicSupport
.preselector
= preselector
;
57 static public BasicSupport
getSupport(Type type
) {
58 BasicSupport support
= null;
63 support
= new Slashdot();
66 support
= new Pipedot();
73 if (support
!= null) {
74 support
.setType(type
);
81 static public String
getSelector(Type type
) {
82 return preselector
+ "/" + type
+ "/";
85 // TODO: check Downloader.java?
86 static protected InputStream
open(URL url
) throws IOException
{
87 URLConnection conn
= url
.openConnection();
89 InputStream in
= conn
.getInputStream();
90 if ("gzip".equals(conn
.getContentEncoding())) {
91 in
= new GZIPInputStream(in
);