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 Mark A Fortner <ph...@yahoo.com> on 2006/06/27 00:27:03 UTC

Problem with Batik Applet

I wrote a small applet to render an SVG file.  However, it can't seem to render the file.  When the applet appears it's blank.

I've debugged through it and there doesn't seem to be any problem.

When I create an application using the same code, the SVG image appears without any problem.

I Googled "batik applet" and saw references to an internally developed applet in the org.apache.batik.apps package, but it no longer seems to exist.

I've tried both the canvas.setURI approach and the canvas.setDocument approach to no avail.

Here's the relevant code that I'm using:

String svgurl = this.getParameter("svg");
        
        canvas.setDoubleBufferedRendering(true);
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        
        canvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
            public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
                System.out.println("Document Loading...");
            }

            public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
                System.out.println("Document Loaded.");
            }
        });
        
        canvas.addSVGLoadEventDispatcherListener
        (new SVGLoadEventDispatcherAdapter() {
                public void svgLoadEventDispatchStarted
                    (SVGLoadEventDispatcherEvent e) {
                    // At this time the document is available...
                    document = canvas.getSVGDocument();
                    // ...and the window object too.
                    window = canvas.getUpdateManager().
                        getScriptingEnvironment().createWindow();
                    // Registers the listeners on the document
                    // just before the SVGLoad event is
                    // dispatched.
                    registerListeners();
                    // It is time to pack the frame.
                    //frame.pack();
                }
            });
        
        if (svgurl != null && !svgurl.equals("")) {
            String parser = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
            SVGDocument doc;
            try {
                doc = f.createSVGDocument(svgurl);
                canvas.setDocument(doc);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            
            
          }
        
        //canvas.setURI(svgurl);
        

If anyone has any ideas, please let me know.

Regards,

Mark Fortner

RE: Problem with Batik Applet

Posted by Mark A Fortner <ph...@yahoo.com>.
Michael,
The jars are located at "http://localhost:8080/pipelineweb/*.jars" and the SVG file is located at "http://localhost:8080/pipelineweb/pipeline.svg.  Surely these are considered the same server?  I've tried just specifying a relative URL for the SVG and that gave me an exception for failing to include the protocol.

Any ideas?

Mark

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote: Applets can only connect back to the server from which they reside.  They cannot access other sites or your local file system without given explicit permission.
 
Michael Bishop

________________________________

From: Mark A Fortner [mailto:phidias51@yahoo.com]
Sent: Mon 6/26/2006 6:27 PM
To: batik-users@xmlgraphics.apache.org
Subject: Problem with Batik Applet


I wrote a small applet to render an SVG file.  However, it can't seem to render the file.  When the applet appears it's blank.

I've debugged through it and there doesn't seem to be any problem.

When I create an application using the same code, the SVG image appears without any problem.

I Googled "batik applet" and saw references to an internally developed applet in the org.apache.batik.apps package, but it no longer seems to exist.

I've tried both the canvas.setURI approach and the canvas.setDocument approach to no avail.

Here's the relevant code that I'm using:

String svgurl = this.getParameter("svg");
        
        canvas.setDoubleBufferedRendering(true);
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        
        canvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
            public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
                System.out.println("Document Loading...");
            }

            public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
                System.out.println("Document Loaded.");
            }
        });
        
        canvas.addSVGLoadEventDispatcherListener
        (new SVGLoadEventDispatcherAdapter() {
                public void svgLoadEventDispatchStarted
                    (SVGLoadEventDispatcherEvent e) {
                    // At this time the document is available...
                    document = canvas.getSVGDocument();
                    // ...and the window object too.
                    window = canvas.getUpdateManager().
                        getScriptingEnvironment().createWindow();
                    // Registers the listeners on the document
                    // just before the SVGLoad event is
                    // dispatched.
                    registerListeners();
                    // It is time to pack the frame.
                    //frame.pack();
                }
            });
        
        if (svgurl != null && !svgurl.equals("")) {
            String parser = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
            SVGDocument doc;
            try {
                doc = f.createSVGDocument(svgurl);
                canvas.setDocument(doc);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            
            
          }
        
        //canvas.setURI(svgurl);
        

If anyone has any ideas, please let me know.

Regards,

Mark Fortner

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

RE: Problem with Batik Applet

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
Applets can only connect back to the server from which they reside.  They cannot access other sites or your local file system without given explicit permission.
 
Michael Bishop

________________________________

From: Mark A Fortner [mailto:phidias51@yahoo.com]
Sent: Mon 6/26/2006 6:27 PM
To: batik-users@xmlgraphics.apache.org
Subject: Problem with Batik Applet


I wrote a small applet to render an SVG file.  However, it can't seem to render the file.  When the applet appears it's blank.

I've debugged through it and there doesn't seem to be any problem.

When I create an application using the same code, the SVG image appears without any problem.

I Googled "batik applet" and saw references to an internally developed applet in the org.apache.batik.apps package, but it no longer seems to exist.

I've tried both the canvas.setURI approach and the canvas.setDocument approach to no avail.

Here's the relevant code that I'm using:

String svgurl = this.getParameter("svg");
        
        canvas.setDoubleBufferedRendering(true);
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        
        canvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
            public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
                System.out.println("Document Loading...");
            }

            public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
                System.out.println("Document Loaded.");
            }
        });
        
        canvas.addSVGLoadEventDispatcherListener
        (new SVGLoadEventDispatcherAdapter() {
                public void svgLoadEventDispatchStarted
                    (SVGLoadEventDispatcherEvent e) {
                    // At this time the document is available...
                    document = canvas.getSVGDocument();
                    // ...and the window object too.
                    window = canvas.getUpdateManager().
                        getScriptingEnvironment().createWindow();
                    // Registers the listeners on the document
                    // just before the SVGLoad event is
                    // dispatched.
                    registerListeners();
                    // It is time to pack the frame.
                    //frame.pack();
                }
            });
        
        if (svgurl != null && !svgurl.equals("")) {
            String parser = XMLResourceDescriptor.getXMLParserClassName();
            SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
            SVGDocument doc;
            try {
                doc = f.createSVGDocument(svgurl);
                canvas.setDocument(doc);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            
            
          }
        
        //canvas.setURI(svgurl);
        

If anyone has any ideas, please let me know.

Regards,

Mark Fortner


Re: Problem with Batik Applet

Posted by th...@kodak.com.
HI Mark,

Mark A Fortner <ph...@yahoo.com> wrote on 07/06/2006 02:58:23 PM:

> Normally I would expect the applet to render the SVG file that it's 
passed. 
> However, all that appears is a big white blank spot.  If I take the same 
code,
> and turn it into an application, the same file renders perfectly.

   I was really trying to figure out what you had debugged that looked
fine...

> I wrap the Batik code with a try/catch and no exceptions are thrown.

   You might register listeners with the canvas to track document load 
events,
GVTTree build events, on load events, and rendering events.

> I'll try loading a simple SVG diagram with no JPEGs or JavaScript and 
see if 
> it renders properly.

   Definitely a good idea.

> If that doesn't work, I'll do a checkout and build the library.
> 
> Thanks for the suggestions.
> 
> Mark
> 
> thomas.deweese@kodak.com wrote:
> Hi Mark,
> 
> Mark A Fortner wrote on 06/26/2006 06:27:03 PM:
> 
> > I wrote a small applet to render an SVG file. However, it can't seem 
to 
> 
> > render the file. When the applet appears it's blank.
> > 
> > I've debugged through it and there doesn't seem to be any problem.
> 
> What does this mean? Obviously there is a problem otherwise you
> wouldn't be posting here ;)
> 
> Do you wrap all Batik class with try/catch blocks so you
> can check if Batik or one of it's libraries is throwing an
> exception? I suspect some form of Security error is at fault
> here.
> 
> > canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
> 
> Does the document you are trying to display use ECMAScript 
> (AKA Java script). Rhino has some problems in an Applet context
> as it's default behavior is to generate bytecode from the JavaScript.
> 
> I think all of those issues are resolved in the SVN version of
> Batik. In either case I would try a simple static SVG first.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Problem with Batik Applet

Posted by Mark A Fortner <ph...@yahoo.com>.
Thomas,
Normally I would expect the applet to render the SVG file that it's passed.  However, all that appears is a big white blank spot.  If I take the same code, and turn it into an application, the same file renders perfectly.

I wrap the Batik code with a try/catch and no exceptions are thrown.

I'll try loading a simple SVG diagram with no JPEGs or JavaScript and see if it renders properly.

If that doesn't work, I'll do a checkout and build the library.

Thanks for the suggestions.

Mark

thomas.deweese@kodak.com wrote: Hi Mark,

Mark A Fortner 
 wrote on 06/26/2006 06:27:03 PM:

> I wrote a small applet to render an SVG file.  However, it can't seem to 

> render the file.  When the applet appears it's blank.
> 
> I've debugged through it and there doesn't seem to be any problem.

   What does this mean?  Obviously there is a problem otherwise you
wouldn't be posting here ;)

   Do you wrap all Batik class with try/catch blocks so you
can check if Batik or one of it's libraries is throwing an
exception?  I suspect some form of Security error is at fault
here.

>         canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);

   Does the document you are trying to display use ECMAScript 
(AKA Java script).  Rhino has some problems in an Applet context
as it's default behavior is to generate bytecode from the JavaScript.

   I think all of those issues are resolved in the SVN version of
Batik.  In either case I would try a simple static SVG first.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org




Re: Problem with Batik Applet

Posted by th...@kodak.com.
Hi Mark,

Mark A Fortner <ph...@yahoo.com> wrote on 06/26/2006 06:27:03 PM:

> I wrote a small applet to render an SVG file.  However, it can't seem to 

> render the file.  When the applet appears it's blank.
> 
> I've debugged through it and there doesn't seem to be any problem.

   What does this mean?  Obviously there is a problem otherwise you
wouldn't be posting here ;)

   Do you wrap all Batik class with try/catch blocks so you
can check if Batik or one of it's libraries is throwing an
exception?  I suspect some form of Security error is at fault
here.

>         canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);

   Does the document you are trying to display use ECMAScript 
(AKA Java script).  Rhino has some problems in an Applet context
as it's default behavior is to generate bytecode from the JavaScript.

   I think all of those issues are resolved in the SVN version of
Batik.  In either case I would try a simple static SVG first.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org