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 <a href="https://www.toolinux.com/">https://www.toolinux.com/</a>.
+ *
+ * @author niki
+ */
public class TooLinux extends BasicSupport {
@Override
public String getDescription() {
- return "TooLinux: Premier quotidien francophone d'actualité généraliste sur Linux, les logiciels libres et l'interopérabilité, depuis mars 2000.";
+ return "TooLinux: Actualité généraliste sur Linux et les logiciels libres";
}
@Override
- public List<Story> list() throws IOException {
- List<Story> list = new ArrayList<Story>();
+ protected List<Entry<URL, String>> getUrls() throws IOException {
+ List<Entry<URL, String>> urls = new ArrayList<Entry<URL, String>>();
+ urls.add(new AbstractMap.SimpleEntry<URL, String>(new URL(
+ "https://www.toolinux.com/"), ""));
+ return urls;
+ }
- 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 = "";
+ @Override
+ protected List<Element> getArticles(Document doc) {
+ return doc.getElementsByClass("hentry");
+ }
- Element urlElement = article.getElementsByTag("a").first();
- if (urlElement != null) {
- intUrl = urlElement.absUrl("href");
- }
+ @Override
+ protected String getArticleId(Document doc, Element article) {
+ return ""; // We use the date
+ }
- Element titleElement = article.getElementsByClass("entry-title")
- .first();
- if (titleElement != null) {
- title = StringUtils.unhtml(titleElement.text()).trim();
- }
+ @Override
+ protected String getArticleTitle(Document doc, Element article) {
+ Element titleElement = article.getElementsByClass("entry-title")
+ .first();
+ if (titleElement != null) {
+ return titleElement.text();
+ }
- Element dateElement = article.getElementsByClass("published")
- .first();
- if (dateElement != null) {
- date = StringUtils.unhtml(dateElement.text()).trim();
- id = dateElement.attr("title").trim();
- }
+ return "";
+ }
- if (id.isEmpty()) {
- // fallback
- id = intUrl.replace("/", "_");
- }
+ @Override
+ protected String getArticleAuthor(Document doc, Element article) {
+ return "";
+ }
- Element detailsElement = article.getElementsByClass("introduction")
- .first();
- details = "(" + date + ") ";
- if (detailsElement != null) {
- details += StringUtils.unhtml(detailsElement.text()).trim();
- }
+ @Override
+ protected String getArticleDate(Document doc, Element article) {
+ Element dateElement = article.getElementsByClass("published").first();
+ if (dateElement != null) {
+ return dateElement.attr("title");
+ }
+
+ return "";
+ }
+
+ @Override
+ protected String getArticleCategory(Document doc, Element article,
+ String currentCategory) {
+ return "";
+ }
+
+ @Override
+ protected String getArticleDetails(Document doc, Element article) {
+ return "";
+ }
- list.add(new Story(getType(), id, title, details, intUrl, extUrl,
- body));
+ @Override
+ protected String getArticleIntUrl(Document doc, Element article) {
+ Element urlElement = article.getElementsByTag("a").first();
+ if (urlElement != null) {
+ return urlElement.absUrl("href");
}
- return list;
- }
-
- @Override
- public void fetch(Story story) throws IOException {
- String fullContent = story.getContent();
- List<Comment> comments = new ArrayList<Comment>();
- 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 getArticleExtUrl(Document doc, Element article) {
+ return "";
+ }
- story.setFullContent(fullContent);
- } finally {
- if (in != null) {
- in.close();
- }
+ @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<Element> 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<Element> 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;
}
}