Search in sources :

Example 1 with HtmlApplet

use of com.gargoylesoftware.htmlunit.html.HtmlApplet in project htmlunit by HtmlUnit.

the class HTMLAppletElement method createAppletMethodAndProperties.

private void createAppletMethodAndProperties() throws Exception {
    final HtmlApplet appletNode = (HtmlApplet) getDomNodeOrDie();
    final Applet applet = appletNode.getApplet();
    if (applet == null) {
        return;
    }
    // Rhino should provide the possibility to declare delegate for Functions as it does for properties!!!
    for (final Method method : applet.getClass().getMethods()) {
        final Function f = new BaseFunction() {

            @Override
            public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) {
                final Object[] realArgs = new Object[method.getParameterTypes().length];
                for (int i = 0; i < realArgs.length; i++) {
                    final Object arg;
                    if (i > args.length) {
                        arg = null;
                    } else {
                        arg = Context.jsToJava(args[i], method.getParameterTypes()[i]);
                    }
                    realArgs[i] = arg;
                }
                try {
                    return method.invoke(applet, realArgs);
                } catch (final Exception e) {
                    throw Context.throwAsScriptRuntimeEx(e);
                }
            }
        };
        ScriptableObject.defineProperty(this, method.getName(), f, ScriptableObject.READONLY);
    }
}
Also used : HtmlApplet(com.gargoylesoftware.htmlunit.html.HtmlApplet) Context(net.sourceforge.htmlunit.corejs.javascript.Context) Function(net.sourceforge.htmlunit.corejs.javascript.Function) BaseFunction(net.sourceforge.htmlunit.corejs.javascript.BaseFunction) BaseFunction(net.sourceforge.htmlunit.corejs.javascript.BaseFunction) Applet(java.applet.Applet) HtmlApplet(com.gargoylesoftware.htmlunit.html.HtmlApplet) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) Method(java.lang.reflect.Method) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable)

Example 2 with HtmlApplet

use of com.gargoylesoftware.htmlunit.html.HtmlApplet in project htmlunit by HtmlUnit.

the class HTMLDocument method getItComputeElements.

static List<DomNode> getItComputeElements(final HtmlPage page, final String name, final boolean forIDAndOrName, final boolean alsoFrames) {
    final List<DomElement> elements;
    if (forIDAndOrName) {
        elements = page.getElementsByIdAndOrName(name);
    } else {
        elements = page.getElementsByName(name);
    }
    final List<DomNode> matchingElements = new ArrayList<>();
    for (final DomElement elt : elements) {
        if (elt instanceof HtmlForm || elt instanceof HtmlImage || elt instanceof HtmlApplet || (alsoFrames && elt instanceof BaseFrameElement)) {
            matchingElements.add(elt);
        }
    }
    return matchingElements;
}
Also used : HtmlApplet(com.gargoylesoftware.htmlunit.html.HtmlApplet) HtmlImage(com.gargoylesoftware.htmlunit.html.HtmlImage) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) BaseFrameElement(com.gargoylesoftware.htmlunit.html.BaseFrameElement) ArrayList(java.util.ArrayList)

Aggregations

HtmlApplet (com.gargoylesoftware.htmlunit.html.HtmlApplet)2 BaseFrameElement (com.gargoylesoftware.htmlunit.html.BaseFrameElement)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)1 HtmlImage (com.gargoylesoftware.htmlunit.html.HtmlImage)1 Applet (java.applet.Applet)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 BaseFunction (net.sourceforge.htmlunit.corejs.javascript.BaseFunction)1 Context (net.sourceforge.htmlunit.corejs.javascript.Context)1 Function (net.sourceforge.htmlunit.corejs.javascript.Function)1 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)1 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)1