You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by osci <je...@gmail.com> on 2007/12/03 05:38:55 UTC
problems extending RhinoInterpreter
Hi,
I'm trying to follow the example at
http://xmlgraphics.apache.org/batik/using/scripting/ecmascript.html#customizingRhino
to extend the RhinoInterpreter and include a print function but it's not
working out for me. Just a note: RhinoInterpreter is spelled incorrectly in
the class declaration line.
I'm using Batik 1.7, Java 1.3.1, netbeans, a macbook, and this code:
package raprogram.svg.script;
import java.net.URL;
import org.apache.batik.script.rhino.*;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.PropertyException;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
public class ExtendedRhinoInterpreter extends RhinoInterpreter {
public ExtendedRhinoInterpreter(URL documentURL) {
// Array of functions to put in the global object.
final String[] names = { "print" };
try {
// Add the functions to the global object.
getGlobalObject().defineFunctionProperties
(names, ExtendedRhinoIntepreter.class,
ScriptableObject.DONTENUM);
} catch (PropertyException e) {
throw new Error(e);
}
}
public static void print(Context cx, Scriptable thisObj,
Object[] args, Function funObj) {
for (int i = 0; i < args.length; i++) {
if (i > 0) {
System.out.print(" ");
}
// Convert the ECMAScript value into a string form.
String s = Context.toString(args[i]);
System.out.print(s);
}
System.out.println();
}
}
I'm getting an error with the constructor. The example is missing the URL
argument but even when I add it I get this error:
ExtendedRhinoInterpreter.java:24: RhinoInterpreter(java.net.URL) in
org.apache.batik.script.rhino.RhinoInterpreter cannot be applied to ()
A second error I'm getting is with this line:
getGlobalObject().defineFunctionProperties
(names, ExtendedRhinoIntepreter.class,
ScriptableObject.DONTENUM);
The error is:
ExtendedRhinoInterpreter.java:31: cannot find symbol
symbol : class ExtendedRhinoIntepreter
location: class raprogram.svg.script.ExtendedRhinoInterpreter
(names, ExtendedRhinoIntepreter.class,
Any help would be greatly appreciated.
Regards,
Jeff Cressman
--
View this message in context: http://www.nabble.com/problems-extending-RhinoInterpreter-tf4934336.html#a14123824
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: problems extending RhinoInterpreter
Posted by osci <je...@gmail.com>.
Hi Cameron,
Thanks for looking into this.
A couple of new things:
1) I forgot to mention that line 17 of the ExtendedRhinoInterpreter example
is missing it's ending semi-colon.
2) In getting the ExtendedRhinoInterpreter compiled I moved on with the rest
of the example and noted that the last line of the InterPool building
example code has setIntepreterPool missing an 'r'.
3) Fixing the above I got stuck because the setInterpreterPool method of
BridgeContext has protected access and I couldn't seem to call it. Perhaps
I'm misunderstanding something straightforward here but my solution was to
extend the BridgeContext and override the method to provide public access. I
also had to extend SVG12BridgeContext to extend the new BridgeContext.
Having done all this I am now able to make print calls from my JavaScript
and have it show up in the Java console. If there was a simpler way to do
this I'd love to hear it.
Here's my final createBridgeContext method:
protected BridgeContext createBridgeContext(SVGOMDocument doc) {
if (loader == null) {
loader = new DocumentLoader(userAgent);
}
ExtendedBridgeContext result;
if (doc.isSVG12()) {
result = new ExtendedSVG12BridgeContext(userAgent, loader);
} else {
result = new ExtendedBridgeContext(userAgent, loader);
}
InterpreterPool pool = new InterpreterPool();
InterpreterFactory f = new ExtendedRhinoInterpreterFactory();
// Register the interpreter factory for all four MIME types that
// Batik normally supports for ECMAScript.
pool.putInterpreterFactory("text/ecmascript", f);
pool.putInterpreterFactory("text/javascript", f);
pool.putInterpreterFactory("application/ecmascript", f);
pool.putInterpreterFactory("application/javascript", f);
result.setInterpreterPool(pool);
return result;
}
Regards,
Jeff Cressman
--
View this message in context: http://www.nabble.com/problems-extending-RhinoInterpreter-tf4934336.html#a14180378
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: problems extending RhinoInterpreter
Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Jeff.
Jeff Cressman:
> I'm trying to follow the example at
> http://xmlgraphics.apache.org/batik/using/scripting/ecmascript.html#customizingRhino
> to extend the RhinoInterpreter and include a print function but it's not
> working out for me. Just a note: RhinoInterpreter is spelled incorrectly in
> the class declaration line.
Thanks.
> I'm using Batik 1.7, Java 1.3.1, netbeans, a macbook, and this code:
> …
> public class ExtendedRhinoInterpreter extends RhinoInterpreter {
>
> public ExtendedRhinoInterpreter(URL documentURL) {
> …
> I'm getting an error with the constructor. The example is missing the URL
> argument but even when I add it I get this error:
>
> ExtendedRhinoInterpreter.java:24: RhinoInterpreter(java.net.URL) in
> org.apache.batik.script.rhino.RhinoInterpreter cannot be applied to ()
That’s a mistake in the example. The RhinoInterpreter class has no
default constructor, just one that takes a single URL object.
> A second error I'm getting is with this line:
>
> getGlobalObject().defineFunctionProperties
> (names, ExtendedRhinoIntepreter.class,
> ScriptableObject.DONTENUM);
That’s the mis-spelling of “ExtendedRhinoInterpreter” causing a problem,
I think.
I’ve updated that page in a number of places so that the example should
work; it should be visible within an hour on the website. (And
apologies for having a less-than-stable API there.)
--
Cameron McCormack, http://mcc.id.au/
xmpp:heycam@jabber.org ▪ ICQ 26955922 ▪ MSN cam@mcc.id.au
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org