public Element(final Document ownerNode, final Tag tag, final boolean voidElement, final boolean selfClosed) { super(ownerNode, NodeType.ELEMENT, Util.toString(tag.getName())); this.voidElement = voidElement; this.selfClosed = selfClosed; this.rawTag = tag.isRawTag(); int attrCount = tag.getAttributeCount(); for (int i = 0; i < attrCount; i++) { String key = Util.toString(tag.getAttributeName(i)); String value = Util.toString(tag.getAttributeValue(i)); setAttribute(key, value); } }
@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")); } }
@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 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 testEncode() { LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder(); Document document = lagartoDOMBuilder.parse("<div foo=\"q w\">a<b</div>"); Element div = (Element) document.getFirstChild(); String foo = div.getAttribute("foo"); assertEquals("q\u00A0w", foo); div.setAttribute("foo", "q\u00A0w\u00A0e"); assertEquals("<div foo=\"q w e\">a<b</div>", document.getHtml()); Text text = (Text) document.getFirstChild().getFirstChild(); assertEquals("a<b", text.getNodeValue()); assertEquals("a<b", text.getTextContent()); assertEquals("a<b", text.getTextValue()); assertTrue(document.check()); }
public Element(Tag tag, boolean voidElement, boolean selfClosed, boolean caseSensitive) { super(NodeType.ELEMENT, tag.getName(), caseSensitive); this.voidElement = voidElement; this.selfClosed = selfClosed; int attrCount = tag.getAttributeCount(); for (int i = 0; i < attrCount; i++) { String key = tag.getAttributeName(i); String value = tag.getAttributeValue(i); setAttribute(key, value); } }
public Element(final Document ownerNode, final Tag tag, final boolean voidElement, final boolean selfClosed) { super(ownerNode, NodeType.ELEMENT, Util.toString(tag.getName())); this.voidElement = voidElement; this.selfClosed = selfClosed; this.rawTag = tag.isRawTag(); int attrCount = tag.getAttributeCount(); for (int i = 0; i < attrCount; i++) { String key = Util.toString(tag.getAttributeName(i)); String value = Util.toString(tag.getAttributeValue(i)); setAttribute(key, value); } }
public Element(Document ownerNode, Tag tag, boolean voidElement, boolean selfClosed) { super(ownerNode, NodeType.ELEMENT, Util.toString(tag.getName())); this.voidElement = voidElement; this.selfClosed = selfClosed; this.rawTag = tag.isRawTag(); int attrCount = tag.getAttributeCount(); for (int i = 0; i < attrCount; i++) { String key = Util.toString(tag.getAttributeName(i)); String value = Util.toString(tag.getAttributeValue(i)); setAttribute(key, value); } }