[jdom-interest] Bug regarding attributes local name using JDOMResult?

Mattias Jiderhamn mattias.jiderhamn at expertsystem.se
Thu Nov 10 01:53:44 PST 2005


Hi list.
I am having trouble using the XSL transformer of Caucho Resin 3 
(http://www.caucho.com/resin-3.0) 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.

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)

536:            if (!attQName.equals(attLocalName)) {
537:                String attPrefix = attQName.substring(0, 
attQName.indexOf(":"));

This works fine with Resin 2 and Xalan.

Although the documentation for org.xml.sax.Attributes.getLocalName() 
(see 
http://java.sun.com/j2se/1.5.0/docs/api/org/xml/sax/Attributes.html#getLocalName(int)) 
says

    Returns: The local name, or the empty string if Namespace 
processing is not being performed, or null if the index is out of range.

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.

So, does JDOM need to take into account that the local name can be 
blank? Or is this a bug with Resin 3?



----------------------------

import org.jdom.transform.JDOMResult;
import org.jdom.transform.JDOMSource;
import org.jdom.Element;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import java.io.IOException;
import java.io.StringReader;

public class XslProblemServlet extends HttpServlet {
   protected void service(HttpServletRequest request, 
HttpServletResponse response) throws ServletException, IOException {
     try {
       TransformerFactory transformerFactory = 
TransformerFactory.newInstance();
       StreamSource streamSource = new StreamSource(new StringReader(
           "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
           "<xsl:stylesheet version=\"1.0\" 
xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" +
           "  <xsl:template match=\"/\">\n" +
           "    <bar><child myAttribute=\"myValue\" /></bar>\n" +
           "  </xsl:template>\n" +
           "</xsl:stylesheet>"));
       Transformer transformer = 
transformerFactory.newTransformer(streamSource);

       JDOMSource source = new JDOMSource(new org.jdom.Document(new 
Element("foo")));
       JDOMResult result = new JDOMResult();
       transformer.transform(source, result);
     }
     catch(Exception ex) {
       throw new ServletException(ex);
     }
   }
}





   Mattias Jiderhamn
   Expert Systems

   Mail: 
<mailto:mattias.jiderhamn at expertsystem.se>mattias.jiderhamn at expertsystem.se
   Web: <http://www.expertsystem.se/>www.expertsystem.se
   Skype: <callto://mattiasj78>mattiasj78
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20051110/0bb9fe6d/attachment.htm


More information about the jdom-interest mailing list