Hi Brecht,

   Ahh, took me a bit but I got it:
 DOMImplementation domImpl =
       GenericDOMImplementation.getDOMImplementation();
 Document document = domImpl.createDocument(null, "svg", null);

This should be:

 DOMImplementation domImpl =
       SVGDOMImplementation.getDOMImplementation();
 Document document = domImpl.createDocument
     (SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);

Brecht Yperman wrote:
   However I think you would be _much_ better off passing
the DOM that the svgGenerator builds directly to the Transcoder
(TranscoderInput will take a document).  To get the
document you want to do something like:


// The following populates the document root with the // generated SVG content. Element root = document.getDocumentElement(); svgGenerator.getRoot(root);


I've tried this (see below), but I keep getting a ClassCastException :(

java.lang.ClassCastException
        at org.apache.batik.dom.svg.SVGOMDocument.getRootElement(Unknown Source)

        private static void transcode(Visualisation vis, File file, ImageTranscoder
t, Dimension dim) throws IOException {
                logger.debug("");

                DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
                Document document = domImpl.createDocument(null, "svg", null);
                SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
                ctx.setComment("Generated by Trs-visualisation");
                SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
                svgGenerator.setSVGCanvasSize(dim);
                vis.render(svgGenerator, new Double(dim.getWidth()).intValue(), new
Double(dim.getHeight()).intValue(), null);

                Element root = document.getDocumentElement();
                svgGenerator.getRoot(root);

TranscoderInput input = new TranscoderInput(document);

                OutputStream ostream = null;
                try {
                        ostream = new FileOutputStream(file);
                } catch (FileNotFoundException e3) {
                        logger.error(e3);
                }
                TranscoderOutput output = new TranscoderOutput(ostream);
                try {
                        t.transcode(input, output);
                } catch (TranscoderException e1) {
                        logger.error(e1);
                }
                ostream.flush();
                ostream.close();
        }




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



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



Reply via email to