Search in sources :

Example 1 with SVGPlugin

use of com.xpn.xwiki.plugin.svg.SVGPlugin in project xwiki-platform by xwiki.

the class ChartingPlugin method generateSvgChart.

private Chart generateSvgChart(JFreeChart jfchart, ChartParams params, XWikiContext context) throws IOException, GenerateException {
    // Get a DOMImplementation
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    // Create an instance of org.w3c.dom.Document
    Document document = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null);
    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
    // Ask the chart to render into the SVG Graphics2D implementation
    Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, params.getInteger(ChartParams.WIDTH).intValue(), params.getInteger(ChartParams.HEIGHT).intValue());
    jfchart.draw(svgGenerator, rect);
    boolean useCSS = false;
    StringWriter swriter = new StringWriter();
    svgGenerator.stream(swriter, useCSS);
    String svgText = swriter.toString();
    String pageURL = null;
    SVGPlugin svgPlugin = (SVGPlugin) context.getWiki().getPlugin("svg", context);
    if (svgPlugin == null) {
        throw new GenerateException("SVGPlugin not loaded");
    }
    String imageURL;
    try {
        imageURL = svgPlugin.getSVGImageURL(svgText, params.getInteger(ChartParams.HEIGHT).intValue(), params.getInteger(ChartParams.WIDTH).intValue(), context);
    } catch (SVGConverterException sce) {
        throw new GenerateException(sce);
    }
    return new ChartImpl(params, imageURL, pageURL);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) DOMImplementation(org.w3c.dom.DOMImplementation) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document) SVGPlugin(com.xpn.xwiki.plugin.svg.SVGPlugin) GenerateException(com.xpn.xwiki.plugin.charts.exceptions.GenerateException) StringWriter(java.io.StringWriter) SVGConverterException(org.apache.batik.apps.rasterizer.SVGConverterException)

Example 2 with SVGPlugin

use of com.xpn.xwiki.plugin.svg.SVGPlugin in project xwiki-platform by xwiki.

the class SVGAction method render.

@Override
public String render(XWikiContext context) throws XWikiException {
    XWikiRequest request = context.getRequest();
    String path = request.getRequestURI();
    String filename = Util.decodeURI(path.substring(path.lastIndexOf("/") + 1), context);
    try {
        ((SVGPlugin) context.getWiki().getPlugin("svg", context)).outputSVGImageFromFile(filename, context);
    } catch (IOException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION, "Exception while sending response", e);
    }
    return null;
}
Also used : IOException(java.io.IOException) SVGPlugin(com.xpn.xwiki.plugin.svg.SVGPlugin) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

SVGPlugin (com.xpn.xwiki.plugin.svg.SVGPlugin)2 XWikiException (com.xpn.xwiki.XWikiException)1 GenerateException (com.xpn.xwiki.plugin.charts.exceptions.GenerateException)1 Rectangle2D (java.awt.geom.Rectangle2D)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 SVGConverterException (org.apache.batik.apps.rasterizer.SVGConverterException)1 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)1 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)1 DOMImplementation (org.w3c.dom.DOMImplementation)1 Document (org.w3c.dom.Document)1