cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <lgaw...@mobilebox.pl>
Subject Re: [jxtg] imports and namespaces
Date Tue, 12 Apr 2005 09:44:44 GMT
Leszek Gawron wrote:
> It seems there is a bug that affects jxtg scripts that use jx:import
sh** I thought I cancelled that. Should go to drafts.

Never mind. You can reproduce the bug like this:

> <?xml version="1.0" encoding="UTF-8"?>
> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
>   <map:views>
>     <map:view from-label="content" name="content">
>       <map:serialize type="html"/>
>     </map:view>
>     <map:view from-label="content" name="pretty">
>       <map:transform src="../stylesheets/system/xml2html.xslt"/>
>       <map:serialize type="html"/>
>     </map:view>
>   </map:views>
>  <map:pipelines>
>   <map:pipeline>
>     <map:match pattern="bugtest">
>       <map:generate src="test.jx" type="jx" label="content"/>
>       <map:serialize type="xml"/>
>     </map:match>
>   </map:pipeline>
>  </map:pipelines>
> </map:sitemap>

> <?xml version="1.0" encoding="UTF-8"?>
> <page xmlns:i18n="http://apache.org/cocoon/i18n/2.1" xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
>     <jx:import uri="resource://org/apache/cocoon/forms/generation/jx-macros.xml"/>

>     <head>
>         <title>cocoon</title>
>     </head>
> </page>

now issuing http://localhost:8080/jxtest/bugtest?cocoon-view=pretty you get:
> <page xmlns:i18n="http://apache.org/cocoon/i18n/2.1" xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
>   <head xmlns:%@$#^@#="%@$#^@#">
>    <title>cocoon</title>
>   </head>
> </page>

I think I know what the problem is but have no idea how to fix it:

1. jx:import "inserts" all tags from imported source instead of the tag 
itself

2. jx:template does nothing at all. This tag does not produce any 
content. It was introduced as a root tag for jx files with macro 
definitions so importing a macro definition file does not produce any 
output at all.

3. The content of jx-macros.xml is:
<jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
              xmlns:fi="http://apache.org/cocoon/forms/1.0#instance">
  <jx:macro name="blah"/>
</jx:template>

4. The chain of SAX events for these scripts will be (whitespace filtered)

startPrefixMapping( i18n )
startPrefixMapping( jx )
startElement( page )

#jx-macros sax events
startPrefixMapping( jx )
startPrefixMapping( fi )

#no element to bind these namespaces to!!!

endPrefixMapping( fi )
endPrefixMapping( jx )
#eof jx-macros sax events

startElement( head )
startElement( title )

.. and so on

I am pretty sure that this problem is caused by the fact that there is 
no element to bind new namespaces to because:

a) if you put ANY element into jx-macros.xml file the namespaces are 
bound to that element and the final output is OK
b) if you define the "fi" namespace at main template level there is also 
no problem at all.


I do not know XML specs well. Would it fix (break :)) things if we 
delayed endPrefixMapping till the end of main script?

PS. official thanks to oceatoon for nailing down the use case that 
broke. I had this once but for a quite complicated template and was not 
able to reproduce it under simpler conditions

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Mime
View raw message