List of usage examples for org.jsoup.nodes Element html
public String html()
From source file:org.apache.nifi.TestPutHTMLElement.java
@Test public void testPrependPElementToDiv() throws Exception { final String MOD_VALUE = "<p>modified value</p>"; testRunner.setProperty(PutHTMLElement.CSS_SELECTOR, "#put"); testRunner.setProperty(PutHTMLElement.PUT_LOCATION_TYPE, PutHTMLElement.PREPEND_ELEMENT); testRunner.setProperty(PutHTMLElement.PUT_VALUE, MOD_VALUE); testRunner.enqueue(new File("src/test/resources/Weather.html").toPath()); testRunner.run();// ww w . j a v a2 s .c om testRunner.assertTransferCount(PutHTMLElement.REL_SUCCESS, 1); testRunner.assertTransferCount(PutHTMLElement.REL_INVALID_HTML, 0); testRunner.assertTransferCount(PutHTMLElement.REL_ORIGINAL, 1); testRunner.assertTransferCount(PutHTMLElement.REL_NOT_FOUND, 0); List<MockFlowFile> ffs = testRunner.getFlowFilesForRelationship(PutHTMLElement.REL_SUCCESS); assertTrue(ffs.size() == 1); String data = new String(testRunner.getContentAsByteArray(ffs.get(0))); //Contents will be the entire HTML doc. So lets use Jsoup again just the grab the element we want. Document doc = Jsoup.parse(data); Elements eles = doc.select("#put"); Element ele = eles.get(0); assertTrue(StringUtils.equals("<p>modified value</p> \n<a href=\"httpd://localhost\"></a>", ele.html())); }
From source file:org.apache.nifi.TestPutHTMLElement.java
@Test public void testAppendPElementToDiv() throws Exception { final String MOD_VALUE = "<p>modified value</p>"; testRunner.setProperty(PutHTMLElement.CSS_SELECTOR, "#put"); testRunner.setProperty(PutHTMLElement.PUT_LOCATION_TYPE, PutHTMLElement.APPEND_ELEMENT); testRunner.setProperty(PutHTMLElement.PUT_VALUE, MOD_VALUE); testRunner.enqueue(new File("src/test/resources/Weather.html").toPath()); testRunner.run();/* ww w. j a v a2s. c o m*/ testRunner.assertTransferCount(PutHTMLElement.REL_SUCCESS, 1); testRunner.assertTransferCount(PutHTMLElement.REL_INVALID_HTML, 0); testRunner.assertTransferCount(PutHTMLElement.REL_ORIGINAL, 1); testRunner.assertTransferCount(PutHTMLElement.REL_NOT_FOUND, 0); List<MockFlowFile> ffs = testRunner.getFlowFilesForRelationship(PutHTMLElement.REL_SUCCESS); assertTrue(ffs.size() == 1); String data = new String(testRunner.getContentAsByteArray(ffs.get(0))); //Contents will be the entire HTML doc. So lets use Jsoup again just the grab the element we want. Document doc = Jsoup.parse(data); Elements eles = doc.select("#put"); Element ele = eles.get(0); assertTrue( StringUtils.equals("<a href=\"httpd://localhost\"></a> \n" + "<p>modified value</p>", ele.html())); }
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./* w ww.ja va 2s. c o m*/ * * @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
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 ww . ja va2 s .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();// w w w .j a v a 2 s . co m 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.seo.SeoRule08011.java
@Override protected void select(SSPHandler sspHandler) { ElementSelector es = new SimpleElementSelector(FLASH_CONTENT_CSS_LIKE_QUERY); es.selectElements(sspHandler, decidableElements); es = new SimpleElementSelector(SCRIPT_ELEMENT); es.selectElements(sspHandler, notDecidableElements); Iterator<Element> iter = notDecidableElements.get().iterator(); while (iter.hasNext()) { Element script = iter.next(); if (!StringUtils.contains(script.html(), SWF_EXT)) { iter.remove();// w ww. ja va2 s . c om } } }
From source file:org.b3log.solo.plugin.list.ListHandler.java
@Override public void action(final Event<JSONObject> event) throws EventException { final JSONObject data = event.getData(); final JSONObject article = data.optJSONObject(Article.ARTICLE); String content = article.optString(Article.ARTICLE_CONTENT); final Document doc = Jsoup.parse(content, StringUtils.EMPTY, Parser.htmlParser()); doc.outputSettings().prettyPrint(false); final StringBuilder listBuilder = new StringBuilder(); listBuilder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Latkes.getStaticServePath() + "/plugins/list/style.css\" />"); final Elements hs = doc.select("h1, h2, h3, h4, h5"); listBuilder.append("<ul class='b3-solo-list'>"); for (int i = 0; i < hs.size(); i++) { final Element element = hs.get(i); final String tagName = element.tagName().toLowerCase(); final String text = element.text(); final String id = "b3_solo_" + tagName + "_" + i; element.before("<span id='" + id + "'></span>"); listBuilder.append("<li class='b3-solo-list-").append(tagName).append("'><a href='#").append(id) .append("'>").append(text).append("</a></li>"); }/*from w w w.ja v a 2 s . c o m*/ listBuilder.append("</ul>"); final Element body = doc.getElementsByTag("body").get(0); content = listBuilder.toString() + body.html(); article.put(Article.ARTICLE_CONTENT, content); }
From source file:org.bonitasoft.web.designer.visitors.HtmlBuilderVisitorTest.java
@Test public void should_add_extra_modules_when_widgets_needs_them() throws Exception { Page page = aPage().build();/*from w ww . j a va2s. co m*/ when(requiredModulesVisitor.visit(page)).thenReturn(newHashSet("needed.module")); String html = visitor.build(page, ""); Element head = Jsoup.parse(html).head(); assertThat(head.html()).contains("angular.module('bonitasoft.ui').requires.push('needed.module');"); }
From source file:org.bonitasoft.web.designer.visitors.HtmlBuilderVisitorTest.java
@Test public void should_not_add_extra_modules_when_no_widgets_needs_them() throws Exception { Page page = aPage().build();/* www.j ava2 s . com*/ when(requiredModulesVisitor.visit(page)).thenReturn(Collections.<String>emptySet()); String html = visitor.build(page, ""); Element head = Jsoup.parse(html).head(); assertThat(head.html()).doesNotContain("angular.module('bonitasoft.ui').requires.push"); }
From source file:org.eclipse.mylyn.docs.examples.ImproveFormatting.java
private static void improveCodeFormatting(File in) throws IOException { String contents = new String(Files.readAllBytes(in.toPath())); // parse the file contents as XML and put it into a DOM Document parse = Jsoup.parse(contents, "UTF-8", Parser.xmlParser()); // obtain all the code sections we want to format Elements select = parse.select("pre[class=programlisting]"); for (Element element : select) { // get to the actual code String text = element.html(); // try to avoid xml and other code already formatted - we're not // able to handle that in this example if (!text.contains("<plugin>") && !text.contains("<span")) { // format all keywords by adding the "keyword" class String code = KEYWORDS.stream().reduce(text, (str, keyword) -> str.replaceAll(keyword + "(\\s|\\(|\\{|\\))", "<code class=\"keyword\">" + keyword + "</code>$1")); // replace the code with the coloured version element.html(code);// ww w .j a v a 2 s.c o m } } // write out the modified code FileWriter fw = new FileWriter(in); fw.write(parse.outerHtml()); fw.flush(); fw.close(); }