Web 2.0 with Cocoon 2.2ApacheCon EU 2007
What isWeb 2.0?
http://en.wikipedia.org/wiki/Image:Web20buzz.png
What isCocoon?
On Pipelines...
• Task: find the total number of unique hosts visiting the home page of your website
On Pipelines...
Windows solution:#include <stdlib.h>...
On Pipelines...
Windows solution:#include <stdlib.h>...
Unix solution:grep index.html access.log | awk ‘{print $2 }’ | sort | uniq | wc -l
On Pipelines...
Pipelines: specialised components glued together
Web 2.0 since 2001tm
Cocoon 2.2..?
maven 2
Cocoon 2.2 Web 2.0
A Web 2.0 application
• Use of other resources via REST
• Cocoon as a web service
• Rich client interface
Building aCocoon 2.2application
Cocoon archetypes
archetype |ˈärk(i)ˌtīp| |ˌɑrk(ə)ˈtaɪp| |ˌɑːkɪtʌɪp|nouna very typical example of a certain person or thing : the book is a perfect archetype of the genre. See note at model .
mvn archetype:create-DarchetypeGroupId=org.apache.cocoon-DarchetypeArtifactId=cocoon-22-archetype-block-DarchetypeVersion=1.0.0-RC1-SNAPSHOT-DgroupId=com.mycompany-DartifactId=myBlock1
archetype video
mvn cocoon:rcl
cocoon:rcl video
mvn jetty:run
jetty:run video
REST
The REST example
• Use Flickr API to display content through Cocoon
• http://www.flickr.com/services/api/request.rest.html
• http://www.flickr.com/services/rest/?method=flickr.method.name&name=value
<map:match pattern="flickr"> <map:generate src="......"/><map:serialize type="xml"/>
</map:match>
<map:match pattern="flickr"> <map:generate src="......"/><map:serialize type="xml"/>
</map:match>
http://www.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=1234&user_id=abcd
Taking it further ...
<map:match pattern="flickr"> <map:generate src="......"/> <map:transform src="flickr2html.xsl"/><map:serialize type="html"/>
</map:match>
<xsl:template match="/"> <html> <head> <link rel="stylesheet" href="styles/site.css" type="text/css" /> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="rsp"><xsl:apply-templates/></xsl:template> <xsl:template match="photos"> <h1><xsl:value-of select="@total"/> photos</h1> <table> <xsl:apply-templates/> </table> </xsl:template>
<xsl:template match="photo"> <tr> <td><img src="http://farm{@farm}.static.flickr.com/{@server}/{@id}_{@secret}_s.jpg"/></td> <td><xsl:value-of select="@title"/></td> </tr> </xsl:template>
http://www.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=1234&photo_id=5678
Adding location...
Pipelines...
Unix solution:grep index.html access.log | awk ‘{print $2 }’ | sort | uniq | wc -l
Pipelines: specialised components glued together
<xsl:template match="photo"> <xsl:copy><!--copy node being visited--> <xsl:copy-of select="@*"/><!--copy of all attributes--> <ci:include src="http://www.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=1234&photo_id={@id}" select="rsp/photo/location" parse="xml"/> </xsl:copy> </xsl:template>
<map:match pattern="flickr"> <map:generate src="......"/> <map:transform src="getLocation.xsl"/> <map:transform type="cinclude"/> <map:transform src="flickr2html.xsl"/><map:serialize type="html"/>
</map:match>
And presenting it... <xsl:template match="photo"> <tr> <td><img src="http://farm{@farm}.static.flickr.com/{@server}/{@id}_{@secret}_s.jpg"/></td> <td><xsl:value-of select="@title"/></td> <xsl:if test="location"> <td> <xsl:apply-templates select="location"/> </td> </xsl:if> </tr> </xsl:template>
<xsl:template match="location"> <xsl:value-of select="locality"/><br/><xsl:value-of select="country"/> </xsl:template>
Building pipelines<map:match pattern="flickr"> <map:generate src="......"/> <map:transform src="getLocation.xsl"/> <map:transform type="cinclude"/> <map:transform src="yahoomaps.xsl"/> <map:transform type="cinclude"/> <map:transform src="flickr2html.xsl"/><map:serialize type="html"/>
</map:match>
http://cocoon.zones.apache.org/demos/release/samples/aggregation/
TMTOWTDI/tim toh' dee/, abbrev.
Web Services
What flavour?
• SOAP, WS-*, ...
• http://cocoon.zones.apache.org/demos/release/samples/blocks/axis/status.xsp
• http://ws.apache.org/
The SOAP example
<map:match pattern="news"> <map:generate src="......"/><map:transform src="photosearch.xsl"/><map:transform type="cinclude"/><map:transform src="photoinsert.xsl"/><map:serialize type="xml"/>
</map:match>
RSS serving example
News/Flickr Mashup
The Rich GUI
Rich GUIs in Cocoon
• Power of CForms’ widget-based framework
• DOJO
The GUI example
pom.xml<dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-forms-impl</artifactId> <version>1.0.0-RC1-SNAPSHOT</version></dependency>
<dependency> <groupId>org.apache.cocoon</groupId> <artifactId>cocoon-ajax-impl</artifactId> <version>1.0.0-RC1-SNAPSHOT</version></dependency>
But there’s more...
• Authentication
• Blogs
• Microformats
• Semantic
Thank you
Latest version
• http://people.apache.org/~asavory/