some weeks ago I posted a proposal about a set of content negotiation selectors that I wrote, based on a negotiation class written (mostly) by a colleague of mine:
* ContentTypeSelector
* CharsetSelector
* LanguageSelector
(see the attached README.txt for more info)
Until now there was no response. What do you think?
--
Johannes Koch . IT Developer
Pixelpark AG . http://www.pixelpark.com
Rotherstra�e 8 . 10245 Berlin . Germany
phone: +49 30 5058 - 1288 . fax: - 1355
HttpNegotiation
---------------
HTTP [1] issues:
- HTTP permits several HTTP headers of one type; WSP requires a separate
HTTP header for each value, e.g.:
Accept-Charset: iso-8859-1
Accept-Charset: utf-8
- headers values are concatenated with ',' separator, e.g.
Accept-Charset: iso-8859-1, utf-8
- HTTP permits parameters for a header value, e.g.
application/vnd.wap.wmlc;level=1.1
- HTTP defines optional preference parameters (q factor), indicating the
client's preference with 0 being the lowest and 1 being the highest
preference; no explicit preference is defined as 1; e.g.
text/html;q=0.5
implementation issues:
- implicit q factors for wildcards:
- */*; q=0.01
- type/*; q=0.02
- *; q=0.01
getPreferredContentType
- uses HTTP Accept header (comma-separated list of MIME media types [2]
with optional parameters)
- performs best match:
- type/subtype match is better than
- type/* match is better than
- */* match
- returns best matching variant
- work-around:
- some clients use only wildcards and so misleadingly claim to support
every MIME type (*/*) or every subtype of a particular type (type/*)
- in case the best matching variant is a wildcard, the default variant
will be returned
getPreferredCharset
- uses HTTP Accept-Charset header (comma-separated list of character sets
[3] with optional parameters)
- performs best match:
- charset match is better than
- * match
- returns best matching variant
getPreferredLanguage
- uses HTTP Accept-Language header (comma-separated list of languages [4]
with optional '-' delimiter and country code [5], with optional
parameters)
- performs best match:
- language-country is better than
- language match
- returns best matching variant
- in case the client understands language, the server provides
language-country, language-country will be returned, although it would
not be a strict match
getPreferredEncoding
- uses HTTP Accept-Encoding header (comma-separated list of content
codings [6] with optional parameters)
- performs best match:
- encoding match is better than
- * match
- returns best matching variant
--------------------------------------------------------------------
Cocoon selectors
----------------
ContentTypeSelector
- reads configuration from sitemap
- calls getPreferredContentType
- sets Vary header appropriately
- returns name of preferred variant (as configured in sitemap)
CharsetSelector
- reads configuration from sitemap
- calls getPreferredCharset
- sets Vary header appropriately
- returns name of preferred variant (as configured in sitemap)
LanguageSelector
- reads configuration from sitemap
- calls getPreferredLanguage
- sets Vary header appropriately
- returns name of preferred variant (as configured in sitemap)
--------------------------------------------------------------------
sitemap.xmap extract:
...
<map:serializers ...>
<!-- HTML 4.01 Strict (UTF-8) -->
<map:serializer logger="sitemap.serializer.html"
mime-type="text/html; charset=utf-8" name="html_utf8"
pool-grow="4" pool-max="32" pool-min="4"
src="org.apache.cocoon.serialization.HTMLSerializer">
<buffer-size>1024</buffer-size>
<encoding>utf-8</encoding>
<doctype-public>-//W3C//DTD HTML 4.01//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/html4/strict.dtd</doctype-system>
</map:serializer>
<!-- HTML 4.01 Strict (ISO-8859-1) -->
<map:serializer logger="sitemap.serializer.html"
mime-type="text/html; charset=iso-8859-1" name="html_latin1"
pool-grow="4" pool-max="32" pool-min="4"
src="org.apache.cocoon.serialization.HTMLSerializer">
<buffer-size>1024</buffer-size>
<encoding>iso-8859-1</encoding>
<doctype-public>-//W3C//DTD HTML 4.01//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/html4/strict.dtd</doctype-system>
</map:serializer>
<!-- WML 1.1 (UTF-8) -->
<map:serializer logger="sitemap.serializer.wml"
mime-type="text/vnd.wap.wml; charset=utf-8" name="wml_utf8"
src="org.apache.cocoon.serialization.XMLSerializer">
<encoding>utf-8</encoding>
<indent>no</indent>
<doctype-public>-//WAPFORUM//DTD WML 1.1//EN</doctype-public>
<doctype-system>http://www.wapforum.org/DTD/wml_1.1.xml</doctype-system>
</map:serializer>
<!-- WML 1.1 (ISO-8859-1) -->
<map:serializer logger="sitemap.serializer.wml"
mime-type="text/vnd.wap.wml; charset=iso-8859-1" name="wml_latin1"
src="org.apache.cocoon.serialization.XMLSerializer">
<encoding>iso-8859-1</encoding>
<indent>no</indent>
<doctype-public>-//WAPFORUM//DTD WML 1.1//EN</doctype-public>
<doctype-system>http://www.wapforum.org/DTD/wml_1.1.xml</doctype-system>
</map:serializer>
<!-- XHTML Mobile 1.0 (UTF-8) -->
<map:serializer logger="sitemap.serializer.xhtml"
mime-type="application/vnd.wap.xhtml+xml; charset=utf-8"
name="xhtml-mp_utf8" pool-grow="2" pool-max="64" pool-min="2"
src="org.apache.cocoon.serialization.XMLSerializer">
<encoding>utf-8</encoding>
<indent>no</indent>
<doctype-public>-//WAPFORUM//DTD XHTML Mobile 1.0//EN</doctype-public>
<doctype-system>http://www.wapforum.org/DTD/xhtml-mobile1.0.dtd</doctype-system>
</map:serializer>
<!-- XHTML Mobile 1.0 (ISO-8859-1) -->
<map:serializer logger="sitemap.serializer.xhtml"
mime-type="application/vnd.wap.xhtml+xml; charset=iso-8859-1"
name="xhtml-mp_latin1" pool-grow="2" pool-max="64" pool-min="2"
src="org.apache.cocoon.serialization.XMLSerializer">
<encoding>iso-8859-1</encoding>
<indent>no</indent>
<doctype-public>-//WAPFORUM//DTD XHTML Mobile 1.0//EN</doctype-public>
<doctype-system>http://www.wapforum.org/DTD/xhtml-mobile1.0.dtd</doctype-system>
</map:serializer>
</map:serializers>
...
<map:selectors ...>
<!-- selecting the preferred content-type for markup -->
<map:selector logger="sitemap.selector.contenttype" name="contentType"
src="org.apache.cocoon.selection.ContentTypeSelector">
<variant name="xhtml-mp" mime-type="application/vnd.wap.xhtml+xml" q="1.0"/>
<variant name="wml" mime-type="application/vnd.wap.wmlc" q="0.95"/>
<variant name="html" mime-type="text/html" q="0.9"/>
</map:selector>
<!-- selecting the preferred language for content -->
<map:selector logger="sitemap.selector.language" name="language"
src="org.apache.cocoon.selection.LanguageSelector">
<variant name="fr" language="fr" q="1.0"/>
<variant name="de" language="de" q="1.0"/>
<variant name="en" language="en" q="1.0"/>
</map:selector>
<!-- selecting the preferred character encoding for markup -->
<map:selector logger="sitemap.selector.charset" name="charset"
src="org.apache.cocoon.selection.CharsetSelector">
<variant name="latin1" charset="iso-8859-1" q="1.0"/>
<variant name="utf8" charset="utf-8" q="0.95"/>
</map:selector>
</map:selectors>
...
<!-- start HttpNegotiationSelector test -->
<map:pipeline>
<map:match pattern="hns">
<!-- tests the preferred language -->
<!-- make sure to test for every configured language, apart from one
(one default language); otherwise a wrong Content-Language
header may be set.
In this case we have three languages in the selector
configuration: 'fr', 'de', and 'en'; so we test for 'fr' and
'de'. -->
<map:select type="language">
<!-- preferred language is french -->
<map:when test="fr">
<map:generate src="hns/test.fr"/>
</map:when>
<!-- preferred language is german -->
<map:when test="de">
<map:generate src="hns/test.de"/>
</map:when>
<!-- default language is english -->
<map:otherwise>
<map:generate src="hns/test.en"/>
</map:otherwise>
</map:select>
<!-- tests the preferred content-type -->
<map:select type="contentType">
<!-- preferred content-type is application/vnd.wap.xhtml+xml -->
<map:when test="xhtml-mp">
<map:transform src="hns/xsl/html/test.xsl"/>
<!-- tests the preferred character encoding -->
<map:select type="charset">
<!-- preferred character encoding is utf-8 -->
<map:when test="utf8">
<map:serialize type="xhtml-mp_utf8"/>
</map:when>
<!-- default character encoding is iso-8859-1 -->
<map:otherwise>
<map:serialize type="xhtml-mp_latin1"/>
</map:otherwise>
</map:select>
</map:when>
<!-- preferred content-type is application/vnd.wap.wmlc -->
<map:when test="wml">
<map:transform src="hns/xsl/wml/test.xsl"/>
<!-- tests the preferred character encoding -->
<map:select type="charset">
<!-- preferred character encoding is utf-8 -->
<map:when test="utf8">
<map:serialize type="wml_utf8"/>
</map:when>
<!-- default character encoding is iso-8859-1 -->
<map:otherwise>
<map:serialize type="wml_latin1"/>
</map:otherwise>
</map:select>
</map:when>
<!-- default content-type is text/html -->
<map:otherwise>
<map:transform src="hns/xsl/html/test.xsl"/>
<!-- tests the preferred character encoding -->
<map:select type="charset">
<!-- preferred character encoding is utf-8 -->
<map:when test="utf8">
<map:serialize type="html_utf8"/>
</map:when>
<!-- default character encoding is iso-8859-1 -->
<map:otherwise>
<map:serialize type="html_latin1"/>
</map:otherwise>
</map:select>
</map:otherwise>
</map:select>
</map:match>
</map:pipeline>
<!-- end HttpNegotiationSelector test -->
...
--------------------------------------------------------------------
[1] HTTP 1.1: http://www.ietf.org/rfc/rfc2616.txt
[2] MIME media type: http://www.ietf.org/rfc/rfc2046.txt
[3] character set: http://www.iana.org/assignments/character-sets
[4] language: ISO 639
[5] country: ISO 3166
[6] content coding: http://www.iana.org/assignments/http-parameters
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
