use of com.gargoylesoftware.htmlunit.html.HtmlLink in project htmlunit by HtmlUnit.
the class HTMLLinkElement method getHref.
/**
* Returns the value of the href property.
* @return the href property
*/
@JsxGetter
public String getHref() {
final HtmlLink link = (HtmlLink) getDomNodeOrDie();
final String href = link.getHrefAttribute();
if (href.isEmpty()) {
return href;
}
try {
return ((HtmlPage) link.getPage()).getFullyQualifiedUrl(href).toString();
} catch (final MalformedURLException e) {
return href;
}
}
use of com.gargoylesoftware.htmlunit.html.HtmlLink in project htmlunit by HtmlUnit.
the class CSSStyleSheet method getHref.
/**
* Returns the URL of the stylesheet.
* @return the URL of the stylesheet
*/
@JsxGetter
public String getHref() {
if (ownerNode_ != null) {
final DomNode node = ownerNode_.getDomNodeOrDie();
if (node instanceof HtmlStyle) {
return null;
}
if (node instanceof HtmlLink) {
// <link rel="stylesheet" type="text/css" href="..." />
final HtmlLink link = (HtmlLink) node;
final String href = link.getHrefAttribute();
if ("".equals(href) && getBrowserVersion().hasFeature(STYLESHEET_HREF_EMPTY_IS_NULL)) {
return null;
}
// Expand relative URLs.
try {
final HtmlPage page = (HtmlPage) link.getPage();
final URL url = page.getFullyQualifiedUrl(href);
return url.toExternalForm();
} catch (final MalformedURLException e) {
// Log the error and fall through to the return values below.
LOG.warn(e.getMessage(), e);
}
}
}
return getUri();
}
use of com.gargoylesoftware.htmlunit.html.HtmlLink in project htmlunit by HtmlUnit.
the class CSSStyleSheet method isActive.
/**
* Returns {@code true} if this stylesheet is active, based on the media types it is associated with (if any).
* @return {@code true} if this stylesheet is active, based on the media types it is associated with (if any)
*/
public boolean isActive() {
final String media;
final HtmlElement e = ownerNode_.getDomNodeOrNull();
if (e instanceof HtmlStyle) {
final HtmlStyle style = (HtmlStyle) e;
media = style.getMediaAttribute();
} else if (e instanceof HtmlLink) {
final HtmlLink link = (HtmlLink) e;
media = link.getMediaAttribute();
} else {
return true;
}
if (StringUtils.isBlank(media)) {
return true;
}
final WebClient webClient = getWindow().getWebWindow().getWebClient();
final MediaListImpl mediaList = parseMedia(webClient.getCssErrorHandler(), media);
return isActive(this, mediaList);
}
use of com.gargoylesoftware.htmlunit.html.HtmlLink in project htmlunit by HtmlUnit.
the class StyleSheetList method isActiveStyleSheetLink.
/**
* Verifies if the provided node is a link node pointing to an active stylesheet.
*
* @param domNode the mode to check
* @return true if the provided node is a stylesheet link
*/
boolean isActiveStyleSheetLink(final DomNode domNode) {
if (domNode instanceof HtmlLink) {
final HtmlLink link = (HtmlLink) domNode;
if (link.isStyleSheetLink()) {
final String media = link.getMediaAttribute();
if (StringUtils.isBlank(media)) {
return true;
}
final WebClient webClient = getWindow().getWebWindow().getWebClient();
final MediaListImpl mediaList = CSSStyleSheet.parseMedia(webClient.getCssErrorHandler(), media);
return CSSStyleSheet.isActive(this, mediaList);
}
}
return false;
}
use of com.gargoylesoftware.htmlunit.html.HtmlLink in project jenkins by jenkinsci.
the class LayoutTest method rejectedLinks.
@Issue("JENKINS-21254")
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
@Test
public void rejectedLinks() throws Exception {
JenkinsRule.WebClient wc = r.createWebClient();
String prefix = r.contextPath + '/';
for (DomElement e : wc.goTo("login").getElementsByTagName("link")) {
String href = ((HtmlLink) e).getHrefAttribute();
if (!href.startsWith(prefix)) {
System.err.println("ignoring " + href);
continue;
}
System.err.println("checking " + href);
wc.goTo(href.substring(prefix.length()), null);
}
}
Aggregations