Hi Cocooners,
I think I may have found and fixed a problem, but I need some confirmation that I haven't actually broken anything ;)


I was recently playing with the idea of having the form definition for a JXForm display templateable using JXTemplate. Thus I constructed my pipeline so:

<map:pipeline internal-only="true">
      <!-- Template the form definition -->
     <map:match pattern="jxt-*-*">
       <map:generate src="system/{1}/{2}/jxform.xml" type="jx"/>
       <map:serialize type="xml"/>
     </map:match>

<!-- Generate the JXForm view of the JXTemplated JXForm, this is invoked from the flowscript-->
<map:match pattern="jxfv-*-*">
<map:generate src="cocoon:/ejxt-{1}-{2}" type="jxforms"/>
<map:transform src="system/ejbforms/jxforms-default.xsl"/>
<map:transform src="system/ejbforms/jxform2html.xsl"/>
<map:serialize type="xhtml"/>
</map:match>
</map:pipeline>


But I found that for some reason the output was no longer working, even if the form definition had no JXTemplate evaluations. I thought this was weird, so I accessed the jxt-*-* pipeline directly (which generates with JXTemplateGenerator) and compared that output after I changed it to the generate with FileGenerator. Interestingly, the file output was identical, yet the jxfv-*-* pipeline began to work when I used FileGenerator. Being curious I put LogTransformer after the generator and notice that JXTemplateGenerator seems to trigger the setDocumentLocator event before every single event!

As I Looked a little deeper into the code for JXTemplateGenerator I found at the start of execute() that setDocumentLocator was being called for every iteration of the event loop:

   private void execute(final XMLConsumer consumer,
                        MyJexlContext jexlContext,
                        JXPathContext jxpathContext,
                        Event startEvent, Event endEvent)
       throws SAXException {
       Event ev = startEvent;
       while (ev != endEvent) {
           consumer.setDocumentLocator(ev.location);
           if (ev instanceof Characters) {
               /* ... snip ... */
           }
           ev = ev.next;
       }
    }

So I moved the consumer.setDocumentLocator() line outside the event loop, and now it all works. Is this correct? From what I understand from the documentation, the generator can include other template files and I was not sure if setDocumentLocator() would still need to be called to indicate the location of the included file??

Many thanks in advance for any advice,
Sam




Reply via email to