Apache » Cocoon »

  Cocoon Core

Cocoon Core 2.2



Generates an XML source hierarchy listing from a Traversable Source.

Basic information

Component typeGenerator
Cocoon blockcore
Java classorg.apache.cocoon.generation.TraversableGenerator
Name in Sitemap
CacheableYes - Yes


The root node of the generated document will normally be a collection node and a collection node can contain zero or more resource or collection nodes. A resource node has no children. Each node will contain the following attributes:

  • name the name of the source
  • lastModified the time the source was last modified, measured as the number of milliseconds since the epoch (as in java.io.File.lastModified)
  • size the source size, in bytes (as in java.io.File.length)
  • date (optional) the time the source was last modified in human-readable form
Note: The TraversableGenerator can browse block defined in the Servlet Service Framework in addition to the resources in the current block.

Configuration options:

  • depth (optional) Sets how deep TraversableGenerator should delve into the source hierarchy. If set to 1 (the default), only the starting collection's immediate contents will be returned.
  • sort (optional) Sort order in which the nodes are returned. Possible values are name, size, time, collection. collection is the same as name, except that the collection entries are listed first. System order is default. 
  • reverse (optional) Reverse the order of the sort 
  • dateFormat (optional) Sets the format for the date attribute of each node, as described in java.text.SimpleDateFormat. If unset, the default format for the current locale will be used.
  •  timeZone (optional) Sets the time zone offset ID for the date attribute, as described in java.util.TimeZone. If unset, the default system time zone will be used. 
  • refreshDelay (optional) Sets the delay (in seconds) between checks on the source hierarchy for changed content. Defaults to 1 second.
  • root (optional) Sets the the regular expression for the root pattern. 
  • include (optional) Sets the the regular expression for including sources based on their names.
  • exclude (optional) Sets the the regular expression for excluding sources based on their names.


      <map:match pattern="pages.xml">
        <map:generate type="traversable" src="blockcontext:/">
          <map:parameter name="depth" value="4"/>
          <map:parameter name="include" value="wsmain$|resource$|basepage$|\.(.+)"/> 
          <map:parameter name="exclude" value="xsl$|xmap$"/>
        <map:serialize type="xml"/>
The sitemap fragment above will browse every block defined in the current block via the Servlet Service Framework (look at the "blockcontext:/" src attribute) and will include every resources fitting the"wsmain/resource/basepage/*.*" pattern (well,  its permutations too, like "resource/wsmain/resource/basepage/*.*) excluding those ending with "xsl" and "xmap".While the exclude could be referred to name of resources, the include should take into account its path as well, since the matching is done path segment by path segment. In other words, every single segment of the path leading to the resources to be included has to be matched.