X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FTooLinux.java;h=3b23b0de1707d584112658bb5f3dcd9c4dd69a1f;hb=aacd7f07ac5e2b4bb4ef0dfef48ec272b16900fa;hp=0cc4c6cf58839d9646ad5d567f48767dfdff068e;hpb=039171a07ca06a8849289ad344c5ac1d09c8ed9c;p=gofetch.git
diff --git a/src/be/nikiroo/gofetch/support/TooLinux.java b/src/be/nikiroo/gofetch/support/TooLinux.java
index 0cc4c6c..3b23b0d 100644
--- a/src/be/nikiroo/gofetch/support/TooLinux.java
+++ b/src/be/nikiroo/gofetch/support/TooLinux.java
@@ -1,20 +1,15 @@
package be.nikiroo.gofetch.support;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URL;
+import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map.Entry;
-import org.jsoup.helper.DataUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
-import org.jsoup.select.Elements;
-
-import be.nikiroo.gofetch.data.Comment;
-import be.nikiroo.gofetch.data.Story;
-import be.nikiroo.utils.StringUtils;
/**
* Support https://www.toolinux.com/.
@@ -28,97 +23,141 @@ public class TooLinux extends BasicSupport {
}
@Override
- public List list() throws IOException {
- List list = new ArrayList();
-
- URL url = new URL("https://www.toolinux.com/");
- InputStream in = downloader.open(url);
- Document doc = DataUtil.load(in, "UTF-8", url.toString());
- Elements articles = doc.getElementsByClass("hentry");
- for (Element article : articles) {
- String id = "";
- String intUrl = "";
- String extUrl = ""; // nope
- String title = "";
- String date = "";
- String details = "";
- String body = "";
- String author = ""; // nope
- String categ = ""; // nope
-
- Element urlElement = article.getElementsByTag("a").first();
- if (urlElement != null) {
- intUrl = urlElement.absUrl("href");
- }
+ protected List> getUrls() throws IOException {
+ List> urls = new ArrayList>();
+ urls.add(new AbstractMap.SimpleEntry(new URL(
+ "https://www.toolinux.com/"), ""));
+ return urls;
+ }
- Element titleElement = article.getElementsByClass("entry-title")
- .first();
- if (titleElement != null) {
- title = StringUtils.unhtml(titleElement.text()).trim();
- }
+ @Override
+ protected List getArticles(Document doc) {
+ return doc.getElementsByClass("hentry");
+ }
- Element dateElement = article.getElementsByClass("published")
- .first();
- if (dateElement != null) {
- date = StringUtils.unhtml(dateElement.text()).trim();
- id = dateElement.attr("title").trim();
- }
+ @Override
+ protected String getArticleId(Document doc, Element article) {
+ return ""; // We use the date
+ }
- if (id.isEmpty()) {
- // fallback
- id = intUrl.replace("/", "_");
- }
+ @Override
+ protected String getArticleTitle(Document doc, Element article) {
+ Element titleElement = article.getElementsByClass("entry-title")
+ .first();
+ if (titleElement != null) {
+ return titleElement.text();
+ }
- Element bodyElement = article.getElementsByClass("introduction")
- .first();
- if (bodyElement != null) {
- body = StringUtils.unhtml(bodyElement.text()).trim();
- }
+ return "";
+ }
- list.add(new Story(getType(), id, title, author, date, categ,
- details, intUrl, extUrl, body));
+ @Override
+ protected String getArticleAuthor(Document doc, Element article) {
+ return "";
+ }
+
+ @Override
+ protected String getArticleDate(Document doc, Element article) {
+ Element dateElement = article.getElementsByClass("published").first();
+ if (dateElement != null) {
+ return dateElement.attr("title");
}
- return list;
- }
-
- @Override
- public void fetch(Story story) throws IOException {
- String fullContent = story.getContent();
- List comments = new ArrayList();
- story.setComments(comments);
-
- URL url = new URL(story.getUrlInternal());
- InputStream in = downloader.open(url);
- try {
- Document doc = DataUtil.load(in, "UTF-8", url.toString());
- Element article = doc.getElementById("content");
- if (article != null) {
- for (String line : toLines(article,
- new BasicElementProcessor() {
- @Override
- public boolean ignoreNode(Node node) {
- if ("notes".equals(node.attr("class"))) {
- return true;
- }
- return false;
- }
- })) {
- fullContent += line + "\n";
- }
+ return "";
+ }
- // Content is too tight with a single break per line:
- fullContent = fullContent.replace("\n", "\n\n") //
- .replace("\n\n\n\n", "\n\n") //
- .replace("\n\n\n\n", "\n\n") //
- .trim();
- }
+ @Override
+ protected String getArticleCategory(Document doc, Element article,
+ String currentCategory) {
+ return "";
+ }
- story.setFullContent(fullContent);
- } finally {
- if (in != null) {
- in.close();
- }
+ @Override
+ protected String getArticleDetails(Document doc, Element article) {
+ return "";
+ }
+
+ @Override
+ protected String getArticleIntUrl(Document doc, Element article) {
+ Element urlElement = article.getElementsByTag("a").first();
+ if (urlElement != null) {
+ return urlElement.absUrl("href");
}
+
+ return "";
+ }
+
+ @Override
+ protected String getArticleExtUrl(Document doc, Element article) {
+ return "";
+ }
+
+ @Override
+ protected String getArticleContent(Document doc, Element article) {
+ Element content = article.getElementsByClass("introduction").first();
+ if (content != null) {
+ return getArticleText(content);
+ }
+
+ return "";
+ }
+
+ @Override
+ protected Element getFullArticle(Document doc) {
+ return doc.getElementById("content");
+ }
+
+ @Override
+ protected List getFullArticleCommentPosts(Document doc, URL intUrl) {
+ return null;
+ }
+
+ @Override
+ protected ElementProcessor getElementProcessorFullArticle() {
+ return new BasicElementProcessor() {
+ @Override
+ public boolean ignoreNode(Node node) {
+ if ("notes".equals(node.attr("class"))) {
+ return true;
+ }
+ return false;
+ }
+ };
+ }
+
+ @Override
+ protected List getCommentCommentPosts(Document doc,
+ Element container) {
+ return null;
+ }
+
+ @Override
+ protected String getCommentId(Element post) {
+ return null;
+ }
+
+ @Override
+ protected String getCommentAuthor(Element post) {
+ return null;
+ }
+
+ @Override
+ protected String getCommentTitle(Element post) {
+ return null;
+ }
+
+ @Override
+ protected String getCommentDate(Element post) {
+ return null;
+ }
+
+ @Override
+ protected Element getCommentContentElement(Element post) {
+ return null;
+ }
+
+ @Override
+ protected ElementProcessor getElementProcessorComment() {
+ return null;
}
}