Configuration
Previous  Top  Next

If you come this far then you will find the rest relatively easy. Cocoon uses a file called sitemap.xmap as its main configuration file. It is there where we tell Cocoon what files to display, map, transform etc. To keep it simple we will simply use an XML document with an associated XSL file to produce a HTML file. Create a test folder in the ..../cocoon folder called test and add the following lines at the bottom of the file before

  </map:pipeline>
 </map:pipelines>

</map:sitemap>

so that it looks like this:

   <!—- serve all .gif graphic files from the vincent dir -->
   <map:match pattern="**.gif">
    <map:read src="vincent/{1}.gif" mime-type="image/gif"/>
   </map:match>

   <!—- serve all .jpg graphic files from the vincent dir -->
   <map:match pattern="**.jpg">
    <map:read src="vincent/{1}.jpg" mime-type="image/jpg"/>
   </map:match>

   <!—- serve all .png graphic files from the vincent dir -->
   <map:match pattern="**.png">
    <map:read src="vincent/{1}.png" mime-type="image/png"/>
   </map:match>

   <!-- directory listing of root (/) -->
   <!—- this is only important if you want to browse the root dir -->
   <map:match pattern="">
    <map:generate type="directory" src="vincent"/>
    <map:transform src="stylesheets/system/directory2html.xsl"/>
    <map:serialize/>
   </map:match>

   <!-- show source of xml files rather than converting them -->
   <map:match pattern="source/*.xml">
    <map:read src="vincent/{1}.xml" mime-type="text/plain"/>
   </map:match>

   <!-- convert .xml files with a .xsl file to a html file -->
   <map:match pattern="**.xml">
    <map:generate type="file" src="vincent/{1}.xml"/>
    <map:transform type="xslt" src="hogwarts.xsl"/>
    <map:serialize/>
   </map:match>

  </map:pipeline>
 </map:pipelines>

</map:sitemap>

Here we tell Cocoon

·how to serve graphics files  
·how to show a directory listing  
·how to convert xml files with a stylesheet file  
 
You will need to restart Cocoon (Tomcat) and copy the test files into that folder to make this work. Then simply navigate to http://localhost:8180/cocoon/test/
and you should be able to click on any .xml and have it transformed into HTML format (while keeping its extension).