Cocoon as Alphabet Soup

Author:
Warrell Harries
For:
Wiley Interscience
Date:
May 2007

A Rich bowl of Cocoon Morsels from A-Z

1. AJAX, Authentication and Aggregation

a.jpg

CForm Definition to use AJAX

<fd:field id="environment" required="true">
   <fd:label>Environment:</fd:label>
   <fd:datatype base="string"/>
   <fd:selection-list src="environment.xml"/>
   <fd:on-value-changed>
      <fd:javascript>
      var value = this.value;
      var appwidget = widget.lookupWidget("../appGroup");
      if (value != null)
      {
         // Get the corresponding type list
         appwidget.setSelectionList(value + ".xml");
         appwidget.state = Packages.org.apache.cocoon.forms.formmodel.WidgetState.ACTIVE;
      }
      else
      {
         // Set an empty selection list
         appwidget.setSelectionLis
         (
            new Packages.org.apache.cocoon.forms.datatype.EmptySelectionList("Select an Environment First")
         );
         appwidget.state = Packages.org.apache.cocoon.forms.formmodel.WidgetState.DISABLED;
      }
      // Always set the type value to null. Note that it will also fire an event on the "type"
      // widget if it already had a value.
      appwidget.value = null;
      </fd:javascript>
   </fd:on-value-changed>
   <fd:help>Please select an Environment</fd:help>
</fd:field>

Pipeline matcher to handle asynchronous browser updates

<map:match pattern="viewform-*.html">
   <map:generate type="jx" src="pages/{1}.xml"/>
   <map:transform type="browser-update"/>
   <map:transform type="i18n"/>
   <map:transform src="resources/forms-samples-styling.xsl"/>
   <map:select type="ajax-request">
      <map:when test="true">
         <map:serialize type="xml"/>
      </map:when>
      <map:otherwise>
         <map:transform src="resources/page-styling.xsl"/>
         <map:serialize type="html"/>
      </map:otherwise>
   </map:select>
</map:match>

Authentication Framework

<authentication-manager>
   <handlers>
      <handler name="ldaphandler">
         <redirect-to uri="cocoon:/login"/>
         <authentication uri="cocoon:raw:/authenticate"/>
      </handler>
   </handlers>
</authentication-manager>
<map:match pattern="updateAppointment">
   <map:act type="auth-protect">
      <map:parameter name="handler" value="ldaphandler"/>
         <map:generate src="empty.xml"/>

Deprecated in favour of CoWarp http://osoco.sourceforge.net/cowarp/

Aggregation

aggregate.jpg

Aggregation is a very powerful concept that allows a document be generated from several other documents. Strictly speaking, all parts are just concatenated in this order to a new document.

"cocoon:" is a pseudo protocol and refers to another pipeline. "cocoon:/" refers to a pipeline from the current sitemap while "cocoon://" refers to a pipeline from the root sitemap.

Other pseudo protocols exist:

"context:" is another pseudo protocol, "context://" is referring to a resource using the servlet context.

"resource:" is yet another pseudo protocol, "resource://" is referring to a resource from the context classloader.

All these pseudo protocols are declared in the cocoon.xconf.

Thus, the parts refer to the pipeline fragments above.

The optional element attribute places the content in a new root element named as specified, using the namespace provided by an optional ns attribute.

2. Blocks, Browsers and Batik

b.jpg

Blocks package functional components and encourage modularity

Current release uses build properties 2.2 adopts Maven archtypes

Use of CForms brings automatic cross-browser support

No more hand-cranked DHTML

Batik brings SVG into the application

Support dynamic graphics in static generated use-cases

3. Customise, CAPTCHA and CLI

Sometimes you just have to write your own component

c.jpg

Custom Serializers, Transformers and Generators prove invaluable for tight coupling to legacy protocols, interfaces and API's

Web Service, NNTP, EJB's, Charting, SAP

