Hi,

I'm having problems with creating an image from a plain
org.w3c.dom.Document. I was told that I could use
DOMUtilities.deepCloneDocument to convert a w3c-Document to a SVGDocument,
but when I run the transcoding I get a ClassCastException. Apparently when
the ImageTranscoder tries to cast the root element to
org.apache.batik.dom.GenericElement.

I'm using a very simple XML in this example to illustrate my problem,
normally I would run a XSL transformation on a Document containing financial
information to create a JPEG image in a report (that is created with an
other transformation on the same source). 

Now I must convert the resulting Document into a String before I give it to
Batik, not a very effective process I would believe...

Below is some sample code that illustrates my problem, as well as the
exception I get. Can anyone see if I'm doing anything wrong?

Thanks,
- Jon



import org.apache.xerces.parsers.*;
import org.apache.batik.transcoder.image.*;
import org.apache.batik.transcoder.*;
import org.apache.batik.dom.util.*;
import org.apache.batik.dom.svg.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import java.io.*;

public class BatikTest {
    public static void main (String args[]) throws Exception {
        final String XML = "<svg><circle cx=\"100\" cy=\"100\" r=\"50\"
style=\"fill:green\"/></svg>";
        DOMParser   parser      = new DOMParser();
        InputSource inputSource = new InputSource(new StringReader(XML));
        parser.parse(inputSource);
        Document SVG = parser.getDocument();        
        Document SVGDOM = DOMUtilities.deepCloneDocument(SVG,
SVGDOMImplementation.getDOMImplementation());        
        TranscoderInput  in  = new TranscoderInput(SVGDOM);
        FileOutputStream f = new FileOutputStream("d:\\svgtest.jpg");
        TranscoderOutput out = new TranscoderOutput(f);
        Transcoder transcoder = new JPEGTranscoder();
 
transcoder.addTranscodingHint(ImageTranscoder.KEY_XML_PARSER_CLASSNAME,
"org.apache.xerces.parsers.SAXParser");
        transcoder.transcode(in, out);
        f.flush();
        f.close();
    }
}
The above code gives the following exception when I try to execute it (it
fails at the line transcoder.transcode(in, out);) :

java.lang.ClassCastException: org.apache.batik.dom.GenericElement
        at
org.apache.batik.dom.svg.SVGOMDocument.getRootElement(SVGOMDocument.java:519
)
        at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.
java:142)
        at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTrans
coder.java:126)
        at com.accenture.jam.xml.BatikTest.main(BatikTest.java:26)


I'm using JDK1.3 on Windows NT and Batik 1.0


* * * * * * * * * * * * * * *

This email with attachments is solely for the use of the individual or
entity to whom it is addressed. Please also be aware that Finansbanken ASA
cannot accept any payment orders or other legal binding correspondence with
customers as a part of an email.

This email message has been virus checked by the virus programs used by
Finansbanken ASA.

* * * * * * * * * * * * * * *

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to