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);
}
}
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;
}
Aggregations