Search in sources :

Example 6 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter 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)

Example 7 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.

the class HTMLAnchorElement method getHref.

/**
 * Returns the value of this link's {@code href} property.
 * @return the value of this link's {@code href} property
 */
@JsxGetter
public String getHref() {
    final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
    final String hrefAttr = anchor.getHrefAttribute();
    if (ATTRIBUTE_NOT_DEFINED == hrefAttr) {
        return "";
    }
    try {
        return getUrl().toString();
    } catch (final MalformedURLException e) {
        return hrefAttr;
    }
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) MalformedURLException(java.net.MalformedURLException) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 8 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.

the class HTMLInputElement method getValue.

/**
 * Returns the value of the JavaScript attribute {@code value}.
 *
 * @return the value of this attribute
 */
@JsxGetter
@Override
public String getValue() {
    final HtmlInput htmlInput = getDomNodeOrDie();
    if (htmlInput instanceof HtmlFileInput) {
        final File[] files = ((HtmlFileInput) htmlInput).getFiles();
        if (files == null || files.length == 0) {
            return ATTRIBUTE_NOT_DEFINED;
        }
        final File first = files[0];
        final String name = first.getName();
        if (name.isEmpty()) {
            return name;
        }
        return "C:\\fakepath\\" + name;
    }
    if (htmlInput instanceof HtmlNumberInput) {
        final HtmlNumberInput htmlNumberInput = (HtmlNumberInput) htmlInput;
        final String valueAttr = htmlInput.getAttributeDirect("value");
        if (!valueAttr.isEmpty()) {
            if ("-".equals(valueAttr) || "+".equals(valueAttr)) {
                return "";
            }
            final int lastPos = valueAttr.length() - 1;
            if (lastPos >= 0 && valueAttr.charAt(lastPos) == '.') {
                if (htmlNumberInput.hasFeature(JS_INPUT_NUMBER_DOT_AT_END_IS_DOUBLE)) {
                    return "";
                }
            }
            try {
                Double.parseDouble(valueAttr);
            } catch (final NumberFormatException e) {
                return "";
            }
        }
    }
    return htmlInput.getAttributeDirect("value");
}
Also used : HtmlFileInput(com.gargoylesoftware.htmlunit.html.HtmlFileInput) HtmlNumberInput(com.gargoylesoftware.htmlunit.html.HtmlNumberInput) HtmlInput(com.gargoylesoftware.htmlunit.html.HtmlInput) File(java.io.File) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 9 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.

the class HTMLLabelElement method getControl.

/**
 * @return the HTMLElement labeled by the given label object
 */
@JsxGetter({ CHROME, EDGE, FF, FF_ESR })
public HTMLElement getControl() {
    final HtmlLabel label = (HtmlLabel) getDomNodeOrDie();
    final HtmlElement labeledElement = label.getLabeledElement();
    if (labeledElement == null) {
        return null;
    }
    return (HTMLElement) getScriptableFor(labeledElement);
}
Also used : HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 10 with JsxGetter

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.

the class HTMLLabelElement method getForm.

/**
 * Returns the value of the JavaScript {@code form} attribute.
 *
 * @return the value of the JavaScript {@code form} attribute
 */
@JsxGetter
@Override
public HTMLFormElement getForm() {
    if (getBrowserVersion().hasFeature(JS_LABEL_FORM_OF_SELF)) {
        final HtmlForm form = getDomNodeOrDie().getEnclosingForm();
        if (form == null) {
            return null;
        }
        return (HTMLFormElement) getScriptableFor(form);
    }
    final HtmlLabel label = (HtmlLabel) getDomNodeOrDie();
    final HtmlElement labeledElement = label.getLabeledElement();
    if (labeledElement == null) {
        return null;
    }
    final HtmlForm form = labeledElement.getEnclosingForm();
    if (form == null) {
        return null;
    }
    return (HTMLFormElement) getScriptableFor(form);
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Aggregations

JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)64 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)15 MalformedURLException (java.net.MalformedURLException)8 URL (java.net.URL)8 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)4 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)4 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)4 ComputedCSSStyleDeclaration (com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration)4 MediaListImpl (com.gargoylesoftware.css.dom.MediaListImpl)3 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)3 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)3 HtmlTableRow (com.gargoylesoftware.htmlunit.html.HtmlTableRow)3 HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)3 JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL)2 JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL)2 JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL)2 JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL)2 JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL)2