Example usage for org.jsoup.nodes Element text

List of usage examples for org.jsoup.nodes Element text

Introduction

In this page you can find the example usage for org.jsoup.nodes Element text.

Prototype

public String text() 

Source Link

Document

Gets the combined text of this element and all its children.

Usage

From source file:org.asqatasun.processing.ProcessRemarkServiceImpl.java

@Override
public SourceCodeRemark createSourceCodeRemark(TestSolution processResult, Element element,
        String messageCode) {/*from  w ww. j  a  v  a 2 s.c o  m*/

    SourceCodeRemark remark = processRemarkDataService.getSourceCodeRemark(element.nodeName(), processResult,
            messageCode, searchElementLineNumber(element));

    remark.setSnippet(getSnippetFromElement(element));
    for (String attr : evidenceElementList) {
        EvidenceElement evidenceElementSup;
        if (StringUtils.equalsIgnoreCase(attr, "text")) {
            evidenceElementSup = getEvidenceElement(attr, element.text());
        } else {
            evidenceElementSup = getEvidenceElement(attr, element.attr(attr));
        }
        remark.addElement(evidenceElementSup);
    }
    return remark;
}

From source file:org.asqatasun.rules.accessiweb22.Aw22Rule06061.java

@Override
protected void select(SSPHandler sspHandler) {
    new SimpleElementSelector(NOT_ANCHOR_LINK_CSS_LIKE_QUERY).selectElements(sspHandler, linksHandler);

    if (linksHandler.isEmpty()) {
        return;// w w w  .  j  av  a 2  s.c o m
    }

    for (Element el : linksHandler.get()) {
        if (StringUtils.isBlank(el.text())
                && el.getElementsByAttributeValueMatching(ALT_ATTR, "^(?=\\s*\\S).*$").isEmpty()) {
            emptyLinksHandler.add(el);
        }
    }
}

From source file:org.asqatasun.rules.doc.utils.exportdomtocsv.ExportDomToCsv.java

/**
 * Before using it please set the FOLDER variable with the path where you
 * want to create your csv file.//from   w  w w  .j av a 2 s  . c om
 *
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    File ref = FileUtils.getFile(FOLDER);
    JsoupFunc jsf = new JsoupFunc();
    Document doc = jsf.getDocument();
    Elements thematiques = doc.select("div.thematique");
    StringBuilder sb = new StringBuilder();
    String testCode;
    String testLabel = "";
    String critere;
    for (int i = 2; i < thematiques.size(); i++) {
        String themeIndex = String.valueOf(i - 1) + "";
        String theme = (thematiques.get(i).child(0).text() + "");
        Elements criteres = thematiques.get(i).select("h3");
        for (int j = 1; j < criteres.size(); j++) {
            Element critereLevel = criteres.get(j);
            String critereH3String = critereLevel.toString();
            String level = critereH3String.substring(critereH3String.indexOf("[") + 1,
                    critereH3String.indexOf("]")) + "";
            Elements tests = criteres.get(j).nextElementSibling().select("[id^=test-]");
            try {
                critere = criteres.get(j).id().substring(5, 10) + "";
            } catch (StringIndexOutOfBoundsException sioobe) {
                try {
                    critere = criteres.get(j).id().substring(5, 9) + "";
                } catch (StringIndexOutOfBoundsException sioobe2) {
                    critere = criteres.get(j).id().substring(5, 8) + "";
                }
            }
            String[] critereArray = criteres.get(j).text().split("] ");
            String critereLabel = critereArray[1].toString() + "";
            for (Element el : tests) {
                Pattern digitPattern = Pattern.compile("\\d+\\.\\d+\\.\\d+\\s?\\:?\\s?");
                Matcher matcher = digitPattern.matcher(el.text());
                if (matcher.find()) {
                    String testLabelReplace = el.html()
                            .replace("index.php", "http://www.accessiweb.org/index.php").replace("\n", "");
                    testLabel = testLabelReplace.substring(matcher.end(), testLabelReplace.length()) + "";
                }
                try {
                    testCode = el.id().substring(5, 12) + "";
                } catch (StringIndexOutOfBoundsException sioobe) {
                    try {
                        testCode = (el.id().substring(5, 11) + "");
                    } catch (StringIndexOutOfBoundsException sioobe3) {
                        testCode = (el.id().substring(5, 10) + "");
                    }
                }
                sb.append(themeIndex + theme + critere + critereLabel + testCode + testLabel + level + "\n");
            }
        }
    }
    FileUtils.writeStringToFile(ref, sb.toString());
}

From source file:org.asqatasun.rules.doc.utils.rga33.extractor.Rgaa3Extractor.java

/**
 * @param args the command line arguments
 * @throws java.io.IOException//from   w  w w . java 2  s.  com
 */
public static void main(String[] args) throws IOException {
    // Get content from websites
    Document rgaa3Doc = Jsoup.parse(new URL(RGAA3_REF_URL), 10000);
    Document aw22Doc = Jsoup.parse(new URL(AW22_URL), 10000);

    extractLevelFromCriterionAndWrite(rgaa3Doc);
    extractRuleInfo(rgaa3Doc);

    // Extract rules from accessiweb 2.2
    for (Element el : aw22Doc.select(TEST_SELECTOR)) {
        if (StringUtils.isNotBlank(el.text())) {
            AW22.put(extractTestFromId(el.id()), el.text());
        }
    }

    //        generateMysql();
    compareReferentials();
    //
    //        getRuleI18nKeys();
    //        checkClassesExist();
    //        updateTestcasesWithRuleTitle();
    //        generateMkdoc();
    //        createTestcaseFiles();

}