public class EJBTransform extends AbstractDOMTransformer
{
protected org.w3c.dom.Document transform(org.w3c.dom.Document document)
{
   org.w3c.dom.Document doc = null;
   try
   {
      Context ctx = new InitialContext();
      Object ejbClientHome =
         ctx.lookup("ejb/"+configuredEJBApp +
            "/com/ejb/services/clientmanager/ejb/ClientManager");
      com.ejb.services.clientmanager.ejb.ClientManagerHome clientManagerHome =
         (com.ejb.services.clientmanager.ejb.ClientManagerHome)
         javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object) ejbClientHome,
            com.ejb.services.clientmanager.ejb.ClientManagerHome.class);
      com.ejb.services.clientmanager.ejb._ClientManager_Stub clientManager =
         (com.ejb.services.clientmanager.ejb._ClientManager_Stub) clientManagerHome.create();
      String processData = convert( document );
      String updatedData = clientManager.saveClient( processData, "S" );

Completely Automated Public Turing test to tell Computers and Humans Apart

Transformer and Reader

custom.jpg

CLI Offline Generation Modem - http://forrest.apache.org/

Many Web 1.0 sites are directed graphs capable of being statically generated (finite user interaction = finite page tree)

<map:views>
   <map:view from-position="last" name="links">
      <map:serialize type="links"/>
   </map:view>
</map:views>

4. Development, Databases and Daisy

d.jpg

Avoid the Exclusion Zones that Afflict Web Development Projects

Sitemap, Pipeline and Components prevent developers treading on each others toes

Instead

They are more likely singing off the same Hymn Sheet

SQL Transformer Injects Relational Model into the pipeline DOM

SQL Query result-sets returned as XML was early way of leveraging power of XSLT into Web applications

Typical usage would use JX Generator to enrich the XML FILE WITH request parameters. The second stage of the pipeline invokes the SQL Transformer

XSLT Transformer usage below outputs <sql:> namespace elements that contain SQL queries

The parameters of these queries can be drawn from the input document, passed in from the sitemap and derived from XPath (2.0 in this case)

<xsl:template match="team">
<xsl:param name="period"/>
<sql:execute-query>
   <sql:query>select appointmentref from
      CLIENTMANAGER.APPOINTMENT a, CLIENTMANAGER.CLIENT c
      where a.clientuid=c.clientuid and  
      substr(char(appointmentdate),1,16) = '<xsl:value-of select="$period"/>'
      and a.ACTIVE=1 and c.SOURCECODE in
      ('<xsl:value-of select="sources/source" separator="','"/>')
   </sql:query>
</sql:execute-query>
</xsl:template>

Daisy is a CMS that offers rich out-of-the-box functionality combined with solid foundations for extensibility and integration.

5. eXist, EhCache and Error Handling

e.jpg

6. Flow, Forms and FOP

f.jpg

7. Generators

g.jpg

8. Hippo

h.jpg

9. Integration, Integration and i18n

i.jpg

10. Java, Javascript and JFreeChart

j.jpg

chart.jpg

11. Kontinuation

k.jpg

12. LDAP, Lucene and Linotype

l.jpg

13. Maven, Modules and Messaging

m.jpg

14. Naming (JNDI)

n.jpg

15. Objects

o.jpg

16. Portals, POI and Podcasts

Portal Infrastructure

Excel your way into the heart of the corporation

podcasting

Play

p.jpg

17. xQuery

q.jpg

18. Readers, Resources and Repositories

r.jpg

19. Serializers, Sessions and Syndication

s.jpg

20. Transformers and Tooling

t.jpg

21. Use-cases, URI's and Utility

u.jpg

22. Velocity, Validation and Verbosity

v.jpg

23. Web 2.0, Web3 and WebDAV

w.jpg

24. XSLT 2.0

x.jpg

25. YOU

y.jpg

26. Zeitgeist

z.jpg

©Cocoon Technology Ltd