W3C home > Mailing lists > Public > www-svg@w3.org > June 2000

More on: How to create a SVG File in Java.

From: Bernd Grolig <Bernd.Grolig@ptv.de>
Date: Mon, 5 Jun 2000 16:47:45 +0200
Message-ID: <81CE335DFC44D311BEFF00E0292A346EE327BB@ptv_nt_09.ptv.ptv.de>
To: www-svg@w3.org
Hello, 
some days ago, I posted a question how to generate a SVG Stream using the
SVG-DOM Implementation and Servlets.
I got some good advice (thank you Vincent Hardy), but there is still a
problem:

It works fine to use the Objectmodel, but I don't know how to parse the
Object Model to the Outputstream. 
I could use the println Method of the Outputstream, but this is I guess not
the idea of the Objectmodel (respectively I didn't even need to work with
it).

Another possibility is, to export the content in an temporary svg file (as
Vincent suggested), but I would prefer to parse the content directly in the
outputstream.

If anybody has some ideas... would be great ;-)

Regards, Bernd.

Here is a simple example:


import org.w3c.dom.svg.*;
import org.csiro.svg.dom.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
	
public class SVGServlet extends HttpServlet {  
	public void doGet (HttpServletRequest req, HttpServletResponse res)
		throws ServletException, IOException {
			try {
			
					res.setContentType("image/svg");
					ServletOutputStream out =
res.getOutputStream();

					// Some SVG Parameters
					SVGNumber x = new SVGNumberImpl();
					SVGNumber y = new SVGNumberImpl();
					SVGNumber width = new
SVGNumberImpl();
					SVGNumber height = new
SVGNumberImpl();
					
					x.setValue(10);
					y.setValue(10);
					width.setValue(10);
					height.setValue(10);

					// Create an instance of a
SVGDocument Class
					SVGDocument doc =
(SVGDocument)Class.forName("org.csiro.svg.dom.SVGDocumentImpl").newInstance(
);
					
					// getRootElement
					SVGSVGElement svg =
(SVGSVGElementImpl)doc.getRootElement();

					// create a new Rect
					SVGRect rect =
(SVGRectImpl)svg.createSVGRect();
					
					// initialize the Rect
					rect.setX(x);
					rect.setY(y);
					rect.setHeight(height);
					rect.setWidth(width);

					// append the Node to the Document
					doc.appendChild(svg);

/***************************************************************************
***

How can I parse the SVGDocument doc to the ServletOutputstream out?

/***************************************************************************
***

					out.println(//doc ??? does not work 
	

		
					
			} catch (Exception e) {
				e.printStackTrace();
			}
}


  	
} // End SVGServlet Class
Received on Monday, 5 June 2000 10:47:52 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:18 GMT