While working with Cocoon, I have come upon some useful patterns for use in the sitemap. Feel free to change/tweak these as needed. – TonyCollen
- Most basic usage of sitemap components
- Usually generating from static XML files
- Good candidate for pre-generation using CLI
No Format |
---|
<map:match pattern="*.html">
<map:generate src="documents/{1}.xml"/>
<map:transform src="stylesheets/docbook2html.xsl"/>
<map:serialize type="xhtml"/>
</map:match>
|
- Useful for automated M/G/T/S
- Allows people to create subdirectories and Cocoon will automatically serve them
- Will match foo/blah.html, foo/bar/blah.html, foo/bar/baz/blah.html, etc.
- Centralized XSLT for unified document structure
No Format |
---|
<map:match pattern="**/*.html">
<map:generate src="documents/{1}/{2}.xml"/>
<map:transform src="stylesheets/docbook2site.xsl"/>
<map:serialize type="html"/>
</map:match>
|
Redirect "empty" requests to a known URI
- Similar to
DirectoryIndex
directive in httpd.conf
No Format |
---|
<map:match pattern="">
<map:redirect-to uri="welcome"/>
</map:match>
|
Sub-Sitemap Automounting
Wiki Markup |
---|
Used in default {{\[Sitemap\]}} |
- Minimizes maintenance of parent sitemaps
- Extremely useful
No Format |
---|
<map:match pattern="*/**">
<map:mount check-reload="yes" src="{1}/" uri-prefix="{1}"/>
</map:match>
|
- dynamic selection of the sitemap to process a URL
- allows specific handling of a certain URL by subsites or site sections
No Format |
---|
<map:match pattern="*/**-info.html">
<map:act type="resource-exists" src="{1}/info.xmap">
<map:mount src="{1}/info.xmap" uri-prefix="{1}"/>
</map:act>
</map:match>
[...] (further processing of this URL)
|
- typical examply of resource-exists selector usage
- allows dynamic selection of a general or specific stylesheet
- easily reusable when implemented as a resource
- allows "inheritance" of stylesheet sets - typically the specific stylesheet imports the general one
- also useful for XML source documents
No Format |
---|
<map:match pattern="**/*.html"
<map:generate src="content/{1}/{2}.xml"/>
<map:select type="resource-exists">
<map:when test="xslt/{1}/document2page.xsl">
<map:transform src="xslt/{1}/document2page.xsl"/>
</map:when>
<map:otherwise>
<map:transform src="xslt/document2page.xml"/>
</map:otherwise>
</map:select>
<map:serialize/>
</map:match>
|
No Format |
---|
<!-- overview page -->
<!-- pattern="{area}/{doctype}/{document-id}.html" -->
<map:match pattern="*/overview.html">
<map:generate type="directory" src="content/{1}">
<map:parameter name="sort" value="date"/>
</map:generate>
<map:transform src="xslt/directory2include.xsl"/>
<map:transform type="cinclude"/>
<map:transform src="xslt/overview/include2html.xsl"/>
<map:serialize/>
</map:match>
|
Other Pattern Pages:
Wonderful. Thank you. I needed this! — Gabridome
Thanks a lot, though I'm missing pattern for usefull errorhandling! — Gernot
- Really simple, when processing something you can most often catch unknown errors with a generic exceptionhandler, those errors can at least give different messages based on a match in the errorhandler.
No Format |
---|
<map:selector name="exception" src="org.apache.cocoon.selection.XPathExceptionSelector">
<exception class="java.lang.Throwable" unroll="true"/>
<map:selector> |
- When your content is generated by xsl, the dummy xml file can be used for error messages.
No Format |
---|
<map:match pattern="**.xml">
<map:generate src="common/error.xml"/>
<map:select type="resource-exists">
<map:when test="{1}.jpg">
<map:transform src="style/picture.xsl">
<map:parameter name="name" value="{1}"/>
</map:transform>
</map:when>
</map:select>
<map:serialize/>
</map:match>
|
Errorhandling documentation --- Patrik C