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 Murray Steele <mu...@peoplesarchive.com> on 2006/03/15 13:55:57 UTC

Batik 1.6, XSLT->SVG->Transcoder (using svg1.2 flowRoot bits)

Hi all,

I've got a XML+XSLT->SVG->Tiff/Png/PDF pipeline that I coded up about a 
year ago to generate some graphics.  I've come back to it and upgraded 
to Batik 1.6 because I wanted to use the flowing text stuff (flowRoot 
etc..) that Batik now supports.  Unfortunately my old code doesn't seem 
to be generating the correct SVG Documents - I'm getting:

"The current document is unable to create an element of the requested 
type (namespace: http://www.w3.org/2000/svg, name: svg:flowRoot)"

errors when I try to transcode my SVG file.

I haven't changed the code that I'm using[1] since I switched to 
batik1.6.  The SVG that my XML/XSLT generates has the version="1.2" 
attribute on the svg root element, and it works if I run it in 
Squiggle, so I'm assuming that it's just some code configuration that 
I've got wrong.  I've seen some rumblings about SAXSVGDocumentFactory 
.. but I'm not using a DocumentFactory to generate anything, can I 
change over easily?  I'm also not sure if any other jars needs to be 
updated (xml-apis, etc...) to facilitate the change over to batik1.6 
from 1.5.

Anyone got any ideas?

Cheers

Muz




[1]Code to generate image from XML+XSLT via SVG + Transcoder:

Source xml = new StreamSource(this.xmlReader); //this.xmlReader 
implements org.xml.sax.XMLReader
Source xslt = new StreamSource(new StringReader(this.storyTitleXslt));

Transformer transformer = 
TransformerFactory.newInstance().newTransformer(xslt);

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);

DocumentBuilder documentBuilder = dbf.newDocumentBuilder();

Document document = documentBuilder.newDocument();
ContentHandler contentHandler = new DOMBuilder(document);
Result res = new SAXResult(contentHandler);
transformer.transform(xml, res);
Transcoder t = SVGFactory.getTranscoder(rasterType);
ByteArrayOutputStream bytes = new 
ByteArrayOutputStream(this.byteArraySize);
TranscoderInput in = new TranscoderInput(svg);
TranscoderOutput out = new TranscoderOutput(bytes);
t.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, this.imageHeight);
t.addTranscodingHint(ImageTranscoder.KEY_WIDTH, this.imageWidth);
t.transcode(in,out);



--
Murray Steele
Head of Development

Peoples Archive
w: http://www.peoplesarchive.com
t: 0207 323 0323
d: 0207 631 9147 

This email has been scanned by Postini.
For more information please visit http://www.postini.com


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


Re: Batik 1.6, XSLT->SVG->Transcoder (using svg1.2 flowRoot bits)

Posted by Murray Steele <mu...@peoplesarchive.com>.
Actually, I did some more digging in the Batik sources and I nailed it 
down to the following:

1. when I do my transform I'm not creating a SVGDocument, just a boring 
old Document.
2. the SVGAbstractTranscoder notices this during Transcode and clones 
the document into an SVGDocument.
3. when it does this it asks the Transcoder for the hint as to which 
DOMImplementation to use, and by default the transcoder uses the 
1.0/1.1 DOMImplementation.
    (lines: 173-186 in SVGAbstractTranscoder.java)

So I've got round this by altering my code[1] to work out what version 
of SVG the incoming document is using and setting a transcoding hint on 
the transcoder as appropriate.  And it works!  Hurrah!

Still, it doesn't seem right that this is what you have to do to get 
XSL+SVG+Transcoding to work.  Are there any better solutions, perhaps 
to do with how I do the transform / create the document in the first 
place?  Or is it perhaps a bug/feature enhancement that could be filed? 
Should the transcoder try to work this kind of thing out; just because 
the incoming Document isn't an SVGDocument doesn't actually mean it's 
not an SVG document.

Muz

[1] - settting a new transcoder hint after working out what the 
incoming document is
if (svg.getDocumentElement().getLocalName().equals("svg") && 
svg.getDocumentElement().hasAttribute("version")) {
     String version = svg.getDocumentElement().getAttribute("version");
     if ((version == null) || (version.length()==0) || 
version.equals("1.0") || version.equals("1.1")) {
         
t.addTranscodingHint(XMLAbstractTranscoder.KEY_DOM_IMPLEMENTATION, 
SVGDOMImplementation.getDOMImplementation());
     } else {
         
t.addTranscodingHint(XMLAbstractTranscoder.KEY_DOM_IMPLEMENTATION, 
SVG12DOMImplementation.getDOMImplementation());
     }
}



On 15 Mar 2006, at 12:55, Murray Steele wrote:

> Hi all,
>
> I've got a XML+XSLT->SVG->Tiff/Png/PDF pipeline that I coded up about 
> a year ago to generate some graphics.  I've come back to it and 
> upgraded to Batik 1.6 because I wanted to use the flowing text stuff 
> (flowRoot etc..) that Batik now supports.  Unfortunately my old code 
> doesn't seem to be generating the correct SVG Documents - I'm getting:
>
> "The current document is unable to create an element of the requested 
> type (namespace: http://www.w3.org/2000/svg, name: svg:flowRoot)"
>
> errors when I try to transcode my SVG file.
>
> I haven't changed the code that I'm using[1] since I switched to 
> batik1.6.  The SVG that my XML/XSLT generates has the version="1.2" 
> attribute on the svg root element, and it works if I run it in 
> Squiggle, so I'm assuming that it's just some code configuration that 
> I've got wrong.  I've seen some rumblings about SAXSVGDocumentFactory 
> .. but I'm not using a DocumentFactory to generate anything, can I 
> change over easily?  I'm also not sure if any other jars needs to be 
> updated (xml-apis, etc...) to facilitate the change over to batik1.6 
> from 1.5.
>
> Anyone got any ideas?
>
> Cheers
>
> Muz
>
>
>
>
> [1]Code to generate image from XML+XSLT via SVG + Transcoder:
>
> Source xml = new StreamSource(this.xmlReader); //this.xmlReader 
> implements org.xml.sax.XMLReader
> Source xslt = new StreamSource(new StringReader(this.storyTitleXslt));
>
> Transformer transformer = 
> TransformerFactory.newInstance().newTransformer(xslt);
>
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> dbf.setNamespaceAware(true);
>
> DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
>
> Document document = documentBuilder.newDocument();
> ContentHandler contentHandler = new DOMBuilder(document);
> Result res = new SAXResult(contentHandler);
> transformer.transform(xml, res);
> Transcoder t = SVGFactory.getTranscoder(rasterType);
> ByteArrayOutputStream bytes = new 
> ByteArrayOutputStream(this.byteArraySize);
> TranscoderInput in = new TranscoderInput(svg);
> TranscoderOutput out = new TranscoderOutput(bytes);
> t.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, this.imageHeight);
> t.addTranscodingHint(ImageTranscoder.KEY_WIDTH, this.imageWidth);
> t.transcode(in,out);
>
>
>
> --
> Murray Steele
> Head of Development
>
> Peoples Archive
> w: http://www.peoplesarchive.com
> t: 0207 323 0323
> d: 0207 631 9147
> This email has been scanned by Postini.
> For more information please visit http://www.postini.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: 
> batik-users-help@xmlgraphics.apache.org
>
>
--
Murray Steele
Head of Development

Peoples Archive
w: http://www.peoplesarchive.com
t: 0207 323 0323
d: 0207 631 9147

This email has been scanned by Postini.
For more information please visit http://www.postini.com


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