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 Alan Crowley <al...@gmail.com> on 2011/05/11 23:19:09 UTC

Odd Batik Error : SVGOMDocument cannot be cast to SVGOMDocument

Hi All,

I have some very simple code, converting SVG to a PNG using batik.

This should be very simple to do, but for some reason there seems to be an
error casting an SVGOMDocument  to be SVGOMDocument  (itself !!!)

Any hints greatly appreciated !

Alan

Here is my SVG:
<svg height='600' width='800' version="1.1" xmlns="
http://www.w3.org/2000/svg"><desc></desc><defs></defs><a
title="StartSymbol0"><circle stroke-width="5" font-size="91px"
style="font-size: 91px; strok
e-width: 5;" stroke="#000000" fill="#00ff00" r="20" cy="35"
cx="35"/></a><circle stroke-width="4" font-size="93px" style="font-size:
93px; stroke-width: 4;" stroke="#000000" fill="#ff7f00" r="20" cy="
222" cx="261"/><circle stroke-width="3" font-size="94px" style="font-size:
94px; stroke-width: 3;" stroke="#000000" fill="#ff7f00" r="10" cy="222"
cx="261"/><path stroke-dasharray="15,5" stroke-width=
"5" style="stroke-width: 5;" d="M56,35C148,35,148,222,240,222"
stroke="#000000" fill="none"/></svg>

Here is my code:
ByteArrayInputStream bais = new ByteArrayInputStream(SVG.getBytes());
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
org.w3c.dom.Document doc = f.createDocument(null, bais);

TranscoderInput input = new TranscoderInput( doc );
OutputStream ostream = new FileOutputStream( name + ".png" );
TranscoderOutput output = new TranscoderOutput( ostream );

PNGTranscoder t = new PNGTranscoder();
t.transcode(input, output); //Line 211
ostream.flush();
ostream.close();

Here is the Exception I get:
java.lang.ClassCastException: org.apache.batik.dom.svg.SVGOMDocument cannot
be cast to org.apache.batik.dom.svg.SVGOMDocument
        at
org.apache.batik.bridge.BridgeContext.setDocument(BridgeContext.java:441)
        at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:54)
        at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:208)
        at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:92)
        at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
        at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
        at
DiagramPersistanceServlet.writeImage(DiagramPersistanceServlet.java:211)

Re: Odd Batik Error : SVGOMDocument cannot be cast to SVGOMDocument

Posted by Peter Hull <pe...@gmail.com>.
On Wed, May 11, 2011 at 10:19 PM, Alan Crowley <al...@gmail.com> wrote:
> This should be very simple to do, but for some reason there seems to be an
> error casting an SVGOMDocument  to be SVGOMDocument  (itself !!!)
Very strange. I tried your code (just pasting it into a main() method)
and it didn't give that error (this was Batik 1.7 as loaded from
Maven)

Pete

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


Re: Odd Batik Error : SVGOMDocument cannot be cast to SVGOMDocument

Posted by Alan Crowley <al...@gmail.com>.
Thanks!

I'm seeing the same, have managed to get all working in a stand alone
application. I reckon i will have to look at my Tomcat setup for potential
conflicts

On Thu, May 12, 2011 at 11:15 AM, <th...@kodak.com> wrote:

> Hi Alan,
>
> Alan Crowley <al...@gmail.com> wrote on 05/11/2011 05:19:09 PM:
>
>
> > This should be very simple to do, but for some reason there seems to
> > be an error casting an SVGOMDocument  to be SVGOMDocument  (itself !!!)
>
>
>         This almost certainly indicates that that your class path has two
> versions of the Batik libraries on it. Most likely your
> SAXSVGDocumentFactory
> is comming from a differerent copy of the Batik Jar's from the
> PNGTranscoder.
>

Re: Odd Batik Error : SVGOMDocument cannot be cast to SVGOMDocument

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

Alan Crowley <al...@gmail.com> wrote on 05/11/2011 05:19:09 PM:

> This should be very simple to do, but for some reason there seems to
> be an error casting an SVGOMDocument  to be SVGOMDocument  (itself !!!)

        This almost certainly indicates that that your class path has two
versions of the Batik libraries on it. Most likely your 
SAXSVGDocumentFactory
is comming from a differerent copy of the Batik Jar's from the 
PNGTranscoder.