cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: Runtime error when custom transformer followed by XSL transform
Date Sat, 12 Jun 2004 10:57:10 GMT
On 11.06.2004 21:20, Jeff Potts wrote:

> I am a new Cocoon developer and new to SAX. I have
> developed my first custom Transformer. The transformer
> works great when it is followed by an XML Serializer
> but it gets a runtime error when it is followed by an
> XSL Transformer.
> 
> My transformer queries a back-end system which returns
> XML. I want to simply replace the original query in my
> XML with the resulting XML from the back-end system
> (like the SQL Transformer does).
> 
> I think my problem is with the parser.parse call.

No, I don't think so, this makes it only obvious. Read below for my 
thinking.

> When
> I just spit the XML into the output with characters()
> I get the XML but with entities instead of angle
> brackets and no runtime error.

You don't push XML then, but only a string. That's definitely not the 
way to go.

> When I use the
> parser.parse call I get the runtime error.

You must have in mind that you are in an XML pipeline. When you call 
this method for each SAX event a method is called on this.xmlconsumer, 
which calls a method on its xmlconsumer, which calls a method on its 
xmlconsumer, which ... until the last xmlconsumer, the serializer, is 
reached. So it's probably not parser.parse itself where the error 
occurs, but "somewhere" in the pipeline.

> I've saved a local copy of the XML from the back-end
> and have successfully transformed it with the same
> stylesheet, so the stylesheet is okay.
> 
> Any help is appreciated. Environment info,
> LogTransformer output, full RuntimeException, and
> Transformer code snipped are attached below.

Very good preparation for a help request ;-)
Read on ...

> LogTransformer output============================
> 
> [setup] ---------------------------- [Fri Jun 11
> 13:50:46 CDT 2004] ----------------------------
> [setDocumentLocator]
> systemid=file:/C:/apache/build/tomcat-4.1/webapps/cocoon/ddash/resources/sampledqlquery.xml,publicid=
> [startDocument] 

startDocument no. 1

> [startElement] uri=,local=testquery,raw=testquery
> [characters] 
> 	
> [startPrefixMapping]
> prefix=xdql,uri=http://com.navigatorsystems.cocoon.dctm.xdql
> [characters] 
> 		
> [characters] 
> 		
> [characters] 
> 	
> [startElement]
> uri=http://com.somehost.cocoon.dctm.xdql,local=execute-query,raw=execute-query
> [setDocumentLocator] systemid=null,publicid=null
> [startDocument] 

startDocument no. 2

> [startElement] uri=,local=root,raw=root
> [characters] 
>     
> [startElement] uri=,local=object,raw=object
> [            ] 1.
> uri=,local=ID,qname=ID,type=CDATA,value=09011f0880003245
> [characters] 
>         
> [startElement] uri=,local=r_object_id,raw=r_object_id
> [characters] 09011f0880003245
> [endElement] uri=,local=r_object_id,raw=r_object_id
> [characters] 
>         
> [startElement] uri=,local=object_name,raw=object_name
> [characters] sub-food.gif
> [endElement] uri=,local=object_name,raw=object_name
> [characters] 
>     
> [endElement] uri=,local=object,raw=object
> [characters] 
>     
> [startElement] uri=,local=object,raw=object
> [            ] 1.
> uri=,local=ID,qname=ID,type=CDATA,value=09011f0880003370
> [characters] 
>         
> [startElement] uri=,local=r_object_id,raw=r_object_id
> [characters] 09011f0880003370
> [endElement] uri=,local=r_object_id,raw=r_object_id
> [characters] 
>         
> [startElement] uri=,local=object_name,raw=object_name
> [characters] sub-food.gif
> [endElement] uri=,local=object_name,raw=object_name
> [characters] 
>     
> [endElement] uri=,local=object,raw=object
> [characters] 
> 
> [endElement] uri=,local=root,raw=root
> [endDocument] 

endDocument no. 1

> [endElement]
> uri=http://com.somehost.cocoon.dctm.xdql,local=execute-query,raw=execute-query
> [endPrefixMapping] prefix=xdql
> [characters] 
> 
> [endElement] uri=,local=testquery,raw=testquery
> [endDocument]

endDocument no. 2

Two problems I see:
1. duplicate startDocument end endDocument events
2. wrong prefix mapping

I guess problem 1 is causing the exception. And I also guess the output 
from setDocumentLocator immediately before startDocument no. 2 til 
endDocument no. 1 is the output of parser.parse, isn't it? You probably 
have to add another XML consumer into the pipeline that filters out the 
*Document events. Therefore add a class extending AbstractXMLPipe and 
overwriting startDocument and endDocument with empty body. Your code 
would then look like:

super.startElement(... params ...);
MyPipe pipe = new MyPipe(this.xmlconsumer);
parser.parse(source, pipe);
super.endElement(... params ...);


class MyPipe extends AbstractXMLPipe {

   MyPipe(XMLConsumer consumer) {
     this.setConsumer(consumer);
   }
   startDocument() {}
   endDocument() {}
}

(Of course with the correct parameters and access modifiers.)

To problem 2: You mapped xdql to 
http://com.navigatorsystems.cocoon.dctm.xdql, but the element has 
uri=http://com.somehost.cocoon.dctm.xdql,local=execute-query,raw=execute-query. 
This means you have the appropriate to 
xmlns:xdql="http://com.navigatorsystems.cocoon.dctm.xdql" in your pipe, 
but the element looks like <execute-query 
xmlns="http://com.somehost.cocoon.dctm.xdql">. Besides that these are 
different uris the element should also be prefixed with xdql or the 
prefix mapping should be changed: mapping "" to 
uri=http://com.somehost.cocoon.dctm.xdql.

Hope this helps,

Joerg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message