cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carsten Ziegeler" <>
Subject C2: Contributing BrowserSelectorFactory
Date Thu, 07 Sep 2000 10:12:31 GMT

as I promised here is my contribution of a BrowserSelectorFactory which works like the media
selection of Cocoon 1. It checks the User-Agent of the HttpRequest against a given string.

You can configure the Factory in the sitemap like the following (which is adapted from the of C1):

   <map:selector name="browser" factory="org.apache.cocoon.selection.BrowserSelectorFactory">
	<!-- # NOTE: The appearance indicates the search order. This is very important since
		# some words may be found in more than one browser description. (MSIE is
		# presented as "Mozilla/4.0 (Compatible; MSIE 4.01; ...")
	<browser name="explorer" useragent="MSIE"/>
	<browser name="pocketexplorer" useragent="MSPIE"/>
	<browser name="handweb" useragent="HandHTTP"/>
	<browser name="avantgo" useragent="AvantGo"/>
	<browser name="imode" useragent="DoCoMo"/>
	<browser name="opera" useragent="Opera"/>
	<browser name="lynx" useragent="Lynx"/>
	<browser name="java" useragent="Java"/>
	<browser name="wap" useragent="Nokia"/>
	<browser name="wap" useragent="UP"/>
	<browser name="wap" useragent="Wapalizer"/>
	<browser name="mozilla5" useragent="Mozilla/5"/>
	<browser name="mozilla5" useragent="Netscape6/"/>
	<browser name="netscape" useragent="Mozilla"/>

You can then easily use the selector inside your pipeline:
	<map:select type="browser">
		<map:when test="explorer">
			<map:transform src="sunshine/styles/IE-html.xsl"/>
		<map:when test="netscape">
			<map:transform src="sunshine/styles/NN-html.xsl"/>
			<map:transform src="sunshine/styles/Unknown-html.xsl"/>
This means, if the user-agent contains the string "MSIE" the browser is detected as "explorer"
and the first "map:when" is "executed". If the user-agent does not contain "MSIE" but "Mozilla"
it is detected as "netscape" and so on.
If the user-agent does not contain any of the given patterns, "otherwise is executed".

And finally: Attached to this email is the source.

I hope you like it, find it as useful as we do and include it into C2.

Carsten Ziegeler

Open Source Group              sunShine - Lighting up e:Business
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn                  

View raw message