org.apache.cocoon.selection
Class AbstractRegexpSelector

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.selection.AbstractSwitchSelector
          extended byorg.apache.cocoon.selection.AbstractRegexpSelector
All Implemented Interfaces:
Configurable, org.apache.cocoon.selection.Selector, org.apache.cocoon.selection.SwitchSelector, ThreadSafe

public abstract class AbstractRegexpSelector
extends AbstractSwitchSelector
implements Configurable

The AbstractRegexpSelector abstract class defines a simple selector operating over configured regular-expression patterns.

Configuration of an AbstractRegexpSelector is quite simple: first of all the patterns used for selections must be configured:

 <map:components>
   ...
   <map:selectors default="...">
     <map:selector name="..." src="org.apache.cocoon.selection....">
       <pattern name="empty">^$</pattern>
       <pattern name="number">^[0-9]+$</pattern>
       <pattern name="string">^.+$</pattern>
     </map:selector>
  </map:selectors>
 </map:components>
 

Then, each configured pattern can be referenced in the pipelines section of the sitemap:

 <map:pipelines>
   ...
   <map:match ...>
     ...
     <map:select type="browser">
       <map:when test="empty">...</map:when>
       <map:when test="number">...</map:when>
       <map:when test="string">...</map:when>
       <map:otherwise>...</map:otherwise>
     </map:select>
     ...
   </map:match>
   ...
 </map:pipelines>
 

Version:
$Id: AbstractRegexpSelector.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  Map patterns
          A Map of regular expression programs by name.
 
Fields inherited from interface org.apache.cocoon.selection.SwitchSelector
ROLE
 
Constructor Summary
protected AbstractRegexpSelector()
          Create a new AbstractRegexpSelector instance.
 
Method Summary
protected  REProgram compile(String pattern)
          Compile the pattern in a REProgram.
 void configure(Configuration configuration)
          Configure this instance parsing all regular expression patterns.
 boolean select(String patternName, Object selectorContext)
          Select a pipeline fragment based on a previously configured pattern.
 
Methods inherited from class org.apache.cocoon.selection.AbstractSwitchSelector
select
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.selection.SwitchSelector
getSelectorContext
 

Field Detail

patterns

protected Map patterns

A Map of regular expression programs by name.

Constructor Detail

AbstractRegexpSelector

protected AbstractRegexpSelector()

Create a new AbstractRegexpSelector instance.

Method Detail

select

public boolean select(String patternName,
                      Object selectorContext)

Select a pipeline fragment based on a previously configured pattern.

Specified by:
select in interface org.apache.cocoon.selection.SwitchSelector
Parameters:
patternName - the name of the configured pattern.
selectorContext - the string to be matched by the named pattern.
Returns:
true if the contexts is matched by the configured pattern.

configure

public void configure(Configuration configuration)
               throws ConfigurationException

Configure this instance parsing all regular expression patterns.

Specified by:
configure in interface Configurable
Parameters:
configuration - the Configuration instance where configured patterns are defined.
Throws:
ConfigurationException - if one of the regular-expression to configure could not be compiled.

compile

protected REProgram compile(String pattern)
                     throws ConfigurationException

Compile the pattern in a REProgram.

Parameters:
pattern - the regular expression pattern in a textual format.
Returns:
a compiled regular expression pattern.
Throws:
ConfigurationException - in the pattern could not be compiled.


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.