xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Eisenberg <da...@catcode.com>
Subject XSL to SVG to JPG transcode error
Date Thu, 16 Aug 2001 21:37:27 GMT
I am attempting to read an XML file, use Xalan to convert it to
SVG, and then use Batik's transcoder to create a JPG file to send
to a user (all this from a servlet). I get a transcoder failure,
as shown below.

Here's the relevant part of the doPost() section of the servlet.
Any suggestions/cures would be greatly appreciated.
=================================

    private Document svgDoc;
    private String retrievedXML;
    StylesheetRoot xslTemplate;
    
    try
    {
        //for storing a compiled and resuseable style sheet
        TransformerFactory factory = TransformerFactory.newInstance();
        xslTemplate = factory.newTemplates("convert_to_svg.xsl");
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }


    retrievedXML = getXML( request );
    try
    {
        xmlString = new StreamSource(
            new StringReader( retrievedXML )
        );
        Transformer transformer = xslTemplate.newTransformer();
        transformer.setOutputProperty("encoding", "UTF-8");

        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();

        /* This is necessary; otherwise the transcoder gets
           a different error (java.lang.ClassCastException:
            org.apache.batik.dom.GenericElement
            at org.apache.batik.dom.svg.SVGOMDocument.getRootElement
            (SVGOMDocument.java:519)  */
        String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        svgDoc = impl.createDocument( svgNS, "svg", null );                         

        transformDOM = new DOMResult(
            svgDoc.getDocumentElement() );

        transformer.transform(
            xmlString,
            transformDOM
        );

        response.setContentType("image/jpeg");
        response.setHeader("Cache-Control",
            "no-cache, post-check=0, pre-check=0");
        String agent = request.getHeader("User-Agent").toLowerCase();
        // netscape chokes on Pragma no-cahe so only send it to explorer
        if (agent.indexOf("explorer") > -1){
          response.setHeader("Pragma", "no-cache");
        }
        response.setHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");

        JPEGTranscoder t = new JPEGTranscoder();
        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
                             new Float(.8));

        // create the transcoder input
        TranscoderInput input = new TranscoderInput( svgDoc );
        try {
            TranscoderOutput output =
                new TranscoderOutput(response.getWriter());
            t.transcode(input, output); /* error occurs here */
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }


========================================================
I get this error:

org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
null
    at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:262)
    at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:126)
    at Transform.doPost(Transform.java:145)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
    at org.apache.tomcat.core.Handler.service(Handler.java:287)
    at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
    at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
    at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
    at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
    at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
    at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
    at java.lang.Thread.run(Thread.java:484)
    
Debug output shows that neither input nor output is null;
       Input doc is org.apache.batik.dom.svg.SVGOMDocument@502819
       output is org.apache.batik.transcoder.TranscoderOutput@78aa80E

-- 
J. David Eisenberg
http://catcode.com


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


Mime
View raw message