List of usage examples for org.jsoup.nodes Element id
public String id()
From source file:org.asqatasun.rules.elementchecker.attribute.IdUnicityChecker.java
/** * This methods checks whether a given id is unique for a set of * elements/* w ww . j a va 2 s . c o m*/ * * @param sspHandler * @param elements * @param testSolutionHandler */ private void checkIdUnicity(SSPHandler sspHandler, Elements elements, TestSolutionHandler testSolutionHandler) { if (elements.isEmpty() || !elements.hasAttr(ID_ATTR)) { testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE); return; } TestSolution testSolution = getSuccessSolution(); for (Element el : elements) { if (el.hasAttr(ID_ATTR) && StringUtils.isNotBlank(el.id()) && getIdPresenceCounter(sspHandler, el.id()) > 1) { testSolution = getFailureSolution(); addSourceCodeRemark(getFailureSolution(), el, getFailureMsgCode()); } } testSolutionHandler.addTestSolution(testSolution); }
From source file:org.asqatasun.rules.elementselector.InputFormElementWithExplicitLabelSelector.java
@Override public void selectElements(SSPHandler sspHandler, ElementHandler<Element> selectionHandler) { for (Element el : getElements(sspHandler)) { if (StringUtils.isNotBlank(el.id()) && isLabelElementWithForAttributeExists(sspHandler, el.id())) { selectionHandler.add(el);//from w w w . ja va 2s . c o m } } }
From source file:org.asqatasun.rules.rgaa22.Rgaa22Rule03101.java
@Override protected void select(SSPHandler sspHandler) { super.select(sspHandler); // From the selected form elements, only keep the one without id // or with an id not unique on the page for (Element el : getElements().get()) { if (!el.hasAttr(ID_ATTR) || StringUtils.isEmpty(el.id().trim()) || CssLikeSelectorBuilder .getNumberOfElements(sspHandler, CssLikeSelectorBuilder.buildSelectorFromId(el.id())) >= 2) { elementsWithoutUniqueId.add(el); }//from ww w . ja va 2 s. c om } }
From source file:org.asqatasun.rules.rgaa22.Rgaa22Rule03111.java
@Override protected void select(SSPHandler sspHandler) { super.select(sspHandler); if (getElements().isEmpty()) { return;//w w w. jav a2 s. co m } Elements elementsWithUniqueId = new Elements(); // From the selected form elements, only keep the one with a unique id // on the page for (Element el : getElements().get()) { if (StringUtils.isNotEmpty(el.id().trim()) && CssLikeSelectorBuilder.getNumberOfElements(sspHandler, CssLikeSelectorBuilder.buildSelectorFromId(el.id())) == 1) { elementsWithUniqueId.add(el); } } // add the subset to the global selection getElements().clean().addAll(elementsWithUniqueId); if (elementsWithUniqueId.isEmpty()) { return; } for (Element el : elementsWithUniqueId) { String labelSelector = CssLikeSelectorBuilder.buildSelectorFromElementsAndAttributeValue(LABEL_ELEMENT, FOR_ATTR, el.id()); if (CssLikeSelectorBuilder.getNumberOfElements(sspHandler, labelSelector) == 0) { this.elementsWithoutLabel.add(el); } } }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule110102.java
@Override protected void check(SSPHandler sspHandler, TestSolutionHandler testSolutionHandler) { /* If the page has no input form element, the test is not applicable */ if (inputFormMap.entrySet().isEmpty()) { testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE); return;//from ww w .ja v a2 s . co m } for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) { /* The attribute Presence Checker */ ElementChecker attributePresenceChecker = new AttributePresenceChecker(ID_ATTR, new ImmutablePair(TestSolution.PASSED, ""), new ImmutablePair(TestSolution.FAILED, ID_MISSING_MSG)); attributePresenceChecker.check(sspHandler, entry.getValue(), testSolutionHandler); /* The attribute Emptiness Checker. Keep default value i.e failed when attribute is empty */ ElementChecker attributeEmptinessChecker = new TextEmptinessChecker( new TextAttributeOfElementBuilder(ID_ATTR), ID_MISSING_MSG, null); attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler); /* The id unicityChecker */ ElementChecker idUnicityChecker = new IdUnicityChecker(ID_NOT_UNIQUE_MSG); idUnicityChecker.check(sspHandler, entry.getValue(), testSolutionHandler); } for (Map.Entry<Element, ElementHandler<Element>> entry : labelFormMap.entrySet()) { /* The attribute Presence Checker */ ElementChecker attributePresenceChecker = new AttributePresenceChecker(FOR_ATTR, new ImmutablePair(TestSolution.PASSED, ""), new ImmutablePair(TestSolution.FAILED, FOR_MISSING_MSG)); attributePresenceChecker.check(sspHandler, entry.getValue(), testSolutionHandler); /* The attribute Emptiness Checker. Keep default value i.e failed when attribute is empty */ ElementChecker attributeEmptinessChecker = new TextEmptinessChecker( new TextAttributeOfElementBuilder(FOR_ATTR), FOR_MISSING_MSG, null); attributeEmptinessChecker.check(sspHandler, entry.getValue(), testSolutionHandler); } for (Map.Entry<Element, ElementHandler<Element>> entry : inputFormMap.entrySet()) { ElementHandler<Element> inputOnError = new ElementHandlerImpl(); /* Check if each input id attribute is linked to a for attribute*/ for (Element el : entry.getValue().get()) { String id = el.id(); if (StringUtils.isNotBlank(id)) { ElementHandler<Element> linkedLabelToInputHandler = new ElementHandlerImpl(); if (entry.getKey() .select(LABEL_ELEMENT + " " + CssLikeSelectorBuilder .buildSelectorFromElementsAndAttributeValue(INPUT_ELEMENT, ID_ATTR, id)) .isEmpty()) { linkedLabelToInputHandler.addAll(entry.getKey().select(CssLikeSelectorBuilder .buildSelectorFromElementsAndAttributeValue(LABEL_ELEMENT, FOR_ATTR, id))); if (linkedLabelToInputHandler.isEmpty()) { inputOnError.add(el); } } } } ElementChecker elementPresenceChecker = new ElementPresenceChecker( new ImmutablePair(TestSolution.FAILED, INVALID_INPUT_MSG), new ImmutablePair(TestSolution.PASSED, "")); elementPresenceChecker.check(sspHandler, inputOnError, testSolutionHandler); } for (Map.Entry<Element, ElementHandler<Element>> entry : labelFormMap.entrySet()) { ElementHandler<Element> labelOnError = new ElementHandlerImpl(); /* Check if each label for attribute is associated to an input id attribute*/ for (Element el : entry.getValue().get()) { String id = el.attr(FOR_ATTR); if (StringUtils.isNotBlank(id)) { ElementHandler<Element> linkedLabelToInputHandler = new ElementHandlerImpl(); linkedLabelToInputHandler .addAll(entry.getKey().select(CssLikeSelectorBuilder.buildSelectorFromId(id))); if (linkedLabelToInputHandler.isEmpty()) { labelOnError.add(el); } } } ElementChecker elementPresenceChecker = new ElementPresenceChecker( new ImmutablePair(TestSolution.FAILED, INVALID_LABEL_MSG), new ImmutablePair(TestSolution.PASSED, "")); elementPresenceChecker.check(sspHandler, labelOnError, testSolutionHandler); } }
From source file:org.opens.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.// w ww . jav a2 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.opens.tanaguru.ruleimplementation.AbstractMarkerPageRuleImplementation.java
/** * To sort marker elements, we extract for each of them the value of the "id" attribute * the value of the "class" attribute and the value of the "role" attribute. * If one of these three values belongs to the marker value list set by the user, * we consider that the element is characterised and we add it to the * "elementMarkerList"./*from ww w. j a v a2 s.co m*/ * * @param nodeList */ private void sortMarkerElements(ElementHandler<Element> elementHandler) { if ((CollectionUtils.isEmpty(markerList) && CollectionUtils.isEmpty(inverseMarkerList)) || elementHandler.isEmpty()) { return; } Iterator<Element> iter = elementHandler.get().iterator(); Element el; while (iter.hasNext()) { el = iter.next(); String id = el.id(); Collection<String> classNames = el.classNames(); String role = el.attr(ROLE_ATTR); // if the element does contain an "id" OR a "class" attribute OR // a "role" attribute AND one the values belongs to the marker list, // it is removed from the global selection and added to the // marker element selection. if (StringUtils.isNotBlank(id) || CollectionUtils.isNotEmpty(classNames) || StringUtils.isNotBlank(role)) { if (checkAttributeBelongsToMarkerList(id, classNames, role, markerList)) { selectionWithMarkerHandler.add(el); iter.remove(); } // if the element belongs to the inverse marker list, it is // removed from the global collection if (checkAttributeBelongsToMarkerList(id, classNames, role, inverseMarkerList)) { iter.remove(); } } } }
From source file:org.opens.tanaguru.rules.elementchecker.attribute.IdUnicityChecker.java
/** * This methods checks whether a given id is unique for a set of * elements//ww w. j a v a 2 s . co m * * @param sspHandler * @param elements * @param testSolutionHandler */ private void checkIdUnicity(SSPHandler sspHandler, Elements elements, TestSolutionHandler testSolutionHandler) { if (elements.isEmpty() || !elements.hasAttr(ID_ATTR)) { testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE); return; } TestSolution testSolution = getSuccessSolution(); for (Element el : elements) { if (el.hasAttr(ID_ATTR) && StringUtils.isNotBlank(el.id()) && getIdPresenceCounter(sspHandler, el.id()) > 1) { testSolution = getFailureSolution(); if (StringUtils.isNotBlank(messageCodeOnIdNotUnique)) { addSourceCodeRemark(getFailureSolution(), el, messageCodeOnIdNotUnique); } } } testSolutionHandler.addTestSolution(testSolution); }
From source file:org.opens.tanaguru.rules.elementselector.InputFormElementWithExplicitLabelSelector.java
@Override public void selectElements(SSPHandler sspHandler, ElementHandler selectionHandler) { for (Element el : getElements(sspHandler)) { if (StringUtils.isNotBlank(el.id()) && isLabelElementWithForAttributeExists(sspHandler, el.id())) { selectionHandler.add(el);//from ww w .jav a2s .co m } } }
From source file:org.opens.tanaguru.rules.rgaa22.Rgaa22Rule03101.java
@Override protected void select(SSPHandler sspHandler, ElementHandler<Element> elementHandler) { ELEMENT_SELECTOR.selectElements(sspHandler, elementHandler); if (elementHandler.isEmpty()) { return;/* ww w . j av a 2s . co m*/ } // From the selected form elements, only keep the one without id // or with an id not unique on the page for (Element el : elementHandler.get()) { if (!el.hasAttr(ID_ATTR) || StringUtils.isEmpty(el.id().trim()) || CssLikeSelectorBuilder .getNumberOfElements(sspHandler, CssLikeSelectorBuilder.buildSelectorFromId(el.id())) >= 2) { elementsWithoutUniqueId.add(el); } } }