xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roy Hollinger <royh...@prologic-inc.com>
Subject Re: InputStream from an SVGDocument?
Date Mon, 14 Nov 2005 19:54:35 GMT
Some of my code converts an in memory SVGDocument into a string to output 
elsewhere. (It has the newlines in it already, so you can just put it into a 
text pane.)

The entire code follows:
    static public String ConvertSVGDocToString(SVGDocument doc)
    {
        String result = null;
        try {
            StringWriter os = new StringWriter();
		// need to put this string in to make it correct.
            String docType =  "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 
20001102//EN\" "
                +   "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
            TranscoderInput input = new TranscoderInput(doc);
            TranscoderOutput output = new TranscoderOutput(os);
            Transcoder svgT = new SVGTranscoder();
            svgT.transcode(input, output);
            result = docType + os.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

On Monday 14 November 2005 02:15 pm, thomas.deweese@kodak.com wrote:
> Hi Michael,
>
> "Bishop, Michael W. CONTR J9C880" <Michael.Bishop@je.jfcom.mil> wrote on
>
> 11/14/2005 02:04:06 PM:
> >      I’m trying to implement/borrow the “View Source” functionality from
>
> the
>
> > Squiggle application, but I’ve hit a small roadblock.  The Squiggle
> > application needs the document’s URL to load and display the data.  What
> >
> > happens if I have an SVG file that hasn’t been saved yet?  Is there a
>
> way to
>
> > get an InputStream to it?
>
>    The DOM has no 'stream' representation handy so the best you can do
> is serialize the DOM (dom.util.DOMUtilities) to a stream.  At this point
> you have two main options, one serialize to a ByteArrayOutputStream and
> then wrap the generated byte array with a ByteArrayInputStream (i.e.
> write to a temp file in memory), or get fancy with Input/Output Stream
> Pipes.  The tricky bit with pipes is that you have to ensure that the
> reader and writer are in different threads (which could get complex,
> or simple, given that the DOM can only be accessed safely in the
> UpdateManager Thread), I think java 5 has some interesting things along
> these lines but I don't know any of the details.
>
> > I could write a temp file, but that seems sloppy.
>
>    The ByteArray stream is what most people seem to do...

-- 
Roy Hollinger
Senior Software Engineer
ProLogic, Inc.
royholl@prologic-inc.com


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


Mime
View raw message