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
