You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Carsten Ziegeler <cz...@sundn.de> on 2000/09/07 12:12:31 UTC
C2: Contributing BrowserSelectorFactory
Hello,
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 cocoon.properties 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"/>
</map:selector>
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>
<map:when test="netscape">
<map:transform src="sunshine/styles/NN-html.xsl"/>
</map:when>
....
<map:otherwise>
<map:transform src="sunshine/styles/Unknown-html.xsl"/>
</map:otherwise>
</map:select>
...
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.
Regards
Carsten Ziegeler
Open Source Group sunShine - Lighting up e:Business
================================================================
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
www.sundn.de mailto:cziegeler@sundn.de
================================================================
AW: C2: Contributing BrowserSelectorFactory
Posted by Carsten Ziegeler <cz...@sundn.de>.
Hello,
sorry...but I send the wrong class file. This one has the corrected class name inside (I hope...)
Regards
Carsten Ziegeler
Open Source Group sunShine - Lighting up e:Business
================================================================
Carsten Ziegeler, S&N AG, Klingenderstrasse 5, D-33100 Paderborn
www.sundn.de mailto:cziegeler@sundn.de
================================================================