xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bishop, Michael W. CONTR J9C880" <Michael.Bis...@je.jfcom.mil>
Subject RE: InputStream from an SVGDocument?
Date Mon, 14 Nov 2005 20:23:07 GMT
Nevermind...it appears your transcoder solution handles that problem as
well!  I'll just have to transcode it to a String before writing it to a
file and that should work fine.

Michael Bishop

-----Original Message-----
From: Bishop, Michael W. CONTR J9C880
[mailto:Michael.Bishop@je.jfcom.mil] 
Sent: Monday, November 14, 2005 3:02 PM
To: batik-users@xmlgraphics.apache.org; royholl@prologic-inc.com
Subject: RE: InputStream from an SVGDocument?

This is excellent.  It is exactly what I think I need.  I was just
starting to dig into the various streams and figure out the threading.
I would imagine the actual transcoding process should take place in a
Thread to avoid nasty hang-ups with large files.

Here's a somewhat related question; is there a way to "pretty" print an
SVG document to a file?  I'm using DOMUtilities.writeDocument(...) and
it's all on one huge line.  Still looks ugly in a JTextArea with
word-wrap on.  I'm just looking for basic indention.  I know I've seen
this somewhere before, but I can't remember where.

Michael Bishop

-----Original Message-----
From: Roy Hollinger [mailto:royholl@prologic-inc.com] 
Sent: Monday, November 14, 2005 2:55 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: InputStream from an SVGDocument?

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

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

---------------------------------------------------------------------
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