org.apache.cocoon.selection
Class AbstractRegexpSelector

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

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:
CVS $Id: AbstractRegexpSelector.html 1304258 2012-03-23 10:09:27Z ilgrosso $
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
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
 
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 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 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-2010 The Apache Software Foundation. All Rights Reserved.