List of usage examples for org.jsoup.nodes Element parent
@Override public final Element parent()
From source file:com.dalthed.tucan.scraper.SingleEventScraper.java
@Override public ListAdapter scrapeAdapter(int mode) throws LostSessionException, TucanDownException { if (checkForLostSeesion()) { if (PREPCall == false) { if (checkforModule()) { return null; }/* ww w .j av a 2 s .c o m*/ String Title = doc.select("h1").text().replace("\n", " "); if (fsh != null) { fsh.setSubtitle(Title); } Iterator<Element> captionIt = doc.select("caption").iterator(); Iterator<Element> dateTable = null; Iterator<Element> materialTable = null; Iterator<Element> informationTable = null; while (captionIt.hasNext()) { Element next = captionIt.next(); if (next.text().equals("Termine")) { dateTable = next.parent().select("tr").iterator(); } else if (next.text().contains("Material")) { materialTable = next.parent().select("tr").iterator(); } else if (next.text().contains("Veranstaltungsdetails")) { informationTable = next.parent().select("tr").iterator(); } } scrapeInformations(informationTable); scrapeAppointments(dateTable); scrapeMaterials(materialTable); if (mPageAdapter != null) { mPageAdapter.initializeData(mPager); } } else { // Es handelt sich um eine bersichtsseite zu einem einzelnen // Termin callRealEventPage(); } } return null; }
From source file:org.asqatasun.rules.elementselector.InputFormElementWithInplicitLabelSelector.java
@Override public void selectElements(SSPHandler sspHandler, ElementHandler<Element> selectionHandler) { for (Element el : getElements(sspHandler)) { if (StringUtils.equalsIgnoreCase(el.parent().nodeName(), LABEL_ELEMENT)) { selectionHandler.add(el);/*from w w w. j a v a 2s. c o m*/ } } }
From source file:org.asqatasun.rules.elementselector.LinkElementSelector.java
/** * /* w w w. ja v a 2 s .co m*/ * @param linkElement * @param linkText * @return whether the current link have a context */ protected boolean doesLinkHaveContext(Element linkElement, String linkText) { // does the current link have a title attribute? if (considerTitleAsContext && linkElement.hasAttr(TITLE_ATTR) && !StringUtils.equalsIgnoreCase(linkElement.attr(TITLE_ATTR), linkText)) { return true; } if (linkElement.hasAttr(ARIA_LABEL_ATTR) && StringUtils.isNotBlank(linkElement.attr(ARIA_LABEL_ATTR))) { return true; } if (linkElement.hasAttr(ARIA_LABELLEDBY_ATTR) && StringUtils.isNotBlank(linkElement.attr(ARIA_LABELLEDBY_ATTR))) { return true; } // does the parent of the current link have some text? if (StringUtils.isNotBlank(linkElement.parent().ownText())) { return true; } // does the current element have a previous sibling of heading type? if (isOneOfPrecedingSiblingofHeadingType(linkElement)) { return true; } // does one of the parent of the current element have a previous sibling // of heading type or is found in the PARENT_CONTEXT_ELEMENTS list? for (Element parent : linkElement.parents()) { if (PARENT_CONTEXT_ELEMENTS.contains(parent.tagName()) || isOneOfPrecedingSiblingofHeadingType(parent)) { return true; } } return false; }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule110102.java
/** * This method linked each input on a page to its form in a map. *//* w ww. j av a 2 s . c om*/ private void putInputElementHandlerIntoTheMap() { for (Element el : inputElementHandler.get()) { if (!el.hasAttr(TITLE_ATTR) && !el.hasAttr(ARIA_LABEL_ATTR) && !el.hasAttr(ARIA_LABELLEDBY_ATTR)) { Element tmpElement = el.parent(); while (StringUtils.isNotBlank(tmpElement.tagName())) { if (tmpElement.tagName().equals(FORM_ELEMENT)) { if (inputFormMap.containsKey(tmpElement)) { inputFormMap.get(tmpElement).add(el); } else { ElementHandler<Element> inputElement = new ElementHandlerImpl(); inputElement.add(el); inputFormMap.put(tmpElement, inputElement); } break; } tmpElement = tmpElement.parent(); } } } }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule110102.java
/** * This method linked each label which have an input child on a page to its * form in a map.//from w w w . j a v a2s . c o m */ private void putLabelElementHandlerIntoTheMap() { for (Element el : labelElementHandler.get()) { Element tmpElement = el.parent(); while (tmpElement != null && StringUtils.isNotBlank(tmpElement.tagName())) { if (tmpElement.tagName().equals(FORM_ELEMENT)) { if (labelFormMap.containsKey(tmpElement)) { Elements els = el.select(FORM_ELEMENT_WITH_ID_CSS_LIKE_QUERY); if (!els.isEmpty()) { labelFormMap.get(tmpElement).add(el); } } else { Elements els = el.select(FORM_ELEMENT_WITH_ID_CSS_LIKE_QUERY); if (!els.isEmpty()) { ElementHandler<Element> labelElement = new ElementHandlerImpl(); labelElement.add(el); labelFormMap.put(tmpElement, labelElement); } } break; } tmpElement = tmpElement.parent(); } } }
From source file:org.asqatasun.rules.rgaa30.Rgaa30Rule110103.java
/** * This method linked each input on a page to its form in a map. *///w w w .ja va2s . c o m private void putInputElementHandlerIntoTheMap() { for (Element el : inputElementHandler.get()) { Element tmpElement = el.parent(); while (StringUtils.isNotBlank(tmpElement.tagName())) { if (tmpElement.tagName().equals(FORM_ELEMENT)) { if (inputFormMap.containsKey(tmpElement)) { inputFormMap.get(tmpElement).add(el); } else { ElementHandler<Element> inputElement = new ElementHandlerImpl(); inputElement.add(el); inputFormMap.put(tmpElement, inputElement); } break; } tmpElement = tmpElement.parent(); } } }
From source file:org.neo4j.browser.CannedCypherExecutionTest.java
@Test public void shouldBeAbleToExecuteAllTheCannedCypherQueriesContainedInStaticHtmlFiles() throws Exception { URL resourceLoc = getClass().getClassLoader().getResource("browser"); assertNotNull(resourceLoc);//from ww w.j ava 2 s . c om final AtomicInteger explainCount = new AtomicInteger(0); final AtomicInteger executionCount = new AtomicInteger(0); Files.walkFileTree(Paths.get(resourceLoc.toURI()), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException { final GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase(); String fileName = file.getFileName().toString(); if (fileName.endsWith(".html")) { String content = FileUtils.readTextFile(file.toFile(), Charsets.UTF_8); Elements cypherElements = Jsoup.parse(content).select("pre.runnable") .not(".standalone-example"); for (Element cypherElement : cypherElements) { String statement = replaceAngularExpressions(cypherElement.text()); if (!statement.startsWith(":")) { if (shouldExplain(statement)) { try (Transaction transaction = database.beginTx()) { Iterable<Notification> actual = database.execute(prependExplain(statement)) .getNotifications(); boolean skipKnownInefficientCypher = !cypherElement.parent().select(".warn") .isEmpty(); if (skipKnownInefficientCypher) { List<Notification> targetCollection = new ArrayList<Notification>(); CollectionUtils.addAll(targetCollection, actual); CollectionUtils.filter(targetCollection, new org.apache.commons.collections4.Predicate<Notification>() { @Override public boolean evaluate(Notification notification) { return notification.getDescription() .contains(NotificationCode.CARTESIAN_PRODUCT .values().toString()); } }); assertThat( format("Query [%s] should only produce cartesian product " + "notifications. [%s]", statement, fileName), targetCollection, empty()); explainCount.incrementAndGet(); transaction.success(); } else { assertThat(format("Query [%s] should produce no notifications. [%s]", statement, fileName), actual, is(emptyIterable())); explainCount.incrementAndGet(); transaction.success(); } } catch (QueryExecutionException e) { throw new AssertionError( format("Failed to explain query [%s] in file [%s]", statement, file), e); } } try (Transaction transaction = database.beginTx()) { database.execute(statement); executionCount.incrementAndGet(); transaction.success(); } catch (QueryExecutionException e) { throw new AssertionError( format("Failed to execute query [%s] in file [%s]", statement, file), e); } } } } return FileVisitResult.CONTINUE; } }); assertTrue("Static files should contain at least one valid cypher statement", executionCount.intValue() >= 1); System.out.printf("Explained %s cypher statements extracted from HTML files, with no notifications.%n", explainCount); System.out.printf("Executed %s cypher statements extracted from HTML files, with no errors.%n", executionCount); }
From source file:org.opens.tanaguru.rules.elementselector.InputFormElementWithInplicitLabelSelector.java
@Override public void selectElements(SSPHandler sspHandler, ElementHandler selectionHandler) { for (Element el : getElements(sspHandler)) { if (StringUtils.equalsIgnoreCase(el.parent().nodeName(), LABEL_ELEMENT)) { selectionHandler.add(el);//from w w w .j av a 2 s .com } } }
From source file:org.opens.tanaguru.rules.elementselector.LinkElementSelector.java
/** * /*w w w . j ava 2s . c om*/ * @param linkElement * @param linkText * @return whether the current link have a context */ protected boolean doesLinkHaveContext(Element linkElement, String linkText) { // does the current link have a title attribute? if (considerTitleAsContext && linkElement.hasAttr(TITLE_ATTR) && !StringUtils.equals(linkElement.attr(TITLE_ATTR), linkText)) { return true; } // does the parent of the current link have some text? if (StringUtils.isNotBlank(linkElement.parent().ownText())) { return true; } // does the current element have a previous sibling of heading type? if (isOneOfPrecedingSiblingofHeadingType(linkElement)) { return true; } // does one of the parent of the current element have a previous sibling // of heading type or is found in the PARENT_CONTEXT_ELEMENTS list? for (Element parent : linkElement.parents()) { if (PARENT_CONTEXT_ELEMENTS.contains(parent.tagName()) || isOneOfPrecedingSiblingofHeadingType(parent)) { return true; } } return false; }
From source file:org.opens.tanaguru.rules.rgaa30.Rgaa30Rule110102.java
/** * This method linked each input on a page to its form in a map. *//*w w w . j a v a2 s .c o m*/ private void putInputElementHandlerIntoTheMap() { for (Element el : inputElementHandler.get()) { if (!el.hasAttr(TITLE_ATTR) && !el.hasAttr(ARIA_LABEL_ATTR) && !el.hasAttr(ARIA_LABELLEDBY_ATTR)) { Element tmpElement = el.parent(); while (StringUtils.isNotBlank(tmpElement.tagName())) { if (tmpElement.tagName().equals(FORM_TAG)) { if (inputFormMap.containsKey(tmpElement)) { inputFormMap.get(tmpElement).add(el); } else { ElementHandler<Element> inputElement = new ElementHandlerImpl(); inputElement.add(el); inputFormMap.put(tmpElement, inputElement); } break; } tmpElement = tmpElement.parent(); } } } }