1 34 35 package org.krysalis.jcharts.encoders; 36 37 38 import org.apache.batik.dom.GenericDOMImplementation; 39 import org.apache.batik.svggen.SVGGraphics2D; 40 import org.krysalis.jcharts.Chart; 41 import org.krysalis.jcharts.chartData.ChartDataException; 42 import org.krysalis.jcharts.imageMap.ImageMapNotSupportedException; 43 import org.krysalis.jcharts.properties.PropertyException; 44 import org.w3c.dom.DOMImplementation ; 45 import org.w3c.dom.Document ; 46 47 import java.io.IOException ; 48 import java.io.OutputStream ; 49 import java.io.OutputStreamWriter ; 50 import java.io.Writer ; 51 52 53 59 public class SVGEncoder 60 { 61 62 66 private SVGEncoder() throws Exception 67 { 68 throw new Exception ( "No need to create an instance of this class!" ); 69 } 70 71 72 82 public static void encode( Chart chart, OutputStream outputStream ) throws ChartDataException, PropertyException, IOException 83 { 84 if( chart.getImageMap() != null ) 86 { 87 throw new ImageMapNotSupportedException( "HTML client-side image maps are not supported by the SVG format." ); 88 } 89 90 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 92 93 Document document = domImpl.createDocument( null, "svg", null ); 95 96 SVGGraphics2D svgGenerator = new SVGGraphics2D( document ); 98 99 chart.setGraphics2D( svgGenerator ); 100 chart.render(); 101 102 Writer writer = new OutputStreamWriter ( outputStream, "UTF-8" ); 103 svgGenerator.stream( writer, false ); 104 105 writer.flush(); 106 writer.close(); 107 } 108 } 109 | Popular Tags |