You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Thomas Bierhance <uf...@stud.uni-karlsruhe.de> on 2003/10/01 00:06:28 UTC
AbstractTextSerializer.needsNamespacesAsAttributes
Hi,
I tried Cocoon 2.1 with the latest Resin Servlet Container.
Problem:
com.caucho.xml.QDOMException:
`null:' is an invalid XML name because the local name is empty.
XML names must be `prefix:name' or simply `name'.
at com.caucho.xml.QName.init(QName.java:102)
[...]
at com.caucho.xml.DOMBuilder.startElement(DOMBuilder.java:287)
at org.apache.cocoon.serialization.AbstractTextSerializer.needsNamespacesAsAttributes(AbstractTextSerializer.java:341)
The current implementation does use an empty string as qualified
name and is missing a call to endElement():
// Output a single element
handler.startDocument();
handler.startPrefixMapping(prefix, uri);
handler.startElement(uri, "element", "", new AttributesImpl());
handler.endPrefixMapping(prefix);
handler.endDocument();
AbstractTextSerializer.needsNamespace could be changed as follows:
String uri = "namespaceuri";
String prefix = "nsp";
String check = "xmlns:" + prefix + "='" + uri + "'";
String localName="element";
String qName= prefix+":"+localName;
[...]
// Output a single element
handler.startDocument();
handler.startPrefixMapping(prefix, uri);
handler.startElement(uri, localName, qName, new org.xml.sax.helpers.AttributesImpl());
handler.endElement(uri, localName, qName);
handler.endPrefixMapping(prefix);
handler.endDocument();
I tried this code with the Resin Transformer and Xalan. It correctly
detects the two cases without errors.
What do you think?
Regards,
Thomas
Re: AbstractTextSerializer.needsNamespacesAsAttributes
Posted by Torsten Curdt <tc...@vafer.org>.
<snip/>
> I tried this code with the Resin Transformer and Xalan. It correctly
> detects the two cases without errors.
>
> What do you think?
Could you prepare a 'diff -u' patch and file it to bugzilla?
thanks
--
Torsten
Re: AbstractTextSerializer.needsNamespacesAsAttributes
Posted by Thomas Bierhance <uf...@stud.uni-karlsruhe.de>.
I did some testing with different versions of Xalan.
It is referred to Xalan 2.0.1 in AbstractTextSerializer, so I tried
this one, the latest 2.5.1 and the one that is shipping with the
latest jdk (2.4.1).
It seems that Xalan doesn't handle empty qNames very well in all
versions (2.4.1 does not differ from 2.0.1 in behaviour):
supplied uri, empty qName - startElement("namespaceuri", "element", "")
Xalan Java 2.4.1: </>
Xalan Java 2.5.1: < xmlns:nsp="namespaceuri" xmlns="namespaceuri"/>
Caucho: Exception
empty uri, empty qName - startElement("", "element", "")
Xalan Java 2.4.1: </>
Xalan Java 2.5.1: </>
Caucho: <nsp:element/>
supplied uri, qName - startElement("namespaceuri", "element", "nsp:element")
Xalan Java 2.4.1: <nsp:element/>
Xalan Java 2.5.1: <nsp:element xmlns:nsp="namespaceuri"/>
Caucho: <nsp:element xmlns:nsp="namespaceuri"/>
Note that with the current test implementation (supplying uri and
empty qName) Xalan 2.5.1 will pass the test although it's not
handling empty qNames!
I think that things are getting mixed up here. One thing is the
namespace attribute, another the empty qNames issue.
--
Regards,
Thomas mailto:uf4b@stud.uni-karlsruhe.de
Re: AbstractTextSerializer.needsNamespacesAsAttributes
Posted by Thomas Bierhance <uf...@stud.uni-karlsruhe.de>.
SW> Please don't apply the patch, as having an empty qname is an essential
SW> part of the test!
SW> Having an empty qname is allowed by the SAX specification (again, see
SW> ContentHandler.startElement()'s javadoc), but some versions of Xalan
SW> (don't know about the current one) have a bug that lead to improper
SW> serialization if the qname is empty. And this is what is tested here.
Just some more thoughts, because now I'm kind of confused ;-)
I thought the test was to check if the namespace attribute will be
present, isn't it? The test checks if "xmlns:nsp='namespaceuri'" is
present?!
The Caucho transformer does accept an empty qName if the uri is also
empty.
If needsNamespacesAsAttributes returns true, the following calls to
startElement will be intercepted by NamespaceAsAttributes. There the
qualified name is only reconstructed, if the supplied uri is empty...
// try to restore the qName. The map already contains the colon
if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) {
eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
}
This will not solve the problem with empty qNames in all cases.
The Xalan-Bug seems to be fixed by the way:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1348
Some test results:
Running the original test with some Xalan (seems to be a buggy
version) leads to...
Result: </>
Conclusion: Trax handler org.apache.xalan.transformer.TransformerIdentityImpl
needs namespace attributes (will be slower).
Running the modified test with some Xalan...
Result: <nsp:element/>
Conclusion: Trax handler org.apache.xalan.transformer.TransformerIdentityImpl
needs namespace attributes (will be slower).
Running the modified test with Caucho...
Result: <nsp:element xmlns:nsp="namespaceuri"/>
Conclusion: Trax handler com.caucho.xsl.TransformerHandlerImpl handles
correctly namespaces.
I'm by no means into the code, but I thought that this issue might
could need some more revision and this could be helpful.
--
Thomas mailto:uf4b@stud.uni-karlsruhe.de
Re: AbstractTextSerializer.needsNamespacesAsAttributes
Posted by Sylvain Wallez <sy...@anyware-tech.com>.
Joerg Heinicke wrote:
> Hello Thomas,
>
> as you can see in the Javadoc above the method this is a check method
> for namespace handling. I have not written that class and don't know
> whether this bit of code is part of the test, but I don't think so. It
> really looks like a bug.
>
> If no one complains, I can apply the patch. If it should be already in
> 2.1.2 I guess Carsten must apply it. Waiting for a reaction, applying
> and building the dist afterwards takes too much time, doesn't it?
Please don't apply the patch, as having an empty qname is an essential
part of the test!
Having an empty qname is allowed by the SAX specification (again, see
ContentHandler.startElement()'s javadoc), but some versions of Xalan
(don't know about the current one) have a bug that lead to improper
serialization if the qname is empty. And this is what is tested here.
Now it's right that an endElement() is missing, that can be safely
added. We can also surround the test with a try/catch that considers
that namespaceAsAttributes is needed in case of problems.
A question, also: why in hell does the Caucho _serializer_ build a DOM?
That's really overkill!
Sylvain
> Thomas Bierhance wrote:
>
>> Hi,
>>
>> I tried Cocoon 2.1 with the latest Resin Servlet Container.
>>
>> Problem:
>>
>> com.caucho.xml.QDOMException:
>> `null:' is an invalid XML name because the local name is empty.
>> XML names must be `prefix:name' or simply `name'.
>> at com.caucho.xml.QName.init(QName.java:102)
>> [...]
>> at com.caucho.xml.DOMBuilder.startElement(DOMBuilder.java:287)
>> at
>> org.apache.cocoon.serialization.AbstractTextSerializer.needsNamespacesAsAttributes(AbstractTextSerializer.java:341)
>>
>>
>> The current implementation does use an empty string as qualified
>> name and is missing a call to endElement():
>>
>> // Output a single element
>> handler.startDocument();
>> handler.startPrefixMapping(prefix, uri);
>> handler.startElement(uri, "element", "", new AttributesImpl());
>> handler.endPrefixMapping(prefix);
>> handler.endDocument();
>> AbstractTextSerializer.needsNamespace could be changed as follows:
>>
>> String uri = "namespaceuri";
>> String prefix = "nsp";
>> String check = "xmlns:" + prefix + "='" + uri + "'";
>> String localName="element";
>> String qName= prefix+":"+localName;
>> [...]
>> // Output a single element
>> handler.startDocument();
>> handler.startPrefixMapping(prefix, uri);
>> handler.startElement(uri, localName, qName, new
>> org.xml.sax.helpers.AttributesImpl());
>> handler.endElement(uri, localName, qName);
>> handler.endPrefixMapping(prefix);
>> handler.endDocument();
>>
>> I tried this code with the Resin Transformer and Xalan. It correctly
>> detects the two cases without errors.
>> What do you think?
>>
>> Regards,
>> Thomas
>
>
--
Sylvain Wallez Anyware Technologies
http://www.apache.org/~sylvain http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance - http://www.orixo.com
RE: AbstractTextSerializer.needsNamespacesAsAttributes
Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Joerg Heinicke wrote:
>
> as you can see in the Javadoc above the method this is a check method for
> namespace handling. I have not written that class and don't know whether
> this bit of code is part of the test, but I don't think so. It
> really looks
> like a bug.
>
> If no one complains, I can apply the patch. If it should be
> already in 2.1.2
> I guess Carsten must apply it. Waiting for a reaction, applying
> and building
> the dist afterwards takes too much time, doesn't it?
>
If it's not that urgent we should with it until the release is finished.
Carsten
Re: AbstractTextSerializer.needsNamespacesAsAttributes
Posted by Joerg Heinicke <jh...@virbus.de>.
Hello Thomas,
as you can see in the Javadoc above the method this is a check method for
namespace handling. I have not written that class and don't know whether
this bit of code is part of the test, but I don't think so. It really looks
like a bug.
If no one complains, I can apply the patch. If it should be already in 2.1.2
I guess Carsten must apply it. Waiting for a reaction, applying and building
the dist afterwards takes too much time, doesn't it?
Joerg
Thomas Bierhance wrote:
> Hi,
>
> I tried Cocoon 2.1 with the latest Resin Servlet Container.
>
> Problem:
>
> com.caucho.xml.QDOMException:
> `null:' is an invalid XML name because the local name is empty.
> XML names must be `prefix:name' or simply `name'.
> at com.caucho.xml.QName.init(QName.java:102)
> [...]
> at com.caucho.xml.DOMBuilder.startElement(DOMBuilder.java:287)
> at org.apache.cocoon.serialization.AbstractTextSerializer.needsNamespacesAsAttributes(AbstractTextSerializer.java:341)
>
> The current implementation does use an empty string as qualified
> name and is missing a call to endElement():
>
> // Output a single element
> handler.startDocument();
> handler.startPrefixMapping(prefix, uri);
> handler.startElement(uri, "element", "", new AttributesImpl());
> handler.endPrefixMapping(prefix);
> handler.endDocument();
>
> AbstractTextSerializer.needsNamespace could be changed as follows:
>
> String uri = "namespaceuri";
> String prefix = "nsp";
> String check = "xmlns:" + prefix + "='" + uri + "'";
> String localName="element";
> String qName= prefix+":"+localName;
>
> [...]
>
> // Output a single element
> handler.startDocument();
> handler.startPrefixMapping(prefix, uri);
> handler.startElement(uri, localName, qName, new org.xml.sax.helpers.AttributesImpl());
> handler.endElement(uri, localName, qName);
> handler.endPrefixMapping(prefix);
> handler.endDocument();
>
> I tried this code with the Resin Transformer and Xalan. It correctly
> detects the two cases without errors.
>
> What do you think?
>
> Regards,
> Thomas
--
System Development
VIRBUS AG
Fon +49(0)341-979-7419
Fax +49(0)341-979-7409
joerg.heinicke@virbus.de
www.virbus.de