Example usage for org.jsoup.nodes Node childNodes

List of usage examples for org.jsoup.nodes Node childNodes

Introduction

In this page you can find the example usage for org.jsoup.nodes Node childNodes.

Prototype

public List<Node> childNodes() 

Source Link

Document

Get this node's children.

Usage

From source file:Main.java

private static void removeComments(Node node) {
    for (int i = 0; i < node.childNodes().size();) {
        Node child = node.childNode(i);
        if (child.nodeName().equals("#comment"))
            child.remove();//from  w w  w  .j av  a  2  s  .c o  m
        else {
            removeComments(child);
            i++;
        }
    }
}

From source file:Main.java

public static String GetNodeTextWithNewLines(Node node) {
    String text = "";

    if (node != null) {
        for (Node childNode : node.childNodes()) {
            if (childNode.nodeName().toLowerCase().equals("br")) {
                text += "\n";
            } else {
                if (childNode instanceof TextNode) {
                    text += childNode;//w  ww .ja v a 2  s. co m
                } else {
                    text += GetNodeTextWithNewLines(childNode);
                }
            }
        }
    }

    return text;
}

From source file:damo.three.ie.util.HtmlUtilities.java

private static void removeComments(Node node) {
    for (int i = 0; i < node.childNodes().size();) {
        Node child = node.childNode(i);
        if (child.nodeName().equals("#comment")) {
            child.remove();//from ww w.j  a va 2 s . c o  m
        } else {
            removeComments(child);
            i++;
        }
    }
}

From source file:com.bibisco.export.HTMLParser.java

private static void parseChildNodes(Node pNode, TextFormatting pTextFormatting, IExporter pExporter) {
    List<Node> lListNode = pNode.childNodes();
    for (Node lNode : lListNode) {
        parseNode(lNode, pTextFormatting, pExporter);
    }//from ww  w  .j a  va  2 s  .  c o m
}

From source file:com.mycollab.core.utils.StringUtils.java

private static void replaceHtml(Node element) {
    List<Node> elements = element.childNodes();
    Pattern compile = Pattern.compile("(?:https?|ftps?)://[\\w/%.-][/\\??\\w=?\\w?/%.-]?[/\\?&\\w=?\\w?/%.-]*");
    for (int i = elements.size() - 1; i >= 0; i--) {
        Node node = elements.get(i);
        if (node instanceof TextNode) {
            String value = ((TextNode) node).text();
            Matcher matcher = compile.matcher(value);
            if (matcher.find()) {
                value = value.replaceAll(
                        "(?:https?|ftps?)://[\\w/%.-][/\\??\\w=?\\w?/%.-]?[/\\?&\\w=?\\w?/%.-]*",
                        "<a href=\"$0\" target=\"_blank\">$0</a>");
                Document newDoc = Jsoup.parse(value);
                List<Node> childs = newDoc.body().childNodes();
                for (int j = 0; j < childs.size(); j++) {
                    Node childNode = childs.get(j).clone();
                    node.before(childNode);
                }/* www.ja  va 2s .  com*/
                node.remove();
            }
        }
    }
}

From source file:com.zacwolf.commons.email.Email.java

public static void removeComments(org.jsoup.nodes.Node node) {
    for (int i = 0; i < node.childNodes().size(); i++) {
        org.jsoup.nodes.Node child = node.childNode(i);
        if (child.nodeName().equals("#comment"))
            child.remove();/*w w w. ja va  2 s  . c o m*/
        else
            removeComments(child);
    }
}

From source file:de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.GoogleReaderMethods.java

