Java Code Examples for net.sourceforge.htmlunit.corejs.javascript.Context#toBoolean()

The following examples show how to use net.sourceforge.htmlunit.corejs.javascript.Context#toBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PointerEvent.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
private static Object getValue(final ScriptableObject object, final String name, final Object defaulValue) {
    Object value = object.get(name);
    if (value != null) {
        if (defaulValue instanceof String) {
            value = String.valueOf(value);
        }
        else if (defaulValue instanceof Double) {
            value = Context.toNumber(value);
        }
        else if (defaulValue instanceof Number) {
            value = (int) Context.toNumber(value);
        }
        else {
            value = Context.toBoolean(value);
        }
    }
    else {
        value = defaulValue;
    }
    return value;
}
 
Example 2
Source File: PointerEvent.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
private static Object getValue(final ScriptableObject object, final String name, final Object defaulValue) {
    Object value = object.get(name);
    if (value != null) {
        if (defaulValue instanceof String) {
            value = String.valueOf(value);
        }
        else if (defaulValue instanceof Double) {
            value = (double) Context.toNumber(value);
        }
        else if (defaulValue instanceof Number) {
            value = (int) Context.toNumber(value);
        }
        else {
            value = Context.toBoolean(value);
        }
    }
    else {
        value = defaulValue;
    }
    return value;
}
 
Example 3
Source File: HTMLListElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the value of the {@code compact} attribute.
 * @param compact the value of the {@code compact} attribute
 */
@JsxSetter
public void setCompact(final Object compact) {
    if (Context.toBoolean(compact)) {
        getDomNodeOrDie().setAttribute("compact", "");
    }
    else {
        getDomNodeOrDie().removeAttribute("compact");
    }
}
 
Example 4
Source File: HTMLListElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the value of the {@code compact} attribute.
 * @param compact the value of the {@code compact} attribute
 */
@JsxSetter
public void setCompact(final Object compact) {
    if (Context.toBoolean(compact)) {
        getDomNodeOrDie().setAttribute("compact", "");
    }
    else {
        getDomNodeOrDie().removeAttribute("compact");
    }
}
 
Example 5
Source File: Window.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Opens a new window.
 *
 * @param url when a new document is opened, <i>url</i> is a String that specifies a MIME type for the document.
 *        When a new window is opened, <i>url</i> is a String that specifies the URL to render in the new window
 * @param name the name
 * @param features the features
 * @param replace whether to replace in the history list or no
 * @return the newly opened window, or {@code null} if popup windows have been disabled
 * @see com.gargoylesoftware.htmlunit.WebClientOptions#isPopupBlockerEnabled()
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536651.aspx">MSDN documentation</a>
 */
@JsxFunction
public WindowProxy open(final Object url, final Object name, final Object features,
        final Object replace) {
    String urlString = null;
    if (!Undefined.isUndefined(url)) {
        urlString = Context.toString(url);
    }
    String windowName = "";
    if (!Undefined.isUndefined(name)) {
        windowName = Context.toString(name);
    }
    String featuresString = null;
    if (!Undefined.isUndefined(features)) {
        featuresString = Context.toString(features);
    }
    final WebClient webClient = getWebWindow().getWebClient();

    if (webClient.getOptions().isPopupBlockerEnabled()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Ignoring window.open() invocation because popups are blocked.");
        }
        return null;
    }

    boolean replaceCurrentEntryInBrowsingHistory = false;
    if (!Undefined.isUndefined(replace)) {
        replaceCurrentEntryInBrowsingHistory = Context.toBoolean(replace);
    }
    if ((featuresString != null || replaceCurrentEntryInBrowsingHistory) && LOG.isDebugEnabled()) {
        LOG.debug(
               "window.open: features and replaceCurrentEntryInBrowsingHistory "
                + "not implemented: url=[" + urlString
                + "] windowName=[" + windowName
                + "] features=[" + featuresString
                + "] replaceCurrentEntry=[" + replaceCurrentEntryInBrowsingHistory
                + "]");
    }

    // if specified name is the name of an existing window, then hold it
    if (StringUtils.isEmpty(urlString) && !"".equals(windowName)) {
        try {
            final WebWindow webWindow = webClient.getWebWindowByName(windowName);
            return getProxy(webWindow);
        }
        catch (final WebWindowNotFoundException e) {
            // nothing
        }
    }
    final URL newUrl = makeUrlForOpenWindow(urlString);
    final WebWindow newWebWindow = webClient.openWindow(newUrl, windowName, webWindow_);
    return getProxy(newWebWindow);
}
 
Example 6
Source File: HTMLElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the {@code spellcheck} property.
 * @return the {@code spellcheck} property
 */
@JsxGetter({FF, FF68, FF60})
public boolean isSpellcheck() {
    return Context.toBoolean(getDomNodeOrDie().getAttributeDirect("spellcheck"));
}
 
Example 7
Source File: Window.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Opens a new window.
 *
 * @param url when a new document is opened, <i>url</i> is a String that specifies a MIME type for the document.
 *        When a new window is opened, <i>url</i> is a String that specifies the URL to render in the new window
 * @param name the name
 * @param features the features
 * @param replace whether to replace in the history list or no
 * @return the newly opened window, or {@code null} if popup windows have been disabled
 * @see com.gargoylesoftware.htmlunit.WebClientOptions#isPopupBlockerEnabled()
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536651.aspx">MSDN documentation</a>
 */
@JsxFunction
public WindowProxy open(final Object url, final Object name, final Object features,
        final Object replace) {
    String urlString = null;
    if (url != Undefined.instance) {
        urlString = Context.toString(url);
    }
    String windowName = "";
    if (name != Undefined.instance) {
        windowName = Context.toString(name);
    }
    String featuresString = null;
    if (features != Undefined.instance) {
        featuresString = Context.toString(features);
    }
    final WebClient webClient = getWebWindow().getWebClient();

    if (webClient.getOptions().isPopupBlockerEnabled()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Ignoring window.open() invocation because popups are blocked.");
        }
        return null;
    }

    boolean replaceCurrentEntryInBrowsingHistory = false;
    if (replace != Undefined.instance) {
        replaceCurrentEntryInBrowsingHistory = Context.toBoolean(replace);
    }
    if ((featuresString != null || replaceCurrentEntryInBrowsingHistory) && LOG.isDebugEnabled()) {
        LOG.debug(
               "window.open: features and replaceCurrentEntryInBrowsingHistory "
                + "not implemented: url=[" + urlString
                + "] windowName=[" + windowName
                + "] features=[" + featuresString
                + "] replaceCurrentEntry=[" + replaceCurrentEntryInBrowsingHistory
                + "]");
    }

    // if specified name is the name of an existing window, then hold it
    if (StringUtils.isEmpty(urlString) && !"".equals(windowName)) {
        try {
            final WebWindow webWindow = webClient.getWebWindowByName(windowName);
            return getProxy(webWindow);
        }
        catch (final WebWindowNotFoundException e) {
            // nothing
        }
    }
    final URL newUrl = makeUrlForOpenWindow(urlString);
    final WebWindow newWebWindow = webClient.openWindow(newUrl, windowName, webWindow_);
    return getProxy(newWebWindow);
}
 
Example 8
Source File: HTMLElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the {@code spellcheck} property.
 * @return the {@code spellcheck} property
 */
@JsxGetter(FF)
public boolean isSpellcheck() {
    return Context.toBoolean(getDomNodeOrDie().getAttributeDirect("spellcheck"));
}