You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by do...@cocoon.apache.org on 2004/07/06 11:26:10 UTC

[Cocoon Wiki] Updated: JXTemplateGenerator

   Date: 2004-07-06T02:26:10
   Editor: UnicoHommes <un...@apache.org>
   Wiki: Cocoon Wiki
   Page: JXTemplateGenerator
   URL: http://wiki.apache.org/cocoon/JXTemplateGenerator

   Document new caching feature

Change Log:

------------------------------------------------------------------------------
@@ -4,10 +4,10 @@
 
 Keep in mind that there's also a JX!TemplateTransformer with the same functionality. 
 
-Current namespace:{{{
+Current namespace:{{{
 xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"}}}
 
-Sitemap Configuration (as in woody sitemap):{{{
+Sitemap Configuration (as in woody sitemap):{{{
 <map:generator name="jx" src="org.apache.cocoon.generation.JXTemplateGenerator" label="content" logger="sitemap.generator.jx"/>}}}
 
 Provides a generic page template with embedded JSTL and XPath expression substitution to access data sent by Cocoon Flowscripts, eg. web continuation.[[BR]]
@@ -21,28 +21,30 @@
  *  parameters - A map of parameters passed to the generator in the pipeline ({{{org.apache.avalon.framework.parameters.Parameters}}})
 
 When using JX!TemplateGenerator you probably want to pass data from your flow. You may pass Java Beans, DOM, JDOM, or !JavaScript objects as these are recognized by both, XPath and JSTL. Pass these objects as 'Bizdata', for example in Flowscript:
-{{{
-var greatlakes = ["Superior", "Michigan", "Huron", "Erie", "Ontario"];
-
+{{{
+var greatlakes = ["Superior", "Michigan", "Huron", "Erie", "Ontario"];
+
 sendPage(uri, {greatlakes: greatlakes}); }}}
 
+== Basic features ==
+
 === jx:choose, jx:when, jx:otherwise ===
 The choose tag performs conditional block execution by the embedded when sub tags. It renders the body of the first when tag whose test condition evaluates to true. If none of the test conditions of nested when tags evaluate to true, then the body of an otherwise  tag is evaluated, if present.
-{{{
-<jx:choose>
-    <jx:when test="Expression">
-       body
-    </jx:when>
-    <jx:otherwise>
-       body
-    </jx:otherwise>
+{{{
+<jx:choose>
+    <jx:when test="Expression">
+       body
+    </jx:when>
+    <jx:otherwise>
+       body
+    </jx:otherwise>
 </jx:choose>}}}
  
 === jx:forEach ===
 Iterate over a collection of objects.
-{{{
-<jx:forEach [var="Name"][items="Expression"][begin="Number"][end="Number"][step="Number"]>
-    body
+{{{
+<jx:forEach [var="Name"][items="Expression"][begin="Number"][end="Number"][step="Number"]>
+    body
 </jx:forEach>}}}
  *  @var   - Contains the current item
  *  @items - The list of items to iterate over
@@ -52,97 +54,156 @@
 
 === jx:formatDate ===
 The formatDate tag provides facilities to format Date values.
-{{{
-<jx:formatDate value="Expression" 
-               [dateStyle="Style"] 
-               [timeStyle="Style"] 
-               [pattern="Expression"] 
-               [type="Type"] 
-               [var="Name"]
+{{{
+<jx:formatDate value="Expression" 
+               [dateStyle="Style"] 
+               [timeStyle="Style"] 
+               [pattern="Expression"] 
+               [type="Type"] 
+               [var="Name"]
                [locale="Expression"]> }}}
 
 === jx:formatNumber ===
 The formatNumber tag is used to display numeric data, including currencies and percentages, in a locale-specific manner. The formatNumber> action determines from the locale, for example, whether to use a period or a comma for delimiting the integer and decimal portions of a number. 
-{{{
-<jx:formatNumber value="Expression" 
-                 [type="Type"] 
-                 [pattern="Expression"] 
-                 [currencyCode="Expression"] 
-                 [currencySymbol="Expression"] 
-                 [maxIntegerDigits="Expression"] 
-                 [minIntegerDigits="Expression"] 
-                 [maxFractionDigits="Expression"] 
-                 [minFractionDigits="Expression"] 
-                 [groupingUsed="Expression"] 
-                 [var="Name"] 
+{{{
+<jx:formatNumber value="Expression" 
+                 [type="Type"] 
+                 [pattern="Expression"] 
+                 [currencyCode="Expression"] 
+                 [currencySymbol="Expression"] 
+                 [maxIntegerDigits="Expression"] 
+                 [minIntegerDigits="Expression"] 
+                 [maxFractionDigits="Expression"] 
+                 [minFractionDigits="Expression"] 
+                 [groupingUsed="Expression"] 
+                 [var="Name"] 
                  [locale="Expression"]> }}}
 
 === jx:if  ===
 Conditional logic based on evaluation of an expression in @test.
-{{{
-<jx:if test="Expression">
-    body
+{{{
+<jx:if test="Expression">
+    body
 </jx:if>}}}
 
 === jx:import ===
 Import a JXTemplate, the uri will be resolved by cocoon (possible to use cocoon:/ etc.).
-{{{
+{{{
 <jx:import uri="URI" [context="Expression"]/>}}}
 This tag is '''not''' for including XML, but just for other JXTemplates.
 
 === jx:macro, jx:parameter ===
 Define a new custom tag. When calling a macro, the line will be substituted with the body of the macro.
-{{{
-<jx:macro name="customTagName" [targetNamespace="Namespace"]>
-    <jx:parameter name="paramA" [optional="Boolean"] [default="Value"]/>*
-     body
+{{{
+<jx:macro name="customTagName" [targetNamespace="Namespace"]>
+    <jx:parameter name="paramA" [optional="Boolean"] [default="Value"]/>*
+     body
 </jx:macro>}}}
 Once defined, call your macro with:
-{{{
+{{{
 <customTagName paramA="someValue"/>}}}
 
 If you pass the 'greatlakes' as in the example above, you may have a macro:
-{{{
-<jx:macro name="tablerows">
-    <jx:parameter name="list"/>
-    <jx:parameter name="color"/>
-    <jx:forEach var="item" items="${list}">
-        <tr><td bgcolor="${color}">${item}</td></tr>
-    </jx:forEach>
-</jx:macro>
-
-<table>
-    <tablerows list="${greatlakes}" color="blue"/>
-</table>
+{{{
+<jx:macro name="tablerows">
+    <jx:parameter name="list"/>
+    <jx:parameter name="color"/>
+    <jx:forEach var="item" items="${list}">
+        <tr><td bgcolor="${color}">${item}</td></tr>
+    </jx:forEach>
+</jx:macro>
+
+<table>
+    <tablerows list="${greatlakes}" color="blue"/>
+</table>
 }}}
 Your result would be:
-{{{
-<table>
-   <tr><td bgcolor="blue">Superior</td></tr>
-   <tr><td bgcolor="blue">Michigan</td></tr>
-   <tr><td bgcolor="blue">Huron</td></tr>
-   <tr><td bgcolor="blue">Erie</td></tr>
-   <tr><td bgcolor="blue">Ontario</td></tr>
+{{{
+<table>
+   <tr><td bgcolor="blue">Superior</td></tr>
+   <tr><td bgcolor="blue">Michigan</td></tr>
+   <tr><td bgcolor="blue">Huron</td></tr>
+   <tr><td bgcolor="blue">Erie</td></tr>
+   <tr><td bgcolor="blue">Ontario</td></tr>
 </table>}}}
 
 === jx:out ===
 Evaluates an expression and outputs the result of the evaluation:
-{{{
+{{{
 <jx:out value="Expression"/>}}}
 
 === jx:set ===
 Define/set a variable
-{{{
-<jx:set var="Name" value="Value"/>
-or
-<jx:set var="Name">
-    [Value=body]
+{{{
+<jx:set var="Name" value="Value"/>
+or
+<jx:set var="Name">
+    [Value=body]
 </jx:set>}}}
 
 === jx:template ===
 Defines a new JXTemplate
-{{{
-<jx:template>
-    jx-elements
-</jx:template>
+{{{
+<jx:template>
+    jx-elements
+</jx:template>
+}}}
+
+== Advanced ==
+
+This section describes some advanced options.
+
+=== Caching ===
+It is possible for cocoon to cache output of this generator. In order to do so you need to provide two pieces of information: the key under which to register the cached response object in the cache and an object that describes the validity of the cached contents. 
+
+'''''Note: This feature is experimental and only available in the cocoon 2.2.0-dev branch in CVS'''''
+==== jx:cache-key ====
+Specify the cache key using jx:cache-key attribute.
+{{{
+<element jx:cache-key="Expression"/>
+}}}
+
+==== jx:cache-validity ====
+Specify the cache validity using jx:cache-validity attribute.
+{{{
+<element jx:cache-key="Expression"/>
+}}}
+
+==== Example ====
+* template.xml:
+{{{
+<?xml version="1.0"?>
+<page jx:cache-key="${cacheKey}" jx:cache-validity="${cacheValidity}"
+      xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"/>
+}}}
+
+* flow.js:
+{{{
+importPackage(Packages.org.apache.excalibur.source.impl.validity);
+
+function foo() {
+  sendPage("bar", {cacheKey: "theKey", cacheValidity: new ExpiresValidity(1000)})
+}
+}}}
+
+* sitemap.xmap:
+{{{
+<?xml version="1.0"?>
+<map:sitemap>
+
+...
+
+  <map:pipeline type="caching">
+
+    <map:match pattern="foo">
+      <map:call function="foo"/>
+    </map:match>
+
+    <map:match pattern="bar">
+      <map:generate type="jx" src="template.xml"/>
+      <map:serialize type="xml"/>
+    </map:match>
+
+  </map:pipeline>
+</map:sitemap>
 }}}