Weird things are happening with flowXXX and svg12 when I am trying to handle onload events.
Is my code wrong or is it a bug in batik?
Here is what happens when I try different things. The java code and svg file are shown after the different cases. The same jave code is used in all cases. I just changed the svg file.
CASE 1:
SVG file same as below and
- added id="element" to the rect element (to flag the element that will be tested)
==> the "hello" message is not printed in the console (onload event not handled)
CASE 2:
SVG file same as below and
- added a dummy attribute to the rect element
==> the "hello" message is printed (onload event handled)
CASE 3
SVG file same as below and
- added id="element" to the flowPara element (we want to test flowPara now)
- removed comments from flowRoot
==> the "hello" message is not printed in the console (onload event not handled)
CASE 4
SVG file same as below and
- added id="element" to the flowPara element
- removed comments from flowRoot
- added a dummy attribute to the flowPara element
==> ClassCastException see stack trace below
CASE 5
SVG file same as below and
- added id="element" to the flowPara element
- removed comments from flowRoot
- added a dummy attribute to the rect element (just to see what happens)
==> same ClassCastException as in case 4
So from what I see:
1- If I want to handle an onload event in my java code the target needs to have an
2- If there is any flowRoot in the SVG file and a onload attribute, I get a ClassCastException, even if the onload attribute is not on a flowXXX element.
What am I doing wrong?
Particularly, I think that using something like to make it work, at least with non flowXXX element s is strange. I didn't find another way to do it though.
And why it doesn't work anymore with FlowXXX elements?
I badly need to handle svg12 FlowXXX onload events so your help is greatly appreciated.
Thanks.
Oscar
PS: I used batik code checked out today from svn.
-- THE SVG FILE --
<svg
version="1.2"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="300"
height="200"
>
<rect x="50" y="50" width="200" height="100" fill="yellow"/>
<!--flowRoot >
<flowRegion >
<rect x="60" y="60" width="180" height="80" visibility="hidden"/>
</flowRegion>
<flowDiv font-size="12">
<flowPara >Some text</flowPara>
</flowDiv>
</flowRoot-->
</svg>
-- JAVA CODE --
public static void main(String[] args) throws Exception {
File inFile = new File("/tmp/test-flowroot-onload.svg");
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
Document doc = factory.createDocument(inFile.toURL().toString());
EventTarget target = (EventTarget) doc.getElementById("element");
target.addEventListener("SVGLoad", new OnLoadListener(), false);
Transcoder tr = new JPEGTranscoder();
tr.addTranscodingHint(ImageTranscoder.KEY_EXECUTE_ONLOAD, true);
final TranscoderInput in = new TranscoderInput(doc);
final TranscoderOutput out = new TranscoderOutput(new FileOutputStream("/dev/null"));
tr.transcode(in, out);
}
--- EXCEPTION --
Exception in thread "main" java.lang.ClassCastException: org.apache.batik.bridge.BridgeContext
at org.apache.batik.bridge.svg12.SVG12TextElementBridge.addTextEventListeners(SVG12TextElementBridge.java:67)
at org.apache.batik.bridge.SVGTextElementBridge.initializeDynamicSupport(SVGTextElementBridge.java:340)
at org.apache.batik.bridge.SVGTextElementBridge.buildGraphicsNode(SVGTextElementBridge.java:251)
at org.apache.batik.bridge.svg12.SVGFlowRootElementBridge.buildGraphicsNode(SVGFlowRootElementBridge.java:317)
at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:210)
at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:161)
at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:77)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:205)
at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:89)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:155)
at org.jop.main.Main.main(Main.java:29)
Do you Yahoo!?
With a free 1 GB, there's more in store with Yahoo! Mail.
