use of com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL in project htmlunit by HtmlUnit.
the class HTMLAnchorElement method getPathname.
/**
* Returns the pathname portion of the link's URL.
* @return the pathname portion of the link's URL
* @see <a href="http://msdn.microsoft.com/en-us/library/ms534332.aspx">MSDN Documentation</a>
*/
@JsxGetter
public String getPathname() {
try {
final URL url = getUrl();
if (!url.getProtocol().startsWith("http") && getBrowserVersion().hasFeature(JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL)) {
return "";
}
if (getBrowserVersion().hasFeature(JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL)) {
final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
String href = anchor.getHrefAttribute();
if (href.length() > 1 && Character.isLetter(href.charAt(0)) && ':' == href.charAt(1)) {
if (getBrowserVersion().hasFeature(JS_ANCHOR_PROTOCOL_COLON_UPPER_CASE_DRIVE_LETTERS)) {
href = StringUtils.capitalize(href);
}
if (getBrowserVersion().hasFeature(JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL)) {
href = "/" + href;
}
return href;
}
}
return url.getPath();
} catch (final MalformedURLException e) {
final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
if (anchor.getHrefAttribute().startsWith("http") && getBrowserVersion().hasFeature(JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL)) {
return "";
}
return "/";
}
}
Aggregations