Search in sources :

Example 1 with JsxSetter

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

the class TextRange method setText.

/**
 * Sets the text contained within the range.
 * @param text the text contained within the range
 */
@JsxSetter
public void setText(final String text) {
    if (range_.getStartContainer() == range_.getEndContainer() && range_.getStartContainer() instanceof SelectableTextInput) {
        final SelectableTextInput input = (SelectableTextInput) range_.getStartContainer();
        final String oldValue = input.getText();
        input.setText(oldValue.substring(0, input.getSelectionStart()) + text + oldValue.substring(input.getSelectionEnd()));
    }
}
Also used : SelectableTextInput(com.gargoylesoftware.htmlunit.html.impl.SelectableTextInput) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 2 with JsxSetter

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

the class HTMLDocument method setCookie.

/**
 * Adds a cookie, as long as cookies are enabled.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms533693.aspx">MSDN documentation</a>
 * @param newCookie in the format "name=value[;expires=date][;domain=domainname][;path=path][;secure]
 */
@JsxSetter
public void setCookie(final String newCookie) {
    final HtmlPage page = getPage();
    final WebClient client = page.getWebClient();
    if (StringUtils.isBlank(newCookie) && client.getBrowserVersion().hasFeature(HTMLDOCUMENT_COOKIES_IGNORE_BLANK)) {
        return;
    }
    client.addCookie(newCookie, getPage().getUrl(), this);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 3 with JsxSetter

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

the class HTMLObjectElement method setClassid.

/**
 * Sets the {@code classid} attribute.
 * @param classid the {@code classid} attribute
 */
@JsxSetter(IE)
public void setClassid(final String classid) {
    getDomNodeOrDie().setAttribute("classid", classid);
    if (classid.indexOf(':') != -1 && getBrowserVersion().hasFeature(HTML_OBJECT_CLASSID)) {
        final WebClient webClient = getWindow().getWebWindow().getWebClient();
        final Map<String, String> map = webClient.getActiveXObjectMap();
        if (map != null) {
            final String xClassString = map.get(classid);
            if (xClassString != null) {
                try {
                    final Class<?> xClass = Class.forName(xClassString);
                    final Object object = xClass.newInstance();
                    boolean contextCreated = false;
                    if (Context.getCurrentContext() == null) {
                        new HtmlUnitContextFactory(webClient).enterContext();
                        contextCreated = true;
                    }
                    wrappedActiveX_ = Context.toObject(object, getParentScope());
                    if (contextCreated) {
                        Context.exit();
                    }
                } catch (final Exception e) {
                    throw Context.reportRuntimeError("ActiveXObject Error: failed instantiating class " + xClassString + " because " + e.getMessage() + ".");
                }
                return;
            }
        }
        if (webClient.getOptions().isActiveXNative() && System.getProperty("os.name").contains("Windows")) {
            try {
                wrappedActiveX_ = new ActiveXObjectImpl(classid);
                wrappedActiveX_.setParentScope(getParentScope());
            } catch (final Exception e) {
                Context.throwAsScriptRuntimeEx(e);
            }
        }
    }
}
Also used : HtmlUnitContextFactory(com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) HtmlObject(com.gargoylesoftware.htmlunit.html.HtmlObject) NativeJavaObject(net.sourceforge.htmlunit.corejs.javascript.NativeJavaObject) ActiveXObjectImpl(com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectImpl) WebClient(com.gargoylesoftware.htmlunit.WebClient) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 4 with JsxSetter

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

the class HTMLAnchorElement method setText.

/**
 * Sets the {@code text} attribute.
 * @param text the {@code text} attribute
 */
@JsxSetter
public void setText(final String text) {
    final DomNode htmlElement = getDomNodeOrDie();
    htmlElement.setTextContent(text);
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Example 5 with JsxSetter

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

the class HTMLScriptElement method setText.

/**
 * Sets the {@code text} property.
 * @param text the {@code text} property
 */
@JsxSetter
public void setText(final String text) {
    final HtmlElement htmlElement = getDomNodeOrDie();
    htmlElement.removeAllChildren();
    final DomNode textChild = new DomText(htmlElement.getPage(), text);
    htmlElement.appendChild(textChild);
    ScriptElementSupport.executeScriptIfNeeded(htmlElement, false, false);
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) DomText(com.gargoylesoftware.htmlunit.html.DomText) 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