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

Mattias Jiderhamn mattias.jiderhamn at expertsystem.se
Mon Nov 21 11:01:54 PST 2005


Actually, I haven't since I reasoned this wasn't necessary.

The only case when the current code would produce the expected output 
while the patched code would not, is if attQName contains both prefix 
and name while attLocalName is the empty string. I figured that if 
such a parser exists, it is erroneous and it shouldn't be JDOMs 
responsibility to handle this. But maybe I'm wrong here?

If I'm wrong, is there a particular set of parser that should be 
tested ("the parsers")?

   /Mattias Jiderhamn

At 2005-11-21 18:48, you wrote:
>Have you tested it w/ the various parsers?
>
>-jh-
>
>Mattias Jiderhamn wrote:
>
>>Here is a patch (against the CVS head) that fixes the issue:
>>Index: src/java/org/jdom/input/SAXHandler.java
>>===================================================================
>>RCS file: /home/cvspublic/jdom/src/java/org/jdom/input/SAXHandler.java,v
>>retrieving revision 1.71
>>diff -u -r1.71 SAXHandler.java
>>--- src/java/org/jdom/input/SAXHandler.java     11 Dec 2004 
>>02:18:55 -0000      1.71
>>+++ src/java/org/jdom/input/SAXHandler.java     11 Nov 2005 08:04:54 -0000
>>@@ -560,7 +560,11 @@
>>                  continue;
>>              }
>>-            if (!attQName.equals(attLocalName)) {
>>+            if ("".equals(attLocalName)) { // "Namespace 
>>processing is not being performed"
>>+                attribute = factory.attribute(attQName, atts.getValue(i),
>>+                                              attType);
>>+                       }
>>+            else if (!attQName.equals(attLocalName)) {
>>                  String attPrefix = attQName.substring(0, 
>> attQName.indexOf(":"));
>>                  Namespace attNs = Namespace.getNamespace(attPrefix,
>>                                                           atts.getURI(i));
>>
>>At 2005-11-10 10:53, you wrote:
>>
>>>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);
>>>     }
>>>   }
>>>}
>>
>>_______________________________________________
>>To control your jdom-interest membership:
>>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
>
>
>   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/20051121/f969dbfd/attachment.htm


More information about the jdom-interest mailing list