@SuppressWarnings("unused")
public static ArrayList<FolderSubscribtionItem> getSubList(String _USERNAME, String _PASSWORD)
        throws UnsupportedEncodingException, IOException {
    ArrayList<FolderSubscribtionItem> _SUBTITLE_ARRAYLIST = new ArrayList<FolderSubscribtionItem>();

    Document doc = Jsoup.connect(GoogleReaderConstants._SUBSCRIPTION_LIST_URL)
            .header("Authorization",
                    GoogleReaderConstants._AUTHPARAMS
                            + AuthenticationManager.getGoogleAuthKey(_USERNAME, _PASSWORD))
            .userAgent(GoogleReaderConstants.APP_NAME).timeout(5000).get();

    Elements objects = doc.select("object");
    Element element = objects.get(0);
    Node childTemp = element.childNodes().get(0);
    List<Node> childs = childTemp.childNodes();

    for (Node node : childs) {
        Elements links = ((Element) node).select("string");
        String idFeed = null;/*from   w  w w.j a va  2 s.  co m*/
        String feedName;
        String parentSubscriptionName;

        for (Element link : links) {
            String tagAttrib = link.attr("name");
            String tagText = link.text();
            if (tagAttrib.equals("id") && idFeed == null)
                idFeed = tagText;
            else if (tagAttrib.equals("title"))
                feedName = tagText;
            else if (tagAttrib.equals("label"))
                parentSubscriptionName = tagText;
        }

        //String idFeed = node.attr("id");
        //String name = node.attr("title");

        //_SUBTITLE_ARRAYLIST.add(new FolderSubscribtionItem(feedName, -1, idFeed, parentSubscriptionName));//TODO implements this again... ? Update FolderSubscribtionItem
    }

    //String[] _SUBTITLE_ARRAY = new String[_SUBTITLE_ARRAYLIST.size()];
    //_SUBTITLE_ARRAYLIST.toArray(_SUBTITLE_ARRAY);
    return _SUBTITLE_ARRAYLIST;
}

From source file:org.coronastreet.gpxconverter.GarminForm.java

private static String findFlowKey(Node node) {
    String key = null;/*from   w  ww  . ja v a  2  s  .  co m*/
    for (int i = 0; i < node.childNodes().size();) {
        Node child = node.childNode(i);
        if (child.nodeName().equals("#comment")) {
            //System.out.println(child.toString());
            String flowKeyPattern = "\\<\\!-- flowExecutionKey\\: \\[(e1s1)\\] --\\>";
            key = child.toString().replaceAll(flowKeyPattern, "$1").trim();
            break;
        } else {
            findFlowKey(child);
            i++;
        }
    }
    return key;
}

From source file:com.sfs.DataFilter.java

/**
 * Removes the comments./*from w  w  w.j a v a  2s  .c  o m*/
 *
 * @param node the node
 */
private static void removeComments(Node node) {
    for (int i = 0; i < node.childNodes().size();) {
        Node child = node.childNode(i);
        if (child.nodeName().equals("#comment"))
            child.remove();
        else {
            removeComments(child);
            i++;
        }
    }
}

From source file:com.screenslicer.core.scrape.Dissect.java

public static String nodeHash(Node node, List<Node> nodes, boolean lenientUrl, boolean lenientTitle) {
    StringBuilder position = new StringBuilder();
    Node cur = node;
    while (cur != null) {
        position.append("<<0>>");
        position.append(cur.hashCode());
        position.append("<<1>>");
        position.append(cur.nodeName());
        position.append("<<2>>");
        position.append(cur.childNodes().size());
        position.append("<<3>>");
        position.append(cur.siblingIndex());
        position.append("<<4>>");
        cur = cur.parent();//w ww  .ja  va 2 s.c o m
    }
    for (Node child : node.childNodes()) {
        position.append("<<c0>>");
        position.append(child.hashCode());
        position.append("<<c1>>");
        position.append(child.nodeName());
        position.append("<<c2>>");
        position.append(child.childNodes().size());
        position.append("<<c3>>");
        position.append(child.siblingIndex());
        position.append("<<c4>>");
    }
    if (nodes != null) {
        for (Node n : nodes) {
            position.append("<<s0>>");
            position.append(n.hashCode());
            position.append("<<s1>>");
            position.append(n.nodeName());
            position.append("<<s2>>");
            position.append(n.childNodes().size());
            position.append("<<s3>>");
            position.append(n.siblingIndex());
            position.append("<<s4>>");
        }
    }
    position.append("<<>>");
    position.append(Util.outerHtml(node).hashCode());
    return "dissectedResults-<<" + lenientUrl + ">>-<<" + lenientTitle + ">>-" + position.toString();
}