Search in sources :

Example 16 with JsxSetter

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

the class HTMLStyleElement method setDisabled.

/**
 * Sets the {@code disabled} property.
 * @param disabled the {@code disabled} property
 */
@Override
@JsxSetter
public void setDisabled(final boolean disabled) {
    final CSSStyleSheet sheet = getSheet();
    final boolean modified = disabled == sheet.isEnabled();
    sheet.setEnabled(!disabled);
    if (modified) {
        getDomNodeOrDie().getPage().clearComputedStyles();
    }
}
Also used : CSSStyleSheet(com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 17 with JsxSetter

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

the class HTMLElement method setInnerText.

/**
 * Replaces all child elements of this element with the supplied text value.
 * (see https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute)
 * @param value the new value for the contents of this element
 */
@JsxSetter
public void setInnerText(final Object value) {
    final String valueString;
    if (value == null && getBrowserVersion().hasFeature(JS_INNER_TEXT_VALUE_NULL)) {
        valueString = null;
    } else {
        valueString = Context.toString(value);
    }
    final DomNode domNode = getDomNodeOrDie();
    final SgmlPage page = domNode.getPage();
    domNode.removeAllChildren();
    if (StringUtils.isNotEmpty(valueString)) {
        final String[] parts = valueString.split("\\r?\\n");
        for (int i = 0; i < parts.length; i++) {
            if (i != 0) {
                domNode.appendChild(page.createElement(HtmlBreak.TAG_NAME));
            }
            domNode.appendChild(new DomText(page, parts[i]));
        }
    }
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomText(com.gargoylesoftware.htmlunit.html.DomText) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 18 with JsxSetter

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

the class HTMLAnchorElement method setUsername.

/**
 * Sets the {@code username} attribute.
 * @param username {@code username} attribute
 */
@JsxSetter({ CHROME, EDGE, FF, FF_ESR })
public void setUsername(final String username) {
    try {
        final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
        final String href = anchor.getHrefAttribute();
        if (ATTRIBUTE_NOT_DEFINED == href) {
            return;
        }
        final URL url = ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(href);
        setUrl(UrlUtils.getUrlWithNewUserName(url, username));
    } catch (final MalformedURLException e) {
    // ignore
    }
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) MalformedURLException(java.net.MalformedURLException) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) 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) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 19 with JsxSetter

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

the class HTMLAnchorElement method setPassword.

/**
 * Sets the {@code password} attribute.
 * @param password {@code password} attribute
 */
@JsxSetter({ CHROME, EDGE, FF, FF_ESR })
public void setPassword(final String password) {
    try {
        final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
        final String href = anchor.getHrefAttribute();
        if (ATTRIBUTE_NOT_DEFINED == href) {
            return;
        }
        final URL url = ((HtmlPage) anchor.getPage()).getFullyQualifiedUrl(href);
        setUrl(UrlUtils.getUrlWithNewUserPassword(url, password));
    } catch (final MalformedURLException e) {
    // ignore
    }
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) MalformedURLException(java.net.MalformedURLException) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) 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) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 20 with JsxSetter

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

the class HTMLAnchorElement method setHost.

/**
 * Sets the host portion of the link's URL (the '[hostname]:[port]' portion).
 * @param host the new host portion of the link's URL
 * @throws Exception if an error occurs
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms533784.aspx">MSDN Documentation</a>
 */
@JsxSetter
public void setHost(final String host) throws Exception {
    final String hostname;
    final int port;
    final int index = host.indexOf(':');
    if (index != -1) {
        hostname = host.substring(0, index);
        port = Integer.parseInt(host.substring(index + 1));
    } else {
        hostname = host;
        port = -1;
    }
    final URL url = UrlUtils.getUrlWithNewHostAndPort(getUrl(), hostname, port);
    setUrl(url);
}
Also used : 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) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Aggregations

JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)28 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)9 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 URL (java.net.URL)5 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)3 JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL)3 JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL)3 JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL)3 JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL)3 JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_COLON_FOR_BROKEN_URL)3 JS_ANCHOR_PROTOCOL_HTTP_FOR_BROKEN_URL (com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHOR_PROTOCOL_HTTP_FOR_BROKEN_URL)3 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)3 DomText (com.gargoylesoftware.htmlunit.html.DomText)3 MalformedURLException (java.net.MalformedURLException)3 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlOption (com.gargoylesoftware.htmlunit.html.HtmlOption)2 HtmlStyle (com.gargoylesoftware.htmlunit.html.HtmlStyle)2 ProxyDomNode (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.ProxyDomNode)2