X-Git-Url: http://git.nikiroo.be/?p=gofetch.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fgofetch%2Fsupport%2FLWN.java;h=dba4c3bfa922f684729352baa2d438e075c1ac88;hp=2fea78a864855529e79d3022e92da3476027d97a;hb=27008a8782c0ed96e07c8dc39ff0ed1f5163a9d0;hpb=93e09a08a68ffd69eed42ecbf95f317b518357d7 diff --git a/src/be/nikiroo/gofetch/support/LWN.java b/src/be/nikiroo/gofetch/support/LWN.java index 2fea78a..dba4c3b 100644 --- a/src/be/nikiroo/gofetch/support/LWN.java +++ b/src/be/nikiroo/gofetch/support/LWN.java @@ -139,8 +139,8 @@ public class LWN extends BasicSupport { } private Comment getComment(Element commentElement) { - String title = firstOrEmpty(commentElement, "CommentTitle"); - String author = firstOrEmpty(commentElement, "CommentPoster"); + String title = firstOrEmpty(commentElement, "CommentTitle").text(); + String author = firstOrEmpty(commentElement, "CommentPoster").text(); String date = ""; int pos = author.lastIndexOf(" by "); @@ -153,69 +153,54 @@ public class LWN extends BasicSupport { } } - String content = ""; + Element content = null; Elements commentBodyElements = commentElement .getElementsByClass("CommentBody"); if (commentBodyElements.size() > 0) { - for (Node contentNode : commentBodyElements.get(0).childNodes()) { - if (contentNode instanceof Element) { - Element contentElement = (Element) contentNode; - if (!contentElement.hasClass("CommentPoster")) { - content = content.trim() + " " - + contentElement.text().trim(); - } - } else { - content = content.trim() + " " - + contentNode.outerHtml().trim(); - } - - } - content = content.trim(); + content = commentBodyElements.get(0); } Comment comment = new Comment(commentElement.id(), author, title, date, - content); + toLines(content)); return comment; } - /** - * Get the first element of the given class, or an empty {@link String} if - * none found. - * - * @param element - * the element to look in - * @param className - * the class to look for - * - * @return the value or an empty {@link String} - */ - private String firstOrEmpty(Element element, String className) { - Elements subElements = element.getElementsByClass(className); - if (subElements.size() > 0) { - return subElements.get(0).text(); - } + private List toLines(Element element) { + return toLines(element, new QuoteProcessor() { + @Override + public String processText(String text) { + while (text.startsWith(">")) { // comments + text = text.substring(1).trim(); + } - return ""; - } + return text; + } - /** - * Get the first element of the given tag, or an empty {@link String} if - * none found. - * - * @param element - * the element to look in - * @param tagName - * the tag to look for - * - * @return the value or an empty {@link String} - */ - private String firstOrEmptyTag(Element element, String tagName) { - Elements subElements = element.getElementsByTag(tagName); - if (subElements.size() > 0) { - return subElements.get(0).text(); - } + @Override + public boolean detectQuote(Node node) { + if (node instanceof Element) { + Element elementNode = (Element) node; + if (elementNode.tagName().equals("blockquote") + || elementNode.hasClass("QuotedText")) { + return true; + } + } + + return false; + } - return ""; + @Override + public boolean ignoreNode(Node node) { + if (node instanceof Element) { + Element elementNode = (Element) node; + if (elementNode.hasClass("CommentPoster")) { + return true; + } + } + + return false; + } + }); } }