X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FBasicSupport.java;h=6d930f6f4320bbeae13a14d098f846fa289fd96b;hb=b34d1f357b076c1697e381b70cb6ff1bb0278b91;hp=b7eaca3cfe8e6917e3507212cfbb24d29657be5b;hpb=d28c4aac3f42d9de93e3969e86a7c84e2d2e963a;p=gofetch.git diff --git a/src/be/nikiroo/gofetch/support/BasicSupport.java b/src/be/nikiroo/gofetch/support/BasicSupport.java index b7eaca3..6d930f6 100644 --- a/src/be/nikiroo/gofetch/support/BasicSupport.java +++ b/src/be/nikiroo/gofetch/support/BasicSupport.java @@ -1,7 +1,10 @@ package be.nikiroo.gofetch.support; import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import org.jsoup.helper.StringUtil; @@ -15,11 +18,33 @@ import org.jsoup.select.NodeVisitor; import be.nikiroo.gofetch.data.Story; import be.nikiroo.utils.Downloader; +/** + * Base class for website support. + * + * @author niki + */ public abstract class BasicSupport { + /** The downloader to use for all websites. */ protected static Downloader downloader = new Downloader("gofetcher"); + /** + * The support type (each website we support has a single type). + * + * @author niki + */ public enum Type { - SLASHDOT, PIPEDOT, LWN, LEMONDE, REGISTER, + /** EN: Any, but mostly IT/Sci */ + SLASHDOT, + /** EN: Clone of Slashdot, mostly abandoned */ + PIPEDOT, + /** EN: Linux */ + LWN, + /** FR: Any */ + LEMONDE, + /** EN: IT */ + REGISTER, + /** FR: Linux */ + TOO_LINUX, } /** @@ -43,7 +68,8 @@ public abstract class BasicSupport { * * @param text * the text to process - * @return + * + * @return the resulting text */ public String processText(String text); @@ -130,21 +156,49 @@ public abstract class BasicSupport { */ abstract public void fetch(Story story) throws IOException; + /** + * The website textual description, to add in the dispatcher page. + *

+ * Should be short. + * + * @return the description + */ abstract public String getDescription(); + /** + * The gopher "selector" to use for output. + *

+ * A kind of "URL path", like "/news/" or "/misc/news/" or... + * + * @return the selector + */ public String getSelector() { return getSelector(type); } + /** + * The support type. + * + * @return the type + */ public Type getType() { return type; } + /** + * The support type. + * + * @param type + * the new type + */ protected void setType(Type type) { this.type = type; } /** + * The {@link String} to append to the selector (the selector will be + * constructed as "this string" then "/type/". + * * @param preselector * the preselector to set */ @@ -181,6 +235,9 @@ public abstract class BasicSupport { case REGISTER: support = new TheRegister(); break; + case TOO_LINUX: + support = new TooLinux(); + break; } if (support != null) { @@ -191,6 +248,17 @@ public abstract class BasicSupport { return support; } + /** + * The gopher "selector" to use for output for this type, using the + * preselector. + *

+ * A kind of "URL path", like "/news/" or "/misc/news/" or... + * + * @param type + * the type to get the selector of + * + * @return the selector + */ static public String getSelector(Type type) { return preselector + "/" + type + "/"; } @@ -348,4 +416,35 @@ public abstract class BasicSupport { return lines; } + + /** + * Reformat the date if possible. + * + * @param date + * the input date + * + * @return the reformated date, or the same value if it was not parsable + */ + static protected String date(String date) { + SimpleDateFormat out = new SimpleDateFormat("yyyy/MM/dd"); + + long epoch = 0; + try { + epoch = Long.parseLong(date); + } catch (Exception e) { + epoch = 0; + } + + if (epoch > 0) { + return out.format(new Date(1000 * epoch)); + } + + try { + Date dat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX") + .parse(date.trim()); + return out.format(dat); + } catch (ParseException e) { + return date; + } + } }