How can I render a Batik SVG Java object in the view portion of a Spring MVC application?
Posted
by
mattblang
on Stack Overflow
See other posts from Stack Overflow
or by mattblang
Published on 2012-10-05T14:40:08Z
Indexed on
2012/10/09
21:38 UTC
Read the original article
Hit count: 375
I am creating and manipulating a SVGOMDocument
object in a controller method. How can I render this object in a JSP view?
I get very close with the following controller method and <object>
tag.
@RequestMapping(value = "/seal")
public ResponseEntity<SVGDocument> createSeal() throws IOException {
InputStream file = new ClassPathResource("seal.svg").getInputStream();
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
SVGDocument svg = (SVGDocument) factory.createDocument("http://www.w3.org/2000/svg", file);
svg.getElementById("name").getFirstChild().setNodeValue("a test name");
return new ResponseEntity<SVGDocument>(svg, HttpStatus.OK);
}
<object data="/seal" type="image/svg+xml"></object>
This displays a string of XML that is a SVG. The string is in quotes with every XML quote escaped.
© Stack Overflow or respective owner