Node implements Cloneable { public String absUrl(String attributeKey) { Validate.notEmpty(attributeKey); if (!hasAttr(attributeKey)) { return ""; } else { return StringUtil.resolve(baseUri, attr(attributeKey)); } } protected  Node(String baseUri, Attributes attributes); protected  Node(String baseUri); protected  Node(); abstract String nodeName(); String attr(String attributeKey); Attributes attributes(); Node attr(String attributeKey, String attributeValue); boolean hasAttr(String attributeKey); Node removeAttr(String attributeKey); String baseUri(); void setBaseUri(final String baseUri); String absUrl(String attributeKey); Node childNode(int index); List<Node> childNodes(); List<Node> childNodesCopy(); final int childNodeSize(); Node parent(); final Node parentNode(); Document ownerDocument(); void remove(); Node before(String html); Node before(Node node); Node after(String html); Node after(Node node); Node wrap(String html); Node unwrap(); void replaceWith(Node in); List<Node> siblingNodes(); Node nextSibling(); Node previousSibling(); int siblingIndex(); Node traverse(NodeVisitor nodeVisitor); String outerHtml(); Appendable html(Appendable appendable); String toString(); @Override boolean equals(Object o); boolean hasSameValue(Object o); @Override Object clone();  }
@Test public void handlesBaseUri() { Tag tag = Tag.valueOf("a"); Attributes attribs = new Attributes(); attribs.put("relHref", "/foo"); attribs.put("absHref", "http: Element noBase = new Element(tag, "", attribs); assertEquals("", noBase.absUrl("relHref")); assertEquals("http: Element withBase = new Element(tag, "http: assertEquals("http: assertEquals("http: assertEquals("", withBase.absUrl("noval")); Element dodgyBase = new Element(tag, "wtf: assertEquals("http: }
@Test public void handlesBaseUriBaseFails() { Tag tag = Tag.valueOf("a"); Attributes attribs = new Attributes(); attribs.put("relHref", "/foo"); attribs.put("absHref", "http: Element dodgyBase = new Element(tag, "wtf: assertEquals("", dodgyBase.absUrl("relHref")); }
@Test public void handleAbsOnFileUris() { Document doc = Jsoup.parse("<a href='password'>One/a><a href='/var/log/messages'>Two</a>", "file:/etc/"); Element one = doc.select("a").first(); assertEquals("file:/etc/password", one.absUrl("href")); Element two = doc.select("a").get(1); assertEquals("file:/var/log/messages", two.absUrl("href")); }
@Test public void handleAbsOnLocalhostFileUris() { Document doc = Jsoup.parse("<a href='password'>One/a><a href='/var/log/messages'>Two</a>", "file: Element one = doc.select("a").first(); assertEquals("file: }
@Test public void absHandlesRelativeQuery() { Document doc = Jsoup.parse("<a href='?foo'>One</a> <a href='bar.html?foo'>Two</a>", "http: Element a1 = doc.select("a").first(); assertEquals("http: Element a2 = doc.select("a").get(1); assertEquals("http: }
@Test public void absHandlesDotFromIndex() { Document doc = Jsoup.parse("<a href='./one/two.html'>One</a>", "http: Element a1 = doc.select("a").first(); assertEquals("http: }