SDSU Emerging Technology
Fall Semester, 2004
Cocoon Forms
Previous     Lecture Notes Index     Next     
© 2004, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 23-Sep-04

CS 683 Emerging Technologies Fall Semester, 2004 Doc 13 Cocoon Form

Contents

Contents

References

Cocoon Forms

Simple Example

formExample/sitemap.xmap

formExample/resources/form.html

formExample/content/age.xsp

formExample/style/main.xsl

Copyright ©, All rights reserved. 2004 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent ( http://www.opencontent.org/opl.shtml) license defines the copyright on this document.

References

Cocoon Developer’s Handbook, Moczar & Aston, Sams Publishing, 2003

Cocoon Forms

Simple Example

Files

In CATALINA_HOME/webapps/cocoon/

formExample/content/age.xspformExample/resources/form.htmlformExample/style/main.xslformExample/sitemap.xmap

http://bismarck.sdsu.edu:9006/cocoon/age/index.html

formExample/sitemap.xmap

<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
   <map:components>
      <map:generators default="file" />
      <map:transformers default="xslt" />
      <map:readers default="resources" />
      <map:serializers default="html" />
      <map:selectors default="browser" />
      <map:matchers default="wildcard" />
   </map:components>
   <map:pipelines>
      <map:pipeline>
         <map:match pattern="index.html">
            <map:read type="resource" 
                  src="resources/form.html" mime-type="text/html">
            </map:read>
         </map:match>
         <map:match pattern="processAge.html">
            <map:generate type="serverpages" src="content/age.xsp" />
            <map:transform type="xslt" src="style/main.xsl" />
            <map:serialize type="html" />
         </map:match>
      </map:pipeline>
   </map:pipelines>
</map:sitemap>

formExample/resources/form.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
      <meta http-equiv="content-type" content="text/html; 
         charset=iso-8859-1" />
      <title>
         Form Example
      </title>
   </head>
   <body>
      <h1>
         Form Example
      </h1>
      <form action="processAge.html" method="get">
      <label for="age">
         Enter your age: 
      </label>
      <input type="text" id="age" name="age" value="10" 
            size="40" />
      <input type="submit" />
   </form>
</body>
</html>

formExample/content/age.xsp

<?xml version="1.0"?>
   
<xsp:page language="java" 
   xmlns:xsp="http://apache.org/xsp"
   xmlns:xsp-request="http://apache.org/xsp/request/2.0" >
   
<page>
   <xsp:logic>
      String ageString = <xsp-request:get-parameter name="age" />;
   </xsp:logic>
   <title>Age Results</title>
   <content>
      <paragraph>You entered: <xsp:expr>ageString</xsp:expr>
      </paragraph>
   </content>
</page>
</xsp:page>

formExample/style/main.xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   
   <xsl:template match="page">
      <html>
         <head>
            <title>
               <xsl:value-of select="title"/>
            </title>
         </head>
         <body>
            <xsl:apply-templates/>
         </body>
      </html>
   </xsl:template>
   
   <xsl:template match="title">
      <h2>
         <xsl:apply-templates/>
      </h2>
   </xsl:template>
   
   <xsl:template match="paragraph">
      <p>
         <xsl:apply-templates/>
      </p>
   </xsl:template>
</xsl:stylesheet>

Previous     visitors since 23-Sep-04     Next