Java Code Examples for org.jsoup.nodes.Element#getElementsByAttributeValue()
The following examples show how to use
org.jsoup.nodes.Element#getElementsByAttributeValue() .
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
Source File: Utils.java From AlphaAlgorithm with MIT License | 6 votes |
/** * Parses an XES file and returns an event log as a Set of Traces. * * @param fileName location of XES file * @return a set of Traces, an event log * @throws IOException if errors occur while reading the XES file */ public static Set<Trace> parseXESFile(String fileName) throws IOException { Document doc = Jsoup.parse(new File(fileName), "UTF-8"); Elements traces = doc.getElementsByTag("trace"); Set<Trace> eventLog = new HashSet<>(); for (int i = 0; i < traces.size(); i++) { Element currentTrace = traces.get(i); Elements events = currentTrace.getElementsByTag("event"); Trace newTrace = new Trace(); for (int j = 0; j < events.size(); j++) { Element currentEvent = events.get(j); Elements name = currentEvent.getElementsByAttributeValue("key", "concept:name"); Element nameN = name.get(0); Elements lifec = currentEvent.getElementsByAttributeValue( "key", "lifecycle:transition"); Element lifc = lifec.get(0); Event ev = new Event(nameN.attr("value") + " " + lifc.attr("value")); newTrace.addEvent(ev); } eventLog.add(newTrace); } return eventLog; }
Example 2
Source File: WhenJavaExtensionIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void should_create_toc_with_treeprocessor() { asciidoctor.javaExtensionRegistry().treeprocessor(new Treeprocessor() { @Override public org.asciidoctor.ast.Document process(org.asciidoctor.ast.Document document) { List<StructuralNode> blocks = document.getBlocks(); for (StructuralNode block : blocks) { for (StructuralNode block2 : block.getBlocks()) { if (block2 instanceof Section) System.out.println(((Section) block2).getId()); } } return document; } }); String content = asciidoctor.convertFile( classpath.getResource("documentwithtoc.adoc"), options().headerFooter(true).toFile(false).safe(SafeMode.UNSAFE).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element toc = doc.getElementById("toc"); assertThat(toc, notNullValue()); Elements elements = toc.getElementsByAttributeValue("href", "#TestId"); assertThat(elements.size(), is(1)); }
Example 3
Source File: BootstrapHandler.java From flow with Apache License 2.0 | 5 votes |
private void handleInitialPageSettings(BootstrapContext context, Element head, InitialPageSettings initialPageSettings) { if (initialPageSettings.getViewport() != null) { Elements viewport = head.getElementsByAttributeValue("name", VIEWPORT); if (!viewport.isEmpty() && viewport.size() == 1) { viewport.get(0).attr(CONTENT_ATTRIBUTE, initialPageSettings.getViewport()); } else { head.appendElement(META_TAG).attr("name", VIEWPORT).attr( CONTENT_ATTRIBUTE, initialPageSettings.getViewport()); } } initialPageSettings.getInline(InitialPageSettings.Position.PREPEND) .stream() .map(dependency -> createDependencyElement(context, dependency)) .forEach(element -> insertElements(element, head::prependChild)); initialPageSettings.getInline(InitialPageSettings.Position.APPEND) .stream() .map(dependency -> createDependencyElement(context, dependency)) .forEach(element -> insertElements(element, head::appendChild)); initialPageSettings.getElement(InitialPageSettings.Position.PREPEND) .forEach(element -> insertElements(element, head::prependChild)); initialPageSettings.getElement(InitialPageSettings.Position.APPEND) .forEach(element -> insertElements(element, head::appendChild)); }
Example 4
Source File: BootstrapHandlerTest.java From flow with Apache License 2.0 | 5 votes |
@Test public void defaultViewport() { initUI(testUI); Document page = pageBuilder.getBootstrapPage(context); Element head = page.head(); Elements viewports = head.getElementsByAttributeValue("name", BootstrapHandler.VIEWPORT); Assert.assertEquals(1, viewports.size()); Element viewport = viewports.get(0); Assert.assertEquals(Viewport.DEFAULT, viewport.attr(BootstrapHandler.CONTENT_ATTRIBUTE)); }
Example 5
Source File: BootstrapHandlerTest.java From flow with Apache License 2.0 | 5 votes |
@Test public void viewportAnnotationOverridesDefault() throws Exception { initUI(testUI, createVaadinRequest(), Collections.singleton(RouteWithViewport.class)); Document page = pageBuilder.getBootstrapPage(context); Element head = page.head(); Elements viewports = head.getElementsByAttributeValue("name", BootstrapHandler.VIEWPORT); Assert.assertEquals(1, viewports.size()); Element viewport = viewports.get(0); Assert.assertEquals("viewport-annotation-value", viewport.attr(BootstrapHandler.CONTENT_ATTRIBUTE)); }
Example 6
Source File: BootstrapHandlerDependenciesTest.java From flow with Apache License 2.0 | 5 votes |
private void assertCssElementLoadedEagerly(Element head, String url) { Elements cssLinks = head.getElementsByAttributeValue("href", url); assertEquals(1, cssLinks.size()); Element linkElement = cssLinks.get(0); assertEquals("link", linkElement.tagName()); assertEquals("text/css", linkElement.attr("type")); assertEquals(url, linkElement.attr("href")); }
Example 7
Source File: BootstrapHandlerDependenciesTest.java From flow with Apache License 2.0 | 5 votes |
private void assertJavaScriptElementLoadedEagerly(Element head, String url) { Elements jsLinks = head.getElementsByAttributeValue("src", url); assertEquals(1, jsLinks.size()); Element linkElement = jsLinks.get(0); assertEquals("script", linkElement.tagName()); assertEquals("text/javascript", linkElement.attr("type")); assertEquals(url, linkElement.attr("src")); }
Example 8
Source File: BootstrapHandlerDependenciesTest.java From flow with Apache License 2.0 | 5 votes |
private void assertHtmlElementLoadedEagerly(Element head, String url) { Elements cssLinks = head.getElementsByAttributeValue("href", url); assertEquals(1, cssLinks.size()); Element linkElement = cssLinks.get(0); assertEquals("link", linkElement.tagName()); assertEquals("import", linkElement.attr("rel")); assertEquals(url, linkElement.attr("href")); }
Example 9
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void should_create_toc_with_treeprocessor() throws Exception { this.asciidoctor.createGroup() .treeprocessor(new Treeprocessor() { @Override public Document process(Document document) { List<StructuralNode> blocks=document.getBlocks(); for (StructuralNode block : blocks) { for (StructuralNode block2 : block.getBlocks()) { if(block2 instanceof Section) System.out.println(((Section) block2).getId()); } } return document; } }) .register(); String content = asciidoctor.convertFile( classpath.getResource("documentwithtoc.adoc"), options().headerFooter(true).toFile(false).safe(SafeMode.UNSAFE).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element toc = doc.getElementById("toc"); assertThat(toc, notNullValue()); Elements elements = toc.getElementsByAttributeValue("href", "#TestId"); assertThat(elements.size(), is(1)); }