Search in sources :

Example 1 with JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL

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 "/";
    }
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL) JS_ANCHOR_PROTOCOL_HTTP_FOR_BROKEN_URL(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_HTTP_FOR_BROKEN_URL) JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL) JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL) JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL) JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL(com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Aggregations

JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL)1 JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL)1 JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL)1 JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL)1 JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL)1 JS_ANCHOR_PROTOCOL_HTTP_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_HTTP_FOR_BROKEN_URL)1 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)1 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1