Java Code Examples for org.jsoup.nodes.Node#attr()

The following examples show how to use org.jsoup.nodes.Node#attr() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private boolean unlikely(Node e) {
    if (e.attr("class") != null && e.attr("class").toLowerCase().contains("caption"))
        return true;

    String style = e.attr("style");
    String clazz = e.attr("class");
    return unlikelyPattern.matcher(style).find() || unlikelyPattern.matcher(clazz).find();
}
 
Example 2
Source Project: JumpGo   File: OutputFormatter.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private boolean unlikely(Node e) {
    if (e.attr("class") != null && e.attr("class").toLowerCase().contains("caption"))
        return true;

    String style = e.attr("style");
    String clazz = e.attr("class");
    return unlikelyPattern.matcher(style).find() || unlikelyPattern.matcher(clazz).find();
}
 
Example 3
Source Project: ZfsoftCampusAssit   File: CommonParser.java    License: Apache License 2.0 5 votes vote down vote up
public void parseCollegeYears(String rawHtml, Setting setting) {
    Element doc = Jsoup.parse(rawHtml).getElementById("xnd");
    for (Node yearNode : doc.childNodes()) {
        if (yearNode.hasAttr("value")) {
            setting.ownYears.add(yearNode.attr("value"));
            if (yearNode.hasAttr("selected")) {
                setting.currentYear = yearNode.attr("selected");
            }
        }
    }

}
 
Example 4
Source Project: ZfsoftCampusAssit   File: CommonParser.java    License: Apache License 2.0 5 votes vote down vote up
public void parseCollegeTerms(String rawHtml, Setting setting) {
    Element doc = Jsoup.parse(rawHtml).getElementById("xqd");
    for (Node yearNode : doc.childNodes()) {
        if (yearNode.hasAttr("value")) {
            setting.ownTerms.add(yearNode.attr("value"));
            if (yearNode.hasAttr("selected")) {
                setting.currentTerm = yearNode.attr("selected");
            }
        }
    }
}
 
Example 5
Source Project: quarkus   File: JavaDocParser.java    License: Apache License 2.0 4 votes vote down vote up
private void appendHtml(StringBuilder sb, Node node) {
    for (Node childNode : node.childNodes()) {
        switch (childNode.nodeName()) {
            case PARAGRAPH_NODE:
                sb.append(NEW_LINE);
                appendHtml(sb, childNode);
                break;
            case ORDERED_LIST_NODE:
            case UN_ORDERED_LIST_NODE:
                appendHtml(sb, childNode);
                break;
            case LIST_ITEM_NODE:
                final String marker = childNode.parent().nodeName().equals(ORDERED_LIST_NODE)
                        ? ORDERED_LIST_ITEM_ASCIDOC_STYLE
                        : UNORDERED_LIST_ITEM_ASCIDOC_STYLE;
                sb.append(NEW_LINE);
                sb.append(marker);
                appendHtml(sb, childNode);
                break;
            case LINK_NODE:
                final String link = childNode.attr(HREF_ATTRIBUTE);
                sb.append("link:");
                sb.append(link);
                final StringBuilder caption = new StringBuilder();
                appendHtml(caption, childNode);
                sb.append(String.format(LINK_ATTRIBUTE_FORMAT, caption.toString().trim()));
                break;
            case CODE_NODE:
                sb.append(BACKTICK);
                appendHtml(sb, childNode);
                sb.append(BACKTICK);
                break;
            case BOLD_NODE:
            case EMPHASIS_NODE:
                sb.append(STAR);
                appendHtml(sb, childNode);
                sb.append(STAR);
                break;
            case ITALICS_NODE:
                sb.append(UNDERSCORE);
                appendHtml(sb, childNode);
                sb.append(UNDERSCORE);
                break;
            case UNDERLINE_NODE:
                sb.append(UNDERLINE_ASCIDOC_STYLE);
                sb.append(HASH);
                appendHtml(sb, childNode);
                sb.append(HASH);
                break;
            case SMALL_NODE:
                sb.append(SMALL_ASCIDOC_STYLE);
                sb.append(HASH);
                appendHtml(sb, childNode);
                sb.append(HASH);
                break;
            case BIG_NODE:
                sb.append(BIG_ASCIDOC_STYLE);
                sb.append(HASH);
                appendHtml(sb, childNode);
                sb.append(HASH);
                break;
            case SUB_SCRIPT_NODE:
                sb.append(SUB_SCRIPT_ASCIDOC_STYLE);
                appendHtml(sb, childNode);
                sb.append(SUB_SCRIPT_ASCIDOC_STYLE);
                break;
            case SUPER_SCRIPT_NODE:
                sb.append(SUPER_SCRIPT_ASCIDOC_STYLE);
                appendHtml(sb, childNode);
                sb.append(SUPER_SCRIPT_ASCIDOC_STYLE);
                break;
            case DEL_NODE:
            case S_NODE:
            case STRIKE_NODE:
                sb.append(LINE_THROUGH_ASCIDOC_STYLE);
                sb.append(HASH);
                appendHtml(sb, childNode);
                sb.append(HASH);
                break;
            case NEW_LINE_NODE:
                sb.append(NEW_LINE);
                break;
            case TEXT_NODE:
                appendEscapedAsciiDoc(sb, ((TextNode) childNode).text());
                break;
            default:
                appendHtml(sb, childNode);
                break;
        }
    }
}
 
Example 6
private void updateMentionUidToEmail(SymphonyClient symClient, List<Node> nodesList) {


        for (Node node : nodesList) {
            String nodeName = node.nodeName();


            if (nodeName.equalsIgnoreCase(NodeTypes.MENTION.toString())) {

                if (node.attributes().hasKey(AttribTypes.UID.toString())) {

                    String uid = node.attr(AttribTypes.UID.toString());

                    SymUser user = null;
                    try {
                        user = symClient.getUsersClient().getUserFromId(Long.parseLong(uid));

                        logger.info("Translated mention uid {} to email {}", uid, user.getEmailAddress());
                    } catch (UsersClientException e) {
                        logger.error("Could not identify user email from id", e);
                    }

                    if (user != null && user.getEmailAddress() != null) {
                        uid = user.getEmailAddress();
                    }

                    Attribute emailAttribute = new Attribute(AttribTypes.EMAIL.toString(), uid);

                    node.attributes().put(emailAttribute);
                    node.removeAttr(AttribTypes.UID.toString());

                }

            }
            updateMentionUidToEmail(symClient, node.childNodes());
        }


    }