@Override public Element clone() { return cloneTo(new Element(ownerDocument, nodeName, voidElement, selfClosed, rawTag)); }
/** * Creates new element with correct configuration. */ protected Element createElementNode(final Tag tag) { boolean hasVoidTags = htmlVoidRules != null; boolean isVoid = false; boolean selfClosed = false; if (hasVoidTags) { isVoid = htmlVoidRules.isVoidTag(tag.getName()); // HTML and XHTML if (isVoid) { // it's void tag, lookup the flag selfClosed = domBuilder.config.isSelfCloseVoidTags(); } } else { // XML, no voids, lookup the flag selfClosed = domBuilder.config.isSelfCloseVoidTags(); } return new Element(rootNode, tag, isVoid, selfClosed); }
@Test void testCssPath() { Document document = new Document(); Element html = new Element(document, "html"); document.addChild(html); Element div1 = new Element(document, "div"); div1.setAttribute("id", "one"); html.addChild(div1); Element div2 = new Element(document, "div"); div1.addChild(div2); assertEquals("html div#one div", div2.getCssPath()); assertEquals("html div#one", div1.getCssPath()); assertTrue(document.check()); }
@Test void testDetach() { Document document = new Document(); Element html = new Element(document, "html"); document.addChild(html); Element div1 = new Element(document, "div"); html.addChild(div1); Element div2 = new Element(document, "div"); div1.addChild(div2); div1.detachFromParent(); assertEquals(0, html.getChildNodesCount()); assertNull(div1.getParentNode()); assertTrue(document.check()); }
@Test void testReindexOne() { Document document = new Document(); Element one = new Element(document, "one"); document.addChild(one); assertEquals(1, document.childElementNodesCount); assertEquals(0, one.siblingElementIndex); Element two = new Element(document, "two"); document.addChild(two); assertEquals(2, document.childElementNodesCount); assertEquals(0, one.siblingElementIndex); assertEquals(1, two.siblingElementIndex); Text three = new Text(document, "xxx"); document.addChild(three); Element four = new Element(document, "four"); document.addChild(four); assertEquals(3, document.childElementNodesCount); assertEquals(0, one.siblingElementIndex); assertEquals(1, two.siblingElementIndex); assertEquals(2, four.siblingElementIndex); }
@Test void testHasVsGet333() { Document document = new Document(); Element one = new Element(document, "one"); document.addChild(one); one.setAttribute("a1", "v1"); assertEquals("v1", one.getAttribute("a1")); assertEquals("v1", one.getAttribute("A1")); assertTrue(one.hasAttribute("a1")); assertTrue(one.hasAttribute("A1")); } }
Document document = new Document(); Element node = new Element(document, "div"); Element em = new Element(document, "em"); node.addChild(em); Text textJodd = new Text(document, "jodd"); assertEquals(1, node.getChildElementsCount("em")); Element b = new Element(document, "b"); node.addChild(b); Text textJodd2 = new Text(document, "fwk");
Document document = new Document(); Element html = new Element(document, "html"); document.addChild(html); Element div1 = new Element(document, "div"); html.addChild(div1); Element div2 = new Element(document, "div"); html.addChild(div2); Element div3 = new Element(document, "div"); html.addChild(div3);
@Test void testAttributes() { Document document = new Document(); Element node = new Element(document, "div"); assertFalse(node.hasAttributes()); assertFalse(node.hasAttribute("id")); assertNull(node.getAttribute("id")); node.setAttribute("id", "jodd"); assertTrue(node.hasAttributes()); assertTrue(node.hasAttribute("id")); assertEquals("jodd", node.getAttribute("id")); node.setAttribute("foo"); assertTrue(node.hasAttribute("foo")); assertNull(node.getAttribute("foo")); assertFalse(node.isAttributeContaining("class", "one")); node.setAttribute("class", " one two three "); assertTrue(node.isAttributeContaining("class", "two")); assertTrue(node.isAttributeContaining("class", "three")); assertEquals(3, node.getAttributesCount()); }
@Test void testSpecialCases() { Document document = new Document(); Element html = new Element(document, "html"); document.addChild(html); assertEquals(0, html.getChildNodesCount()); assertNull(html.getChild(0)); assertNull(html.getChild(1000)); assertEquals(0, html.getChildNodes().length); assertNull(html.getFirstChild()); assertNull(html.getFirstChildElement()); assertNull(html.getFirstChildElement("h1")); assertNull(html.getLastChild()); assertNull(html.getLastChildElement()); assertNull(html.getLastChildElement("h1")); assertEquals(0, html.getSiblingIndex()); assertEquals(0, html.getSiblingElementIndex()); assertEquals(0, html.getSiblingNameIndex()); assertTrue(document.check()); }
@Override public Element clone() { return cloneTo(new Element(ownerDocument, nodeName, voidElement, selfClosed, rawTag)); }
@Override public Element clone() { return cloneTo(new Element(ownerDocument, nodeName, voidElement, selfClosed, rawTag)); }
@Override public Element clone() { return cloneTo(new Element(nodeName, voidElement, selfClosed, caseSensitive)); }
/** * Creates new element with correct configuration. */ protected Element createElementNode(final Tag tag) { boolean hasVoidTags = htmlVoidRules != null; boolean isVoid = false; boolean selfClosed = false; if (hasVoidTags) { isVoid = htmlVoidRules.isVoidTag(tag.getName()); // HTML and XHTML if (isVoid) { // it's void tag, lookup the flag selfClosed = domBuilder.config.isSelfCloseVoidTags(); } } else { // XML, no voids, lookup the flag selfClosed = domBuilder.config.isSelfCloseVoidTags(); } return new Element(rootNode, tag, isVoid, selfClosed); }
/** * Creates new element with correct configuration. */ protected Element createElementNode(Tag tag) { boolean hasVoidTags = htmlVoidRules != null; boolean isVoid = false; boolean selfClosed = false; if (hasVoidTags) { isVoid = htmlVoidRules.isVoidTag(tag.getName()); // HTML and XHTML if (isVoid) { // it's void tag, lookup the flag selfClosed = domBuilder.config.isSelfCloseVoidTags(); } } else { // XML, no voids, lookup the flag selfClosed = domBuilder.config.isSelfCloseVoidTags(); } return new Element(rootNode, tag, isVoid, selfClosed); }
/** * Creates new element with correct configuration. */ protected Element createElementNode(Tag tag) { boolean isVoid = domBuilder.isVoidTag(tag.getName()); boolean selfClosed = false; if (domBuilder.hasVoidTags()) { // HTML ad XHTML if (isVoid) { // it's void tag, lookup the flag selfClosed = domBuilder.isSelfCloseVoidTags(); } } else { // XML, no voids, lookup the flag selfClosed = domBuilder.isSelfCloseVoidTags(); } Element element = new Element(tag, isVoid, selfClosed, domBuilder.isCaseSensitive()); if (domBuilder.isCalculatePosition()) { element.position = calculatePosition(tag); } return element; }