Selectors

Selectors are the conditional constructions for sitemaps. The most commonly used one is the BrowserSelector which allows different routes in the pipeline dependant on the client's browser. Useful for differences in browser behaviour. The Paloose site makes use of this so that the text based Lynx and the iPhone browser are supported.

Component Declaration

Selectors are defined in the component declaration part of the Sitemap.

<map:selectors default="browser"> <map:selector name="browser" src="resource://lib/selection/BrowserSelector"> <map:browser name="explorer" useragent="MSIE"/> ... </map:selector> </map:selectors>

The default attribute specifies the type of selector to use if none is specified in a pipeline.

BrowserSelector

The root sitemap needs to have the BrowserSelector declared as a component:

<map:components> ... <map:selectors default="browser"> <map:selector name="browser" src="resource://lib/selection/BrowserSelector"> <map:browser name="explorer" useragent="MSIE"/> <map:browser name="pocketexplorer" useragent="MSPIE"/> <map:browser name="handweb" useragent="HandHTTP"/> <map:browser name="avantgo" useragent="AvantGo"/> <map:browser name="imode" useragent="DoCoMo"/> <map:browser name="opera" useragent="Opera"/> <map:browser name="lynx" useragent="Lynx"/> <map:browser name="java" useragent="Java"/> <map:browser name="wap" useragent="Nokia"/> <map:browser name="wap" useragent="UP"/> <map:browser name="wap" useragent="Wapalizer"/> <map:browser name="mozilla5" useragent="Mozilla/5"/> <map:browser name="mozilla5" useragent="Netscape6/"/> <map:browser name="netscape" useragent="Mozilla"/> <map:browser name="safari" useragent="Safari"/> <map:browser name="iphone" useragent="iPhone"/> </map:selector> </map:selectors> ... </map:components>

where

Each sub-element, <map:browser>, defines a particular browser by its user agent type, where

We can use the selector in the pipeline in any position provided that the overall conditions for the pipeline are met: that is, a pipeline must start with a generator and end with a serializer, or have a mount or reader pipeline element. For example (from this site):

<map:match pattern="**.html"> <map:aggregate element="root" label="aggr-content"> <map:part src="cocoon:/headings.xml" element="headings" strip-root="true"/> <map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/> <map:part src="cocoon:/newsArticles.xml" element="news-articles" strip-root="true"/> <map:part src="cocoon:/{1}.xml" element="content" strip-root="true"/> </map:aggregate> <map:select type="browser"> <map:when test="lynx"> <map:transform src="context://resources/transforms/page2lynx.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> </map:when> <map:otherwise> <map:transform src="context://resources/transforms/page2html.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> </map:otherwise> </map:select> <map:transform src="context://resources/transforms/stripNamespaces.xsl"/> <map:serialize type="html" /> </map:match>

RequestParameterSelector

The sitemap needs to have the RequestParameterSelector declared as a component:

<map:selectors default="browser"> ... <map:selector name="request-parameter" src="resource://lib/selection/RequestParameterSelector"> <map:parameter-name>type</map:parameter-name> </map:selector> </map:selectors>

where

The <map:paraneter-name> tag defines a default test parameter in the query string if one is not defined in the pipeline (in this case 'type'.

We can use the selector in the pipeline in any position provided that the overall conditions for the pipeline are met: that is, a pipeline must start with a generator and end with a serializer, or have a mount, call or reader pipeline element. For example (from the Chandos Symphony Orchestra site):

<map:match pattern="*.html"> <map:aggregate element="root" label="aggr-content"> <map:part src="cocoon:/menus.xml" element="menus" strip-root="true"/> <map:part src="cocoon:/newsArticles.xml" element="newsArticles" strip-root="true"/> <map:part src="cocoon:/futureConcerts.xml" element="futureConcerts" strip-root="true"/> <map:part src="cocoon:/{1}.xml" element="content" strip-root="true"/> </map:aggregate> <map:select type="request-parameter"> <map:parameter name="parameter-name" value="type"/> <map:when test="xml"> <map:transform src="context://resources/transforms/extractXML.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> <map:call resource="outputXML"/> </map:when> <map:when test="text"> <map:transform src="context://resources/transforms/extractXML.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> <map:transform src="context://resources/transforms/xml2text.xsl" label="text-transform"> <map:parameter name="page" value="{1}"/> </map:transform> <map:call resource="outputPage"/> </map:when> <map:otherwise> <map:transform src="context://resources/transforms/page2html.xsl" label="page-transform"> <map:parameter name="page" value="{1}"/> </map:transform> <map:call resource="outputPage"/> </map:otherwise> </map:select> </map:match>

RegexpSelector

The sitemap needs to have the RegexpSelector declared as a component:

<map:selectors default="browser"> <map:selector name="regexp-selector" src="resource://lib/selection/RegexpSelector"/> </map:selectors>

where

We can use the selector in the pipeline in any position provided that the overall conditions for the pipeline are met: that is, a pipeline must start with a generator and end with a serializer, or have a mount, call or reader pipeline element. For example (from an experimental Paloose CMS system:

<map:component-configurations> <map:global-variables> <themesDir>context://themes</themesDir> <defaultTheme>{ant:default-theme}</defaultTheme> <currentTheme>{cookies:theme}</currentTheme> <rootDir>context://</rootDir> </map:global-variables> </map:component-configurations> <map:pipeline> <map:match pattern="/(page).html/" type="regexp"> <map:act type="cookies"> <map:select type="regexp-selector"> <map:parameter name="test-value" value="{global:currentTheme}"/> <map:when test="/.+/"> <map:generate src="context://themes/{global:currentTheme}/data/body.xml" label="raw-xml"/> </map:when> <map:otherwise> <map:generate src="context://themes/astral/data/body.xml" label="raw-xml"/> </map:otherwise> </map:select> ... <map:transform type="moduleWrite"/> </map:act> </map:match>

In the example the selector checks for a current theme (/.+/ is any character). If the string is empty then the otherwise clause is carried out. If there is a theme declared then the appropriate theme directory is used.

VariableSelector

The sitemap needs to have the VariableSelector declared as a component:

<map:selectors default="browser"> <map:selector name="variable-selector" src="resource://lib/selection/VariableSelector"/> </map:selectors>

where

We can use the selector in the pipeline in any position provided that the overall conditions for the pipeline are met: that is, a pipeline must start with a generator and end with a serializer, or have a mount, call or reader pipeline element. For example (from an experimental Paloose CMS system:

<map:component-configurations> <map:global-variables> <themesDir>context://themes</themesDir> <defaultTheme>{ant:default-theme}</defaultTheme> <currentTheme>{cookies:theme}</currentTheme> <rootDir>context://</rootDir> </map:global-variables> </map:component-configurations> <map:pipeline> <map:match pattern="/(page).html/" type="regexp"> <map:act type="cookies"> <map:select type="variable-selector"> <map:parameter name="parameter-name" value="{cookies:theme}"/> <map:when test=""> <map:generate src="context://themes/astral/data/body.xml" label="raw-xml"/> </map:when> <map:otherwise> <map:generate src="context://themes/{cookies:theme}/data/body.xml" label="raw-xml"/> </map:otherwise> </map:select> ... <map:transform type="moduleWrite"/> </map:act> </map:match>

This almost the same as the previous example.

Copyright 2006 – 2011 Hugh Field-Richards. All Rights Reserved.