Well, it _could_ have a chance to work, but flowscript is definitely not the appropriate location to compute cache information for an element of the view pipeline.
not the appropriate .. but really there is no other place ..
The problem with JXG is that the template is the generate() method _only_ whereas an XSP is the full class, allowing to define getKey() and getValidity().Fine for simple cases but limits of this solution will appear very fast.
So what about adding two optional attributes on the template's root element, defining the cache information?
<page
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
jx:cache-key='${cocoon.request.get("abc") + "!!spacer!!" + cocoon.request.get("bcd")....'
jx:cache-validity='${new DeltaTimeCacheValidity(60 * 60 * 24)}'>
... template ....
</page>
WDYT?
I just know what would users do (what I would also do if I wanted something more complex)
the .js file:
function validityForView() {
var validity = new SomeVeryHardToComputeInOneLineValidity();
return validity;
}function keyForView() {
var key = someVeryStrangeKeyFetchedFromSomewhere;
return key;
}function showSomeView() {
cocoon.session.setAttribute( "myViewValidityFunc", validityForView );
cocoon.session.setAttribute( "myViewKey", keyForView );
cocoon.sendPage( "view/myview.jx", {} );
}the template: <page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0" jx:cache-key='${cocoon.session.myViewKey()}' jx:cache-validity='${cocoon.session.myViewValidityFunc()}'> ... template .... </page>
This and other examples proove that we need a way to extend jxtemplate generator with flow functions (or other logic "providers") when simple macro is not enough. This may lead to a jsb taglib nightmare but hey: user has got his own brain not to put database inserts in there and if he is he's just asking for troubles.
I still do not understand why we do have jx:formatDate and jx:formatNumber which are just some instances of formatters while there either should be none at all or just pluggable ones. Like these:
function stringToSAX( str, consumer, ignoreRootElement ) {
var is = new Packages.org.xml.sax.InputSource( new java.io.StringReader( str )
);
var ignore = ( ignoreRootElement == "true" );
var parser = null;
var includeConsumer = new org.apache.cocoon.xml.IncludeXMLConsumer( consumer,
consumer );
includeConsumer.setIgnoreRootElement( true );
try {
parser = cocoon.getComponent(
Packages.org.apache.excalibur.xml.sax.SAXParser.ROLE );
parser.parse( is, includeConsumer );
} finally {
if ( parser != null ) cocoon.releaseComponent( parser );
}
}
function wikiToSAX( str, consumer ) { var radeoxStr = radeoxEngine.render( str, radeoxContext ); var buffer = new java.lang.StringBuffer("<root>" ); buffer.append( radeoxStr ) buffer.append( "</root>" ); var is = new Packages.org.xml.sax.InputSource( new java.io.StringReader( buffer.toString() ) );
var parser = null; var includeConsumer = new org.apache.cocoon.xml.IncludeXMLConsumer( consumer, consumer ); includeConsumer.setIgnoreRootElement( true ); try { parser = cocoon.getComponent( Packages.org.apache.excalibur.xml.sax.SAXParser.ROLE ); parser.parse( is, includeConsumer ); } finally { if ( parser != null ) cocoon.releaseComponent( parser ); } }
Now I have to do the same session trick and build a macro:
<jx:macro name="wiki-string">
<jx:parameter name="value"/>
<jx:set var="ignored" value="${cocoon.session.wikify( value, cocoon.consumer
)}"/>
</jx:macro>
I did not mean to sound unpleasant by any way. I would like to contribute something more than bug reports but I do not know cocoon's internals that much to catch all possible problems.
-- Leszek Gawron
