xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Roland.Webe...@t-systems.com>
Subject AW: Batik and XmlHttpRequest / accessing Batik objects from javascript in svg
Date Tue, 05 Oct 2010 16:34:04 GMT
Hi Thomas,

thank you very much for your valuable hints. I'll check it out.

Regarding communication, I already use getURL() now. However, there seems to be a bug that
has already been mentioned here, but was confirmed as fixed. Yet it still (or again) seems
to exist: I cannot use getURL() inside an Applet (works fine in squiggle)  without granting
a right to create a Classloader via a java.policy file in the user home directory:

Please have a look here:


Ok, while rereading the above post, I realized that this fix is not included in the current
release version 1.7 I use. Is that correct? The fix is from 2008 in 1.8Alpha ?! It seems there
hasn't there been any further major release since that? Hmm, that's sad, because I managed
to handle several problems now - but the requirement of a java.policy file on the user's computer
is a real showstopper. How stable are current SVN-Releases that include the fix? Is it possible
to use them in a productional environment?

Thanks again,

Von: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Gesendet: Mittwoch, 29. September 2010 12:28
An: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Betreff: Re: Batik and XmlHttpRequest / accessing Batik objects from javascript in svg

Hi Roland,

<Roland.Weber01@t-systems.com> wrote on 09/17/2010 08:45:30 AM:

> However, I got 2 main problems in getting my existing SVGs run in an
> Applet with JSVGCanvas:
> 1) The Adobe Plugin is currently embedded into an HTML page via the
> embed-tag. This enables all scripts in the SVGs to access all Html-
> Elements/Javascripts  from the OUTER HTML page and vice versa. That
> means I can define a Javascript object in a script block on the HTML
> and use it inside the Javascript of the SVG out of the box. Or for
> example I can get hold of a DIV-Element from the outer HTML page by
> calling something like
> parent.document.getElementById(<divId>);
> from within javscript inside SVG.
> No discussion on whether this is a good design or concept - fact is,
> that the Javascript in the existing SVGs heavily relies on
> Javascript blocks and Elements of the surrounding HTML page. My
> question is: Is there a way to achieve the same effect when using an
> Applet with JSVGCanvas to display the SVGs? Probably not.

        Correct, I don't believe this is possible.  It's only possible in
Adobe because they can actually run their scripts in the Browsers script
engine such an option is not AFAIK available for Java.

> However, I could surpass this by calling a method from my Applet
> from inside the SVG's Javascript (as I can get hold of Elements of
> the HTML page from my Applet). The question is: How to access The
> JSVGCanvas or the Applet object from javascript within SVG? Is there
> a way, maybe via the Rhino engine?

        You will need to a little bit of setup in Java first.  Basically
you need to bind the Applet and or JSVGCanvas object to a global in
the JavaScript interpreter.  You can do this by calling
'getInterpreter(String lang)' (lang should probably be "text/ecmascript")
on the BridgeContext associated with the JSVGCanvas.  This will give
you the Interpreter that is being used.  On that object you can call
'bindObject(String name, Object obj)'.

        That will bind 'obj' to 'name' as a global in the script environment.
>From their Rhino does a decent job of exposing Java methods into JavaScript.

> 2) A related problem is the current communication. Within the Adobe
> plugin, I can access the browsers XmlHttpRequest object and use it
> for ajax-like communication from within the SVG. This doesn't work
> within the Applet with JSVGCanvas. Isn't there something like a
> lightweight XmlHttpRequest object available in Batik?

        Check 'getURL', and parseXML, they are generally a decent work
alike (not quite as flexible).

> If not, would it be possible to call some Java code from within the SVGs
> Javascript to build some similar communication and how does this
> work? Would security settings deny this (can't use signed Applets)
> if I only would connect to the same server/codedbase? Ajax-like
> communication within the svg is awesome, it makes the graph/
> workfloweditor quite fast with the Adobe Plugin - this would be a
> point Batik could really benefit from when it comes to developer and
> customer acceptance!

        As I said above you can expose your own Java methods fairly
easily.  You are bound by the Applet sandbox (as it Batik) so you
are restricted in the servers you can connect to (of course you
should have similar restrictions with XmlHttpRequest).

Good luck.

View raw message