apache > cocoon
 

Regular-Expression-Header-Selector in Cocoon

RegexpHeaderSelector

NAME

regexp-header

WHAT

The RegexpHeaderSelector component is used to select appropriate sitemap processing depending on a particular header value.

TYPE

Selector, Sitemap Component

BLOCK

Core

CLASS

org.apache.cocoon.selection.RegexpHeaderSelector

SINCE

Cocoon 2.1.6

CACHEABLE

not applicable

Description

The RegexpheaderSelector tests a header field against the test attribute of the selectors when clause.

Usage

The RegexpHeaderSelector allows to define sitemap processing based on the content of a particular header field.

Sitemap pipeline examples

<map:select type="regexp-header">
  <map:when test="xhtml">
  ....
  </map:when>
  ...
  <map:otherwise>
  ...
  </map:otherwise>
</map:select>
        

Sitemap component configuration example

<map:selectors...
  <map:selector name="regexp-header" 
    src="org.apache.cocoon.selection.RegexpHeaderSelector"
    
    <pattern name="xhtml">application/xhtml\+xml</pattern>
    ...
    <header-name>accept</header-name>
    
  </map:selectors>
...

Configuration

The configuration section of RegexpHeaderSelector specifies a mapping from header strings to symbolic pattern names.

Each pattern element specifies a name attribute holding the symbolic pattern name used in the test attribute expression. The contents contains a regular expression to match against the header value.

The header concerned is named by the contents of the header-name element.

Setup

Setting up a RegexpHeaderSelector includes choosing the <map:when> test expressions, and a optional <map:otherwise> clause.

The test attribute of the <map:when> clause must match a pattern attribute name value. The value of the test attribute in a <map:when> clause must be declared in a pattern name attribute.

The header-name can be overridden by a parameter element.

Effect on Object Model and Sitemap Parameters

The RegexpHeaderSelector has no side effects on the object model, or any sitemap parameters.

Notes

The main motivation for this selector is to do some simple content negotiation to serve XHTML 1.1 pages where the browser indicates it accepts application/xhtml+xml, and HTML pages otherwise. However, this has many more uses, including automatic i18n according to the accept-language header.

Bugs/Caveats

The RegexpHeaderSelector adds the response header attribute Vary having a value of the header name, indicating that the response differ for different user agents. This information especially meaningfull for an http-proxy server.

History

26-07-04: initial creation

See also

A general documentation about selectors is available at Matchers and Selectors.