org.apache.cocoon.selection
Class RegexpHeaderSelector

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
              extended by org.apache.cocoon.selection.RegexpHeaderSelector
All Implemented Interfaces:
Component, Configurable, LogEnabled, ThreadSafe, Selector, SwitchSelector

public class RegexpHeaderSelector
extends AbstractRegexpSelector

The RegexpHeaderSelector class defines a selector matching specific headers to configured regular-expression patterns.

The configuration of an RegexpHeaderSelector follows exactly what has been outlined in AbstractRegexpSelector regarding regular expression patterns, and additionally it requires an extra configuration element specifying the header whose value needs to be matched:

 <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>
       <header-name>...</header-name>
     </map:selector>
  </map:selectors>
 </map:components>
 

If not configured, or if it needs to be overriddent, the header name can also be specified as a <map:parameter .../> inside the pipeline itself.

Version:
CVS $Id: RegexpHeaderSelector.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Field Summary
protected  String headerName
          The name of the header to work on.
 
Fields inherited from class org.apache.cocoon.selection.AbstractRegexpSelector
patterns
 
Fields inherited from interface org.apache.cocoon.selection.SwitchSelector
ROLE
 
Constructor Summary
RegexpHeaderSelector()
          Create a new RegexpHeaderSelector instance.
 
Method Summary
 void configure(Configuration configuration)
          Configure this instance parsing all regular expression patterns and storing the header name upon which selection occurs.
 Object getSelectorContext(Map objectModel, Parameters parameters)
          Return the value of the header identified by the configured header name, if any.
 boolean select(String expr, Map objectModel, Parameters params)
          Selectors test pattern against some objects in a Map model and signals success with the returned boolean value
 
Methods inherited from class org.apache.cocoon.selection.AbstractRegexpSelector
compile, 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

headerName

protected String headerName

The name of the header to work on.

Constructor Detail

RegexpHeaderSelector

public RegexpHeaderSelector()

Create a new RegexpHeaderSelector instance.

Method Detail

configure

public void configure(Configuration configuration)
               throws ConfigurationException

Configure this instance parsing all regular expression patterns and storing the header name upon which selection occurs.

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

getSelectorContext

public Object getSelectorContext(Map objectModel,
                                 Parameters parameters)

Return the value of the header identified by the configured header name, if any.

Parameters:
objectModel - the Cocoon object model.
parameters - the Parameters associated with the pipeline.
Returns:
the value of the configured request parameter or null.

select

public boolean select(String expr,
                      Map objectModel,
                      Parameters params)
Selectors test pattern against some objects in a Map model and signals success with the returned boolean value

Specified by:
select in interface Selector
Overrides:
select in class AbstractSwitchSelector
Parameters:
expr - The expression to test.
objectModel - The Map containing object of the calling environment which may be used to select values to test the expression.
params - The sitemap parameters, as specified by <parameter/> tags.
Returns:
Signals successful test.


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