Subj : Re: Embedding Parameters To : gonzalo From : Igor Bukanov Date : Thu Apr 10 2003 05:41 pm gonzalo wrote: > Hello: > > We are trying to interpretate JS code on a HTML page. We are using > RHINO, but we need a DOM implementation. We have three questions: > > a) We are creating a Document object as a Scriptable object. That way > we can give an implementation to the calls in JS such as > document.write. The problem is we allways get a runtime error > indicating wrong parameter type. How should we declare the method?? We > are using public void jsFunction_write(ScriptableObject str) If you would need to support only a version of document.write with a single argument, you would use jsFunction_write(String str), Rhino will convert the corresponding JavaScript argument automatically when calling it. But since you need to deal with JS calling document.write(arg1, arg2, ...(, you should use something like: void jsFunction_write(ScriptableObject str) public static Object jsFunction_getClass( Context cx,Scriptable thisObj, Object[] args, Function funObj) { StringBuffer sb = new StringBuffer(); for (int i = 0; i != args.length; ++i) { sb.append(ScriptRuntme.toString(args[i])); } DocumentClass doc = (DocumentClass)thisObj; doc.write_impl(sb.toString()); return Undefined.instance; // void result } > > > b) Does any one know of a good DOM implementation we could provide to > RHINO, so we dont have to code all the interface?? For comercial one you can ask the company where I work, www.icesoft.com. AFAIK there is no reasonable open source implementations. > > c) So far, we know how to give an implementation to: > * getting the value of a property (jsGet_ ) > * calling a function (jsFunction_ ) > * calling the object constructor(jsConstructor) > Now, we DONT KNOW how to: > * capture the setting of a property (obj.style.cursor = 'hand'; (JS > code)) I assume here obj points to some DOM element, but then your DOM implementation should support getStyle() method which Rhino via reflection will map to obj.style property etc. > * handle events. How to control things like (document.onkeydown = > msKeyDown;) If you do not need to call msKeyDown, then the fact that you inherit your document from ScriptableObject will handle that, but if you do, the situation is rather complex since you would need to convert this to document.addEventListener(...) and it is better to have a DOM implementation that knows about this usage. > * overloaded methods. When a method accept a variable number of > parameters, how to decleare it on our ScriptableObject See above. Regards, Igor .