You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> on 2005/11/14 20:04:06 UTC
InputStream from an SVGDocument?
Hello,
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? I could write a temp file, but that
seems sloppy.
Michael Bishop
Re: InputStream from an SVGDocument?
Posted by Roy Hollinger <ro...@prologic-inc.com>.
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" <Mi...@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
Re: InputStream from an SVGDocument?
Posted by th...@kodak.com.
Hi Michael,
"Bishop, Michael W. CONTR J9C880" <Mi...@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...