Hi,
I stumbled upon a problem concerning deep cloning of nodes in SVG 1.2
documents. I have got an SVG 1.2 document with a metadata element that
has got a child element in a custom namespace. Now, if I try to get a
deep clone of any direct or indirect parent of that custom element by
calling the node.clone(true), I get a NullPointerException, because
the owner document of the cloned custom element is not set.
My SVG document looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<svg externalResourcesRequired="true" height="300mm"
preserveAspectRatio="none" version="1.2" viewBox="0 0 300 300"
width="300mm" xmlns="http://www.w3.org/2000/svg"
xmlns:cns="http://my/custom/namespace" xmlns:xlink="http://www.w3.org/1999/xlink
">
<g>
<metadata>
<cns:mymetadata attr1="value" attr2="value" />
</metadata>
<g transform="translate(24.745000000000005 18.049999999999997)
rotate(0)">
<rect width="100" height="50" fill="red" />
</g>
</g>
</svg>
The stacktrace I get is the following:
Exception in thread "main" java.lang.NullPointerException
at
org
.apache
.batik.dom.svg.SVGOMElement.createLiveAnimatedString(SVGOMElement.java:
390)
at
org
.apache
.batik
.dom
.svg
.SVGStylableElement.initializeLiveAttributes(SVGStylableElement.java:
118)
at
org
.apache
.batik.dom.svg.SVGStylableElement.<init>(SVGStylableElement.java:103)
at
org
.apache
.batik.dom.svg.SVGGraphicsElement.<init>(SVGGraphicsElement.java:96)
at
org.apache.batik.dom.svg12.BindableElement.<init>(BindableElement.java:
68)
at
org
.apache.batik.dom.svg12.BindableElement.newNode(BindableElement.java:99)
at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:309)
at
org
.apache
.batik.dom.AbstractParentNode.deepCopyInto(AbstractParentNode.java:377)
at
org.apache.batik.dom.AbstractElement.deepCopyInto(AbstractElement.java:
563)
at
org.apache.batik.dom.svg.SVGOMElement.deepCopyInto(SVGOMElement.java:
891)
at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:309)
at
org
.apache
.batik.dom.AbstractParentNode.deepCopyInto(AbstractParentNode.java:377)
at
org.apache.batik.dom.AbstractElement.deepCopyInto(AbstractElement.java:
563)
at
org.apache.batik.dom.svg.SVGOMElement.deepCopyInto(SVGOMElement.java:
891)
at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:309)
at
org
.apache
.batik.dom.AbstractParentNode.deepCopyInto(AbstractParentNode.java:377)
at
org.apache.batik.dom.AbstractElement.deepCopyInto(AbstractElement.java:
563)
at
org.apache.batik.dom.svg.SVGOMElement.deepCopyInto(SVGOMElement.java:
891)
at org.apache.batik.dom.AbstractNode.cloneNode(AbstractNode.java:309)
at CloneNodeTest.main(CloneNodeTest.java:25)
When change the version of the SVG document to 1.1, everything works
fine.
I already did some debugging, and apparently, the custom
cns:mymetadata element from my example SVG document is being
represented by a BindableElement if the SVG12DOMImplementation is
used, whereas it is a GenericElementNS for SVG 1.1. I don't know if
this by itself is already the problem that causes the NPE. But at
least I find it somewhat strange that a custom element that is a child
of an SVG metadata element and will thus never ever be rendered, is
represented by a subclass of SVGGraphicsElement.
I managed to get rid of this problem by patching Batik so that the
SVG12DOMImplementation always returns a GenericElementNS instead of a
BindableElement. But I suppose that this is not really an acceptable
solution to the problem because custom elements that are not children
of a metadata element and are thus supposed to be rendered will not
work any more.
Any help with this problem is much appreciated.
Thanks in advance,
Daniel
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]