Continuing my conversation with myself....

I updated the Woody block and noticed there are quite a few new things there. In order to implement the <wt:class> and <wt:new> tags I extended JXTemplateGenerator to support dynamic evaluation of custom tags. I just checked in this update. See the documentation. The attached file contains implementations of all of the <wt:xxx> tags including class, new, union, case and struct.

Regards,

Chris

Christopher Oliver wrote:

The attached fixes a couple of bugs and adds the wt:continuation-id tag. I've tested it with all the forms/{1}_template.xml examples in the woody samples.

Regards,
Chris

Christopher Oliver wrote:

Attached is a first attempt to implement the behavior of the Woody template transformer with the macro facility of the JXTemplateGenerator.


<snip>

------------------------------------------------------------------------


<snip>



<jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>

<jx:set var="woodyStack" value="${java.util.Stack()}"/>
<jx:set var="woodyClasses" value="${java.util.HashMap()}"/>

<jx:macro name="form-template" 
targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="action"/>
  <jx:parameter name="method"/>
  <wi:form-template xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"; 
action="${action}" method="${method}">
     <jx:set var="ignored" value="${woodyStack.push(this['woody-form'])}"/>
     <jx:evalBody/>
     <jx:set var="ignored" value="${woodyStack.pop()}"/>
  </wi:form-template>
</jx:macro>

<jx:macro name="widget" targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:set var="contextWidget" value="${woodyStack.peek()}"/>
  <jx:set var="widget" value="${contextWidget.getWidget(id)}"/>
  <jx:choose>
    <jx:when test="${widget.getSize() != null}"> <!-- repeater -->
       <jx:set var="lastRow" value="${widget.getSize() - 1}"/>
       <jx:forEach varStatus="loop" begin="0" end="${lastRow}">
           <jx:set var="row" value="${widget.getRow(loop.index)}"/>
           <jx:set var="ignored" value="${woodyStack.push(row)}"/>
           ${row.generateSaxFragment(cocoon.consumer, locale)}
           <jx:evalBody/>
           <jx:set var="ignored" value="${woodyStack.pop()}"/>
       </jx:forEach>
     </jx:when>
     <jx:otherwise>
       ${widget.generateSaxFragment(cocoon.consumer, locale)}
       <jx:evalBody/>
     </jx:otherwise>
  </jx:choose>
</jx:macro>

<jx:macro name="repeater-widget-label" 
targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:parameter name="widget-id"/>
  <jx:set var="contextWidget" value="${woodyStack.peek()}"/>
  <jx:set var="repeater" value="${contextWidget.getWidget(id)}"/>
  ${repeater.generateWidgetLabel(this['widget-id'], cocoon.consumer)}

</jx:macro>

<jx:macro name="widget-label" 
targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:set var="contextWidget" value="${woodyStack.peek()}"/>
  <jx:set var="widget" value="${contextWidget.getWidget(id)}"/>
  ${widget.generateLabel(cocoon.consumer)}

</jx:macro>

<jx:macro name="repeater-size" 
targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:set var="contextWidget" value="${woodyStack.peek()}"/>
  <jx:set var="widget" value="${contextWidget.getWidget(id)}"/>
  ${widget.generateSize(cocoon.consumer)}

</jx:macro>

<jx:macro name="repeater-widget" 
targetNamespace="http://apache.org/cocoon/woody/template/1.0"; 
xmlns:wt="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>

  <jx:set var="contextWidget" value="${woodyStack.peek()}"/>
  <jx:set var="widget" value="${contextWidget.getWidget(id)}"/>
  <jx:set var="lastRow" value="${widget.getSize() - 1}"/>
  <jx:forEach varStatus="loop" begin="0" end="${lastRow}">
      <jx:set var="row" value="${widget.getRow(loop.index)}"/> 
      <jx:set var="ignored" value="${woodyStack.push(row)}"/>
      <jx:evalBody/>
      <jx:set var="ignored" value="${woodyStack.pop()}"/>
  </jx:forEach>
</jx:macro>

<jx:macro name="continuation-id" 
targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <wi:continuation-id 
xmlns:wi="http://apache.org/cocoon/woody/instance/1.0";>${cocoon.continuation.id}</wi:continuation-id>
</jx:macro>

<jx:macro name="class" targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:set var="ignored" value="${woodyClasses.put(id, macro.body)}"/>
</jx:macro>

<jx:macro name="new" targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:eval select="${woodyClasses.get(id)}"/>
</jx:macro>

<jx:macro name="struct" targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:set var="contextWidget" value="${woodyStack.peek()}"/>
  <jx:set var="widget" value="${contextWidget.getWidget(id)}"/>
  <jx:set var="ignored" value="${woodyStack.push(widget)}"/>
  <wi:struct xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"; id="${id}">
  <jx:evalBody/>
  </wi:struct>
  <jx:set var="ignored" value="${woodyStack.pop()}"/>
</jx:macro>

<jx:macro name="union" targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:set var="contextWidget" value="${woodyStack.peek()}"/>
  <jx:set var="widget" value="${contextWidget.getWidget(id)}"/>
  <jx:set var="ignored" value="${woodyStack.push(widget)}"/>
  <wi:union xmlns:wi="http://apache.org/cocoon/woody/instance/1.0"; id="${id}">
  <jx:evalBody/>
  </wi:union>
  <jx:set var="ignored" value="${woodyStack.pop()}"/>
</jx:macro>

<jx:macro name="case" targetNamespace="http://apache.org/cocoon/woody/template/1.0";>
  <jx:parameter name="id"/>
  <jx:set var="contextWidget" value="${woodyStack.peek()}"/>
  <jx:if test="${contextWidget.getValue() == id}">
    <jx:evalBody/>
  </jx:if>
</jx:macro>

</jx:template>

Reply via email to