@Test void testPseudoInput() { String html = readFile("pseudoInput.html"); String htmlOK = readFile("pseudoInput-ok.html"); Jerry doc = jerry(html); Jerry allInputs = doc.$(":input"); Jerry formChildren = doc.$("form > *"); doc.$("#messages").text("Found " + allInputs.length() + " inputs and the form has " + formChildren.length() + " children."); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testSibling2() { String html = readFile("sibling2.html"); String htmlOK = readFile("sibling2-ok.html"); Jerry doc = jerry(html); int len = doc.$(".hilite").siblings().css("color", "red").length(); doc.$("b").text(String.valueOf(len)); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testFilter2() { String html = readFile("filter2.html"); String htmlOK = readFile("filter2-ok.html"); Jerry doc = jerry(html); doc.$("li").filter(($this, index) -> Jerry.$("strong", $this).length() == 1).css("background-color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testHas2() { String html = readFile("has2.html"); String htmlOK = readFile("has2-ok.html"); Jerry doc = jerry(html); doc.$("li").has("ul").css("background-color", "red"); doc.$( "ul" ).append( "<li>" + ( doc.$( "ul" ).has( "li" ).length() > 0 ? "Yes" : "No" ) + "</li>" ); doc.$( "ul" ).has( "li" ).addClass( "full" ); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoButton() { String html = readFile("pseudoButton.html"); String htmlOK = readFile("pseudoButton-ok.html"); Jerry doc = jerry(html); Jerry input = doc.$(":button").css("background", "yellow", "border", "3px red solid"); doc.$("div").text("For this type jQuery found " + input.length() + ".").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testChildrenVsContents() { String html = readFile("contents.html"); String htmlOK = readFile("contents-ok.html"); Jerry doc = jerry(html); doc.$("span.contents").contents().remove(); doc.$("span.children").children().remove(); int count = doc.$(".count").contents().length(); doc.$(".count").text(Integer.toString(count)); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoFile() { String html = readFile("pseudoFile.html"); String htmlOK = readFile("pseudoFile-ok.html"); Jerry doc = jerry(html); Jerry input = doc.$("form input:file").css("background", "yellow", "border", "3px red solid"); doc.$("div").text("For this type jQuery found " + input.length() + ".").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testPseudoCheckbox() { String html = readFile("pseudoCheckbox.html"); String htmlOK = readFile("pseudoCheckbox-ok.html"); Jerry doc = jerry(html); Jerry input = doc.$("form input:checkbox").wrap("<span></span>").parent().css("background", "yellow", "border", "3px red solid"); doc.$("div").text("For this type jQuery found " + input.length() + ".").css("color", "red"); assertEquals(htmlOK, actualHtml(doc)); }
@Test void testHtmlAll() { Jerry j = Jerry.jerry("<div><span>1</span></div><div><span>2</span></div>"); assertEquals(j.htmlAll(true), j.htmlAll(false)); j = j.$("div"); assertEquals("<span>1</span>", j.html()); assertEquals("<span>1</span><span>2</span>", j.htmlAll(false)); assertEquals("<div><span>1</span></div><div><span>2</span></div>", j.htmlAll(true)); Jerry j2 = j.find("span"); assertEquals(2, j2.length()); assertEquals("12", j2.text()); assertEquals("1", j2.html()); assertEquals("12", j2.htmlAll(false)); assertEquals("<span>1</span><span>2</span>", j2.htmlAll(true)); }
/** * Updates the copyright dates in the given file. */ @Override public void handleFile(File htmlFile) { if(jerryParser == null){ jerryParser = Jerry.jerry().enableHtmlMode(); jerryParser.getDOMBuilder().setCaseSensitive(false); jerryParser.getDOMBuilder().setParseSpecialTagsAsCdata(true); jerryParser.getDOMBuilder().setSelfCloseVoidTags(false); jerryParser.getDOMBuilder().setConditionalCommentExpression(null); jerryParser.getDOMBuilder().setEnableConditionalComments(false); jerryParser.getDOMBuilder().setImpliedEndTags(false); } log.trace("Handling file {}", htmlFile); try { String fileContents = FileUtils.readFileToString(htmlFile); Jerry html = jerryParser.parse(fileContents); Jerry selector = html.$("[data-cadmium='copyright']"); log.debug("Found {} copyright tags.", selector.length()); if(selector.length() > 0) { selector.text(year.toString()); log.trace("Writing updated file {}",htmlFile); FileUtils.writeStringToFile(htmlFile, html.html(), false); } } catch(Throwable t) { log.warn("Failed to update file "+htmlFile, t); } }
Jerry html = jerryParser.parse(ipAddress); Jerry ipNode = html.$("#greenip"); if(ipNode.length() == 1) { ipAddress = ipNode.text(); } else {