CookieSelector

- TARGET-AUDIENCE: *beginner*
- COCOON-RELEASES: 2.1.4
- DOCUMENT-STATUS: *draft*


What you will get from this page

How to use the CookieSelector.

If you wondered how to use the CookieSelector, here's how.

In the sitemap's <map:selectors> block, make sure you have:

<map:selector name="cookie-selector" src="org.apache.cocoon.selection.CookieSelector"/>

I may be preaching to the choir here, but as a gentle reminder: the "name" attribute for the selector doesn't need to be "cookie-selector," it can be anything you want it to be, so long as you don't reuse the name for something else...

Here's a snippet from a sample sitemap.xmap that uses the CookieSelector:

<map:match pattern="**.html">
  <map:aggregate element="root">
    <map:part src="cocoon://{1}.links"/>
    <map:part src="cocoon://content/{1}.html"/>
    <map:part src="cocoon://get-quote"/>
    <map:part src="cocoon://skin-form"/>
  </map:aggregate>
  <map:select type="cookie-selector">
  <map:parameter name="cookie-name" value="the-name-of-the-cookie"/>
    <map:when test="skin-style-1">
      <map:transform src="stylesheets/facade/abstract-style.xsl"/>
    </map:when>
    <map:when test="skin-style-2">
      <map:transform src="stylesheets/facade/vanity-style.xsl"/>
    </map:when>                      
    <map:otherwise>
      <map:transform src="stylesheets/facade/default-style.xsl"/>
    </map:otherwise>
  </map:select>   
  <map:serialize type="html"/>
</map:match> 

A quick explanation as to what's going on here: <map:select type="cookie-selector"> tells Cocoon to use the aforementioned CookieSelector.

<map:parameter name="cookie-name" value="the-name-of-the-cookie"/> The 'name="cookie-name"' part of the parameter tells Cocoon it is selecting a cookie by name, the name of the cookie is provided by the 'value="the-name-of-the-cookie"' bit.

<map:when test="some-aribitrary-value"> Tests the value of the cookie against a value you specify: ie "some-arbitrary-value".

<map:otherwise> provides a nice safe default if the value of the cookie doesn't match any of the test values for which you are testing (selecting).

I use this particular block in the sitemap to implement a persistent "skinnable" website.

Have fun!


page metadata

- AUTHOR:[MichaelTiffany[BR]] - AUTHOR-CONTACT: mailto:mtiffany71@aol.com[[BR]] - REVIEWED-BY:[[BR]] - REVIEWER-CONTACT:[[BR]]

CookieSelector (last edited 2009-09-20 23:40:50 by localhost)