cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 23714] New: - Bug in SessionAttributeGenerator, double startDoc/endDoc SAX events generated
Date Fri, 10 Oct 2003 03:04:00 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23714>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23714

Bug in SessionAttributeGenerator, double startDoc/endDoc SAX events generated

           Summary: Bug in SessionAttributeGenerator, double startDoc/endDoc
                    SAX events generated
           Product: Cocoon 2
           Version: 2.1.2
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: sitemap components
        AssignedTo: dev@cocoon.apache.org
        ReportedBy: andrzej@chaeron.com


I ran into what seems to be the infamous "failed to execute pipeline"
problem with Cocoon 2.1.2 in trying to execute a simple XSLT transform.  

Eliminating the transform from the pipeline and serializing directly to
XML showed well formed XML going into the transform step, which was very
frustrating, so I put in a logging transform. Lo and behold, the logger
showed that the startDocument and endDocument SAX events were doubled up!

What caused this problem is that I had set a session attribute to hold the
XML document I wanted transformed, but I had set that attribute to be the
DOM Document object, then used SessionAttributeGenerator to create the SAX
event stream for the transformation.  This should be perfectly acceptable!

Problem is that the generate() method in SessionAttributeGenerator looks
as follows:

public void generate() throws IOException, SAXException,
ProcessingException {
 xmlConsumer.startDocument();

 if (this.elementName != null) {
  xmlConsumer.startElement("", this.elementName, this.elementName, new
  AttributesImpl()); XMLUtils.valueOf(xmlConsumer, this.attrObject);
  xmlConsumer.endElement("", this.elementName, this.elementName);
 } else {
  XMLUtils.valueOf(xmlConsumer, this.attrObject);
 }

 xmlConsumer.endDocument();
}

The bug is evident because if the this.attrObject is set to a Document
object (rather than the document root Element), the method generates a
start/end document....but so does the interior code! So you get duplicate
start/endDocument events generated and downstream XSLT transforms barf on
the input (funny that the XML serializer doesn't much care about this
duplication).

Anyway, rewriting the generate() method of SessionAttributeGenerator will
correct this insidious bug:

public void generate() throws IOException, SAXException,
ProcessingException {
 if( !( attrObject instanceof Document ) {
  xmlConsumer.startDocument();
 }

 ...same interior code as before

 if( !( attrObject instanceof Document ) {
  xmlConsumer.endDocument();
 }	
}

Of course, also need to add:

 import org.w3c.dom.Document;

Can one of the developers make this change for 2.1.3 and thus kill this
bug once and for all?

Thanks guys!

....Andrzej

Mime
View raw message