<html>
<body>
Hi list.<br>
I am having trouble using the XSL transformer of Caucho Resin 3
(<a href="http://www.caucho.com/resin-3.0" eudora="autourl">
http://www.caucho.com/resin-3.0</a>) together with JDOM. The problem
occurs when using attributes without namespace and outputting to a
JDOMResult. On the one hand this worked fine with Resin 2, on the other
hand Resin 3 seems to follow the specification more closely, so I'm not
quite sure whether the problem lies with Resin or JDOM.<br><br>
The point of problem is in org.jdom.input.SAXHandler.startElement(). Here
it is assumed that the local name of the attribute is equal to the QName,
if no namespace/prefix is used. (Line numbers from 1.0 release)<br><br>
536: if
(!attQName.equals(attLocalName)) {<br>
537:
String attPrefix = attQName.substring(0,
attQName.indexOf(":"));<br><br>
This works fine with Resin 2 and Xalan.<br><br>
Although the documentation for org.xml.sax.Attributes.getLocalName() (see
<a href="http://java.sun.com/j2se/1.5.0/docs/api/org/xml/sax/Attributes.html#getLocalName(int" eudora="autourl">
http://java.sun.com/j2se/1.5.0/docs/api/org/xml/sax/Attributes.html#getLocalName(int</a>
)) says <br><br>
Returns: The local name, or the empty string if Namespace
processing is not being performed, or null if the index is out of
range.<br><br>
So Resin 3 returns the emtpy string in this case, which causes
"java.lang.StringIndexOutOfBoundsException: String index out of
range: -1" on line 537 above. Below you will find a self contained
example.<br><br>
So, does JDOM need to take into account that the local name can be blank?
Or is this a bug with Resin 3?<br><br>
<br><br>
----------------------------<br><br>
import org.jdom.transform.JDOMResult;<br>
import org.jdom.transform.JDOMSource;<br>
import org.jdom.Element;<br><br>
import javax.servlet.http.HttpServlet;<br>
import javax.servlet.http.HttpServletRequest;<br>
import javax.servlet.http.HttpServletResponse;<br>
import javax.servlet.ServletException;<br>
import javax.xml.transform.TransformerFactory;<br>
import javax.xml.transform.Transformer;<br>
import javax.xml.transform.stream.StreamSource;<br>
import java.io.IOException;<br>
import java.io.StringReader;<br><br>
public class XslProblemServlet extends HttpServlet {<br>
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {<br>
try {<br>
TransformerFactory transformerFactory =
TransformerFactory.newInstance();<br>
StreamSource streamSource = new
StreamSource(new StringReader(<br>
"<?xml
version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
+<br>
"<xsl:stylesheet version=\"1.0\"
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
+<br>
"
<xsl:template match=\"/\">\n" +<br>
" <bar><child
myAttribute=\"myValue\" /></bar>\n" +<br>
"
</xsl:template>\n" +<br>
"</xsl:stylesheet>"));<br>
Transformer transformer =
transformerFactory.newTransformer(streamSource);<br><br>
JDOMSource source = new JDOMSource(new
org.jdom.Document(new Element("foo")));<br>
JDOMResult result = new JDOMResult();<br>
transformer.transform(source,
result);<br>
}<br>
catch(Exception ex) {<br>
throw new ServletException(ex);<br>
}<br>
}<br>
}<br><br>
<br><br>
<br>
<x-sigsep><p></x-sigsep>
Mattias Jiderhamn<br>
Expert Systems<br><br>
<i> Mail</i>:
<a href="mailto:mattias.jiderhamn@expertsystem.se">
mattias.jiderhamn@expertsystem.se</a> <br>
<i> Web</i>:
<a href="http://www.expertsystem.se/">www.expertsystem.se</a> <br>
<i> Skype</i>: <a href="callto://mattiasj78">mattiasj78<br>
</a></body>
</html>