xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dinkar Ganti" <dink...@lifeconnect.com>
Subject RE: What happens to the Document that SVGGenerator uses?
Date Fri, 17 Aug 2001 17:14:46 GMT

The "stream" method works very nicely and I have been using it to generate
simple charts using a commercially available charting toolkit. The reason I
could not use the "stream" is because, the application is a part of a Cocoon
pipeline and I need to generate output SAX events on the content handler.
Here, JDOM expects a complete Document and therefore I needed a completed

I tried an earlier suggestion of removing the root from the document and
appending the svgRoot. This works fine with JDOM's XMLOutputter, howver,
SAXOutputter seems to be ignoring the namespace and therefore IE does not
display the graph. This is probably an issue with JDOM implementation.

Thank you for the reply.


-----Original Message-----
From: Randall Parker [mailto:randall2@nls.net]
Sent: Friday, August 17, 2001 11:08 AM
To: Batik Users
Subject: Re: What happens to the Document that SVGGenerator uses?


I see that you are using JDOM as your outputter. I haven't tried that but
would like to know how to do that.

However, I have been using SVGGraphics2D stream() method with some success.

   boolean UseCSS = true;

Here is the stream method from SVGGraphics2D (and this demonstrates yet
again how great it is to have open source
btw). See that they do more to prepare the document before they stream it
out. Try adding some stuff from the try clause
here before you stream it out with JDOM:.

    public void stream(Element svgRoot, Writer writer, boolean useCss)
        throws SVGGraphics2DIOException {
        try {
            PrintWriter out = new PrintWriter(writer);
            DocumentFragment svgDocument =

              Node svgCssDocument = svgDocument;
              XmlWriter.writeXml(svgCssDocument, writer);
              XmlWriter.writeXml(svgDocument, writer);
            if (useCss)

            XmlWriter.writeXml(svgDocument, writer);
        } catch (SVGGraphics2DIOException e) {
            // this catch prevents from catching an SVGGraphics2DIOException
            // and wrapping it again in another SVGGraphics2DIOException
            // as would do the second catch (XmlWriter throws
            // Exception but flush throws IOException)
        } catch (IOException io) {
                handleError(new SVGGraphics2DIOException(io));

On Thu, 16 Aug 2001 17:47:33 -0400, Dinkar Ganti wrote:

>public class SVGTest {
>    public void paint(Graphics2D g2d) {
>        g2d.setPaint(Color.red);
>        g2d.fill(new Rectangle(10, 10, 100, 100));
>    }
>    public static void main(String [] args) throws IOException {
>        // Get a DOMImplementation
>        DOMImplementation domImpl =
>            GenericDOMImplementation.getDOMImplementation();
>        // Create an instance of org.w3c.dom.Document
>        org.w3c.dom.Document document = domImpl.createDocument(null, "svg",
>        // Create an instance of the SVG Generator
>        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
>        // Ask the test to render into the SVG Graphics2D implementation
>        SVGTest test = new SVGTest();
>        test.paint(svgGenerator);
>        // Finally, stream out SVG to the standard output using UTF-8
>        // character to byte encoding
>	//        boolean useCSS = true; // we want to use CSS style attribute
>        //Writer out = new OutputStreamWriter(System.out, "UTF-8");
>        //svgGenerator.stream(out, useCSS);
>	DOMBuilder builder = new DOMBuilder();
>	XMLOutputter outputter = new XMLOutputter();
>	org.jdom.Document jdomDocument = builder.build(document);
>	outputter.output(jdomDocument, System.out);
>    }

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

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

View raw message