I think you can use a combination of session attributes and jx macros to get the effect you want, e.g.

// Flow script

function toSAX(str, consumer) {
  ...
}

cocoon.session.setAttribute("stringToSAX", toSAX);

function myPage() {
   ...
   sendPage("page.html", {...});
}

// template

<jx:macro name="output-xml">
<jx:parameter name="value">
<jx:set var="ignored" value="${cocoon.session.stringToSAX(value, cocoon.consumer)}">
</jx:macro>


Since both Flow script (cocoon.load()) and JXTemplateGenerator (<jx:import/>) support including other files you can factor such code into supporting "library" files and include them in your application code.

Chris


Leszek Gawron wrote:


I have a lot of flowscript top level variables (application context, currently
logged in user context, application statistics). I would like to provide them
to ALL application views. Right now sendPage implements a PUSH politics (I
have to specify explicitly what I would like to make available to the view).
Including top level variables manually in every sendPage is messy and error
prone.

Is there any way to implement something like AOP for variables? I mean every
bizData gets appended a set of common variables? This would make flow closer
to a PULL model Controller exposes everything it got - in the boundaries of
sanity of course - the view gets only what it wants. Exposing everything might
not be a good idea but some controlled set might help a lot.

moreover one would like to provide JXTemplateGenerator with additional
functionality as in
http://marc.theaimsgroup.com/?t=108212968300007&r=1&w=2&n=6
jx template generator has a number and date formatter but if application
defines additional features in flowscript the easiest way would be to add it
to every bizData.

<Chris-code>
I guess you could even avoid the sax buffer and stream it directly in the template:


// flowscript fragment
var message = ...;
sendPage("page.html", {message: message, streamer: {toSAX: toSAX}});


// jx template fragment
<jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>
...
<jx:set var="ignored" value="${streamer.toSAX(message.content, cocoon.consumer}}"/>
...
</jx/template>
</Chris-code>
WDYT?
lg





Reply via email to