Matchers

Matchers are used to match the request into a particular pipeline. In Paloose (version 0.7.0 or later) there are two types of matcher: WildcardURIMatcher and RegexpURIMatcher. WildcardURIMatcher is equivalent to the Cocoon matcher of the same name. However RegexpURIMatcher is slightly different to its Cocoon equivalent: it uses a PHP-modified Perl regular expression syntax. For details of this see the PHP manual pages)

<map:matchers default="wildcard"> <map:matcher name="wildcard" src="resource://lib/matching/WildcardURIMatcher"/> <map:matcher name="regexp" src="resource://lib/matching/RegexpURIMatcher"/> </map:matchers>

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

Sitemap Variables and Matching Patterns

It is possible to define variables in the Cocoon sitemap. Paloose uses this principle, but, at present, uses a very restricted set. Like Cocoon variables are defined by enclosing them in brackets "{...}". The primary area where this is used is in the pattern matching.

Wildcard Pattern Matching

For example take the wildcard matcher

<map:match pattern="*/*.html"> ... </map:match>

The wildcards in the match pattern are assigned to internal pattern variables "{1}", "{2}" etc, in a similar fashion to Perl regular expressions. So in the above case if the pattern to be matched is "documentation/index.html" then there would be a match. The internal variables would be set {1} = "documentation" and {2} = "index". These variables are used within the various pipeline components to resolve string expressions. For example

<map:match pattern="*/*.html"> <map:generate src="context://{1}/{2}.xml"/> ... </map:match>

In this case the generator would fetch the file documentation/index.xml from the current application context (see pseudo protocols below). Note that the constructions "**" and "*" are different and are identical to their Cocoon counterparts.

The values for the pattern variables are taken from the current matcher. If you want to access a higher matcher (wherever it is) then you would have to use the string {../1}, which means access the pattern variable {1} in the previous matcher. These can be extended as necessary, for example {../../1} to access a matcher two levels above the current one.

Regular Expression Pattern Matching

Since version 0.7.0 it has been possible to carry out matching using regular expressions. Paloose regular expressions are not the same as Cocoon regular expressions. The PHP5 version based on Perl is used and a full description of the regexp can be found on the PHP5 manual page. The pattern variables work in similar fashion as the wildcard matcher. For example:

<map:match type="regexp" pattern="/.*\.(html)|(tex)|(xml)/"> ... </map:match>

would match all requests that have a file extension "html", "tex" and "xml". In the following all requests for documents between "nb1996" and "nb1999" would read the html file directly:

<map:match type="regexp" pattern="/nb199([6789]).html/"> <map:read src="context://nb/199{1}/nb199{1}.html"/> </map:match>

and the following would take all others in 2000 or later and process them from an XML file.

<map:match type="regexp" pattern="/nb20(.+).html/"> <map:generate src="cocoon:/20{1}/nb20{1}.xml" label="xml-content"/> <map:transform src="context://resources/transforms/notebooks-html.xsl" label="page-transform"> <map:parameter name="page" value="nb20{1}"/> </map:transform> <map:serialize/> </map:match>
Copyright 2006 – 2023 Hugh Field-Richards. All Rights Reserved.