Class LocaleMatcher

  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.matching.LocaleMatcher
All Implemented Interfaces:
Disposable, Component, Configurable, LogEnabled, Serviceable, ThreadSafe, Matcher

public class LocaleMatcher
extends AbstractLogEnabled
implements Matcher, ThreadSafe, Serviceable, Configurable, Disposable

A matcher that locates and identifies to the pipeline a source document to be used as the content for an i18n site, based upon a locale provided in a range of ways.


A sample configuration (given in the <map:matchers> section of the sitemap) is given below. This configuration shows default values.

   <map:matcher name="i18n" src="org.apache.cocoon.matching.LocaleMatcher">
     <default-locale language="en" country="US"/>

Above configuration parameters mean:


This matcher will be used in a pipeline like so:

   <map:match pattern="*.html">
     <map:match type="i18n" pattern="xml/{1}.*.xml">
       <map:generate src="{source}"/>

* in the pattern identifies the place where locale should be inserted. In case of a blank locale, if character before and after * is the same (like in example above), duplicate will be removed (xml/{1}.*.xml becomes xml/{1}.xml).

Locale Identification

Locales will be tested in following order:

If negotiate mode is set to true, a source will be looked up using each locale. Where the full locale (language, country, variant) doesn't match, it will fall back first to language and country, and then just language, before moving on to the next locale.

If negotiate mode is set to false (default), first found locale will be returned.

Sitemap Variables

Once a matching locale has been found, the following sitemap variables will be available to sitemap elements contained within the matcher:

CVS $Id: LocaleMatcher.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Upayavira, Vadim Gritsenko

Field Summary
Fields inherited from interface org.apache.cocoon.matching.Matcher
Constructor Summary
Method Summary
 void configure(Configuration config)
 void dispose()
 Map match(String pattern, Map objectModel, Parameters parameters)
          Matches the pattern against some Request values and returns a Map object with replacements for wildcards contained in the pattern.
 void service(ServiceManager manager)
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public LocaleMatcher()
Method Detail


public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable


public void configure(Configuration config)
Specified by:
configure in interface Configurable


public void dispose()
Specified by:
dispose in interface Disposable


public Map match(String pattern,
                 Map objectModel,
                 Parameters parameters)
          throws PatternException
Description copied from interface: Matcher
Matches the pattern against some Request values and returns a Map object with replacements for wildcards contained in the pattern.

Specified by:
match in interface Matcher
pattern - The pattern to match against. Depending on the implementation the pattern can contain wildcards or regular expressions.
objectModel - The Map with object of the calling environment which can be used to select values this matchers matches against.
Map The returned Map object with replacements for wildcards/regular-expressions contained in the pattern. If the return value is null there was no match.

Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.