You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Andreas Bielk <an...@codesense.com> on 2001/07/04 13:19:04 UTC

Bug?

Here is the situation:

We add a <use> element to an existing DOM tree with:

Element e = document.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI,
"use");
e.setAttributeNS(null, "x", "10" );
e.setAttributeNS(null, "y", "20" );
e.setAttributeNS(XLinkSupport.XLINK_NAMESPACE_URI, "href", "#MyRef" );

When we try to transcode the DOM, Batik dumps the stacktrace below.

java.lang.NullPointerException
	at org.apache.batik.bridge.URIResolver.getNode(URIResolver.java:86)
	at org.apache.batik.bridge.URIResolver.getElement(URIResolver.java:62)
	at
org.apache.batik.bridge.BridgeContext.getReferencedElement(BridgeContext.jav
a:277)
	at
org.apache.batik.bridge.SVGUseElementBridge.createGraphicsNode(SVGUseElement
Bridge.java:64)
	at
org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:170)
	at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:136)
	at
org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:176)
	at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:136)
	at
org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:176)
	at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:136)
	at
org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:176)
	at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:136)
	at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:69)
	at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.
java:155)
	at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTrans
coder.java:126)
	at
com.codesense.financial.iserver.test.TestRunner.savePNG(TestRunner.java:230)
	at
com.codesense.financial.iserver.test.TestRunner.runTest(TestRunner.java:131)
	at
com.codesense.financial.iserver.test.TestRunner.main(TestRunner.java:326)


Looking at URIResolver.getNode()
...
        if (uri.startsWith("#")) {
            return document.getElementById(uri.substring(1));
        }

        if (documentURI == null)
            documentURI = document.getURL();

        if (documentURI.equals(uri)) {
            return document;
        }
...

and SVGOMDocument.getURL()
       return (url == null) ? null : url.toString();

It´s clear that there´s a bug in getNode(), but is that really the problem?
When we serializes the DOM to a textfile
(org.apache.batik.dom.util.DOMUtilities.writeDocument)
the "href" attribute of the <use> have a missing namespace prefix.

Thoughts anyone? This is a showstopper right now for us..


Regards, Andreas Bielk

/**********************************************************
                  C o d e S e n s e  A B
       Marinens väg 30, SE-136 40 Haninge, Sweden
Office: +46 (0)8 - 707 32 30  GSM: +46 (0)70 - 532 92 01
                 http://www.codesense.com
***********************************************************/
    (PGP public key available at: search.keyserver.net)


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


RE: Bug?

Posted by Andreas Bielk <an...@codesense.com>.
> Sorry but I don't think there is a bug in getNode. I think you have not
> specified the URI of the document (this one is required to handle use
> element).
>
> > (org.apache.batik.dom.util.DOMUtilities.writeDocument)
> > the "href" attribute of the <use> have a missing namespace prefix.

Ok, but is it really a good design to let URIResolver.getNode()
result in a NullPointerExcepion when the URI is missing?

Hmm, shouldn´t the document URI specified if I create the DOM with:
SAXSVGDocumentFactory factory = new
SAXSVGDocumentFactory("org.apache.xerces.parsers.SAXParser");
SVGOMDocument document =
factory.createDocument("http://codesense.com/templates/"+id,new
StringReader(_data));

> According to the DOM spec, the setAttributeNS method takes a
> qualifiedName
> and not a localName.
>
> The setAttributeNS(xlinkNamespaceURI, "xlink:href", ...);
> will solve your second problem.

Doh! I knew that :-') that solved the NullPointerException...

Thanks / Andreas

/**********************************************************
                  C o d e S e n s e  A B
       Marinens väg 30, SE-136 40 Haninge, Sweden
Office: +46 (0)8 - 707 32 30  GSM: +46 (0)70 - 532 92 01
                 http://www.codesense.com
***********************************************************/
    (PGP public key available at: search.keyserver.net)


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


Re: Bug?

Posted by Thierry Kormann <tk...@sophia.inria.fr>.
On Wednesday 04 July 2001 13:19, Andreas Bielk wrote:
> Here is the situation:
>
> We add a <use> element to an existing DOM tree with:
>
> It´s clear that there´s a bug in getNode(), but is that really the problem?
> When we serializes the DOM to a textfile

Sorry but I don't think there is a bug in getNode. I think you have not 
specified the URI of the document (this one is required to handle use 
element).

> (org.apache.batik.dom.util.DOMUtilities.writeDocument)
> the "href" attribute of the <use> have a missing namespace prefix.

According to the DOM spec, the setAttributeNS method takes a qualifiedName 
and not a localName.

The setAttributeNS(xlinkNamespaceURI, "xlink:href", ...);

will solve your second problem.

Thierry.

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