From source file:org.asqatasun.rules.doc.utils.rga33.extractor.Rgaa3Extractor.java

private static void extractLevelFromCriterionAndWrite(Document doc) throws IOException {
    StringBuilder crit = new StringBuilder();
    for (Element el : doc.select(CRITERION_SELECTOR)) {
        if (StringUtils.isNotBlank(el.id())) {
            crit.append(el.id().replace("crit", "Rgaa30"));
            crit.append("=");
            String content = el.html();
            content = content.substring(content.indexOf("] ") + 1);
            content = extractRuleContent(content);
            crit.append(content);//from w  w  w  .j  a va  2s.  c  om
            crit.append("\n");
            String level = el.text().substring(el.text().indexOf("[") + 1, el.text().indexOf("]"));
            levelFromCrit.put(el.id().replaceAll("crit-", ""), level);
        }
    }
    if (writeCritInFile) {
        FileUtils.write(new File(CRITERION_I18N_FILE_PATH), crit.toString());
    }
}

From source file:org.asqatasun.rules.doc.utils.rga33.extractor.Rgaa3Extractor.java

private static void extractRuleInfo(Document doc) {
    boolean isFirst112 = false;
    for (Element el : doc.select(TEST_SELECTOR)) {
        if (StringUtils.isNotBlank(el.id())) {
            Rule rule = new Rule(RGAA3_REF_URL, REF_NAME);
            rule.ruleId = el.id();//from ww  w.j  ava  2s  . c om
            rule.ruleDash = extractTestFromId(rule.ruleId);
            if (rule.ruleDash.equals("1-1-2")) {
                if (!isFirst112) {
                    isFirst112 = true;
                } else {
                    rule.ruleDash = "1-1-4";
                    rule.ruleId = "test-1-1-4";
                }
            } else if (rule.ruleDash.equals("11-1-4-5")) {
                rule.ruleDash = "11-14-5";
            }
            rule.setRuleRawHtml(el.html().replaceAll("href=\"", "href=\"" + RGAA3_MAIN_URL));
            rule.ruleHtmlWithoutLink = extractRuleContent(rule.ruleRawHtml);
            rule.ruleText = el.text();
            rule.level = levelFromCrit.get(rule.getCriterion());
            RGAA3.put(rule.ruleDash, rule);
        }
    }
}

From source file:org.asqatasun.rules.elementselector.ImageElementSelector.java

/**
 * /*from  w  ww  . j ava  2 s.  c o m*/
 * @param imageParent
 * @param image
 * @return whether the current image is an image link
 */
private boolean isImageLink(Element imageParent, Element image) {
    if (imageParent == null || !StringUtils.equals(imageParent.text(), image.text())) {
        return false;
    }
    if (imageParent.children().size() == 1) {
        return isImageLink(imageParent.child(0), image);
    } else if (imageParent.children().isEmpty() && imageParent.equals(image)) {
        return true;
    }
    return false;
}

From source file:org.asqatasun.rules.elementselector.ImageElementSelector.java

/**
 * An link is seen as composite when it is composed with more than one 
 * element. The tested element has at least one image. If the text is different
 * from the one of the child element, the link is composite by definition. 
 * It the text is identical, we check whether the current element has more
 * than 1 child./*ww  w  .ja  v  a2 s  .c  om*/
 * @param imageParent
 * @return whether the current image is a composite link.
 */
private boolean isCompositeLink(Element imageParent, Element image) {
    if (imageParent == null) {
        return false;
    }
    if (!StringUtils.equals(imageParent.text(), image.text())) {
        return true;
    }
    if (imageParent.children().size() == 1) {
        return isCompositeLink(imageParent.child(0), image);
    } else if (imageParent.children().size() > 1) {
        return true;
    }
    return false;
}

From source file:org.asqatasun.rules.rgaa22.Rgaa22Rule06161.java

@Override
protected void select(SSPHandler sspHandler) {
    super.select(sspHandler);

    for (Element el : getElements().get()) {
        if (StringUtils.isBlank(el.text())
                && el.getElementsByAttributeValueMatching(ALT_ATTR, "^(?=\\s*\\S).*$").isEmpty()) {
            emptyLinksHandler.add(el);/*from   w  w w . j  av  a2s . co m*/
        }
    }
}

From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule060501.java

@Override
protected void select(SSPHandler sspHandler) {
    ElementSelector elementsSelector = new SimpleElementSelector(NOT_ANCHOR_LINK_CSS_LIKE_QUERY);
    elementsSelector.selectElements(sspHandler, linksHandler);
    for (Element el : linksHandler.get()) {
        if (StringUtils.isBlank(el.text())
                && el.getElementsByAttributeValueMatching(ALT_ATTR, "^(?=\\s*\\S).*$").isEmpty()) {
            emptyLinksHandler.add(el);//from   w ww .jav  a  2s .com
        }
    }
}