You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Andrzej Jan Taramina <an...@chaeron.com> on 2003/10/07 16:41:47 UTC

Bug in SessionAttributeGenerator?

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 Jan Taramina
Chaeron Corporation: Enterprise System Solutions
http://www.chaeron.com


pseudo-protocol

Posted by marcos nieto <co...@yahoo.es>.
Hi all,
 
Is it possible use pseudo- protocol in a xml file? because I've this file
 
...
 
 <coplet>
        <ci:includexml>
          <ci:src>cocoon://menuarbre-coplet</ci:src>
          <ci:parameters>
            <ci:parameter>
              <ci:name>esport</ci:name>
              <ci:value>5001</ci:value>
            </ci:parameter>
          </ci:parameters>
        </ci:includexml>
      </coplet>
....
 
And it doesn´t work "cocoon:// "  but  "cocoon:/" it's work ...
 
I use cocoon 2.1.1
 
thanks a lot. bye



---------------------------------
Yahoo! Messenger
Nueva versi&oacute;n: Super Webcam, voz, caritas animadas, y m&aacute;s #161;Gratis!

Re: Bug in SessionAttributeGenerator?

Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2003-10-07 at 16:41, Andrzej Jan Taramina wrote:
> 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:
<snip/>

I just committed a fix, could you try it out and confirm that it works?
Thanks.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org