org.apache.cocoon.selection
Class AbstractRegexpSelector

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.selection.AbstractSwitchSelector
          extended byorg.apache.cocoon.selection.AbstractRegexpSelector
All Implemented Interfaces:
Configurable, LogEnabled, Selector, SwitchSelector, ThreadSafe
Direct Known Subclasses:
RegexpHeaderSelector, RegexpRequestParameterSelector

public abstract class AbstractRegexpSelector
extends AbstractSwitchSelector
implements Configurable, ThreadSafe

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:
CVS $Id: AbstractRegexpSelector.java 30941 2004-07-29 19:56:58Z vgritsenko $
Author:
Pier Fumagalli

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  org.apache.regexp.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
getSelectorContext, select
 
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
 

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 SwitchSelector
Specified by:
select in class AbstractSwitchSelector
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 org.apache.regexp.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-2005 The Apache Software Foundation. All Rights Reserved.