You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Thierry Kormann <tk...@sophia.inria.fr> on 2001/04/15 19:38:34 UTC

Batik and servlet technology

Hi,

Here is just a proof of concept: a small servlet I have hacked. It displays a 
PNG image using the parameter 'image' (which has to be a URI).

example of use:

<img src="../servlet/SVGServlet?image=http://localhost:8080/batikFX.svg" 
width="450" height="500">

I have used tomcat.

-------

/*****************************************************************************
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included with this distribution in  *
 * the LICENSE file.                                                         *
 *****************************************************************************
/

import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.batik.transcoder.*;
import org.apache.batik.transcoder.image.*;


/**
 * A servlet that returns a PNG image. Specify the URI of the image using the
 * 'image' parameter.
 *
 * <p>Example of use:</p>

 * <pre>
 * &lt;img src="../servlet/SVGServlet?image=http://localhost:8080/batikFX.svg"
 * width="450" height="500">
 * </pre>
 *
 * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry 
Kormann</a>
 * @version $Id$
 */
public class SVGServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse 
response)
        throws IOException, ServletException {

        response.setContentType("image/png");
        OutputStream ostream = response.getOutputStream();
        TranscoderOutput output = new TranscoderOutput(ostream);

        URL url = new URL(request.getParameter("image"));
        TranscoderInput input = new TranscoderInput(url.openStream());
        PNGTranscoder t = new PNGTranscoder();
        t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_CLASSNAME,
                             "org.apache.crimson.parser.XMLReaderImpl");
        try {
            t.transcode(input, output);
        } catch (TranscoderException ex) { }
    }
}

-------

Have fun.
Thierry.

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


Re: Batik and servlet technology

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Thierry Kormann" <tk...@sophia.inria.fr>
To: <ba...@xml.apache.org>
Sent: Sunday, April 15, 2001 10:38
Subject: Batik and servlet technology


>
> Hi,
>
> Here is just a proof of concept: a small servlet I have hacked. It
displays a
> PNG image using the parameter 'image' (which has to be a URI).
>
> example of use:
>
> <img src="../servlet/SVGServlet?image=http://localhost:8080/batikFX.svg"
> width="450" height="500">
>
> I have used tomcat.

Sweet. simple, yet functional.

I've done some more complex versions of the same thing, using Posted
content.

If there is one thing that we needed to be careful of, it was not exposing
security issues by accepting file: urls in the request, otherwise I can get
/etc/passwd rendered to a bitmap in a nice font. As well as tuning the
security params in tomcat to do the right thing, we scan through the
incoming SVG to intercept some remote http links and remap them to local
caches. It all seems to work ok.

-steve


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