org.apache.cocoon.selection
Class DateSelector

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.selection.AbstractSwitchSelector
          extended byorg.apache.cocoon.selection.DateSelector
All Implemented Interfaces:
Configurable, LogEnabled, Selector, SwitchSelector, ThreadSafe

public class DateSelector
extends AbstractSwitchSelector
implements Configurable, ThreadSafe

A Selector depending on current date, and time.

This selector matches when a configured date is before, respectivly after the current date, and time.

You may want to use this selector to make the pipeline behaviour time dependent.

The configuration of DataSelector configures for a symbolic name a compare-mode, and a date-time value.
The compare mode is specified by the element name before, or after. The date-time value is specified by the attribute date. The attribute dateformat specifies the dateformat of the date-time value. Time only values are relative to the current date. Optionally you specify a country, and a language attribute for specifying the locale used in the date-value parsing. Per default the default locale is used.

The following configuration example, sets partition a day into four time areas, each spanning six hours, giving them symbolic names night, morning, afternoon, and evening.


  <map:components>
  ...
    <map:selectors default="browser">
    ...
      <map:selector type="date" src="org.apache.cocoon.selection.DateSelector">
        <before name="night" date="06:00:00" dateformat="HH:mm:ss"/>
        <before name="morning" date="12:00:00" dateformat="HH:mm:ss"/>
        <before name="afternoon" date="18:00:00" dateformat="HH:mm:ss"/>
        <before name="evening" date="23:59:59" dateformat="HH:mm:ss"/>
      </map:selector>
    ...
    </map:selectors>
  ...
  </map:components>
 

The above date selector definition is used to control the behaviour of a pipeline processing depending on the current time of day.


  <map:pipelines>
    <map:pipeline>
    ...
      <map:match pattern="&asterik;&asterik;/resources/*.css">
      <map:select type="date">
        <map:when test="night">
          <!-- do something for night publishing -->
          <map:read src="resources/{2}-night.css" mime-type="text/css>
        </map:when>
        <map:when test="morning">
          <!-- do something for night publishing -->
          <map:read src="resources/{2}-morning.css" mime-type="text/css>
        </map:when>
        ...
        <map:otherwise>
          <!-- define for completness, and if selecting fails due to errors -->
        </map:otherwise>
      </map:select>
    </map:pipeline>
  </map:pipelines>
 

Version:
CVS $Id: DateSelector.java 156626 2005-03-09 09:43:39Z cziegeler $
Author:
Bernhard Huber

Field Summary
static String AFTER_ELEMENT
           
static String BEFORE_ELEMENT
           
static String COUNTRY_ATTR
           
static String DATE_ATTR
           
static String DATEFORMAT_ATTR
           
static String LANGUAGE_ATTR
           
static String NAME_ATTR
           
 
Fields inherited from interface org.apache.cocoon.selection.SwitchSelector
ROLE
 
Constructor Summary
DateSelector()
           
 
Method Summary
 void configure(Configuration config)
           
protected  void configure(Configuration conf, String confName, Map configMap)
           
 Object getSelectorContext(Map objectModel, Parameters parameters)
          create an object representing a context for multiple select/when invocations
 boolean select(String expression, Object selectorContext)
          Evaluate select for a given expression
protected  void setUnsetFields(Calendar cal, Calendar default_cal)
          set fields which are not set by parsing the date attribute value
 
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
 

Field Detail

AFTER_ELEMENT

public static final String AFTER_ELEMENT
See Also:
Constant Field Values

BEFORE_ELEMENT

public static final String BEFORE_ELEMENT
See Also:
Constant Field Values

NAME_ATTR

public static final String NAME_ATTR
See Also:
Constant Field Values

DATE_ATTR

public static final String DATE_ATTR
See Also:
Constant Field Values

DATEFORMAT_ATTR

public static final String DATEFORMAT_ATTR
See Also:
Constant Field Values

LANGUAGE_ATTR

public static final String LANGUAGE_ATTR
See Also:
Constant Field Values

COUNTRY_ATTR

public static final String COUNTRY_ATTR
See Also:
Constant Field Values
Constructor Detail

DateSelector

public DateSelector()
Method Detail

configure

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

configure

protected void configure(Configuration conf,
                         String confName,
                         Map configMap)

setUnsetFields

protected void setUnsetFields(Calendar cal,
                              Calendar default_cal)
set fields which are not set by parsing the date attribute value

Parameters:
cal - Calendar parsed in
default_cal - Calendar object providing default value for unset fields of cal

getSelectorContext

public Object getSelectorContext(Map objectModel,
                                 Parameters parameters)
create an object representing a context for multiple select/when invocations

Specified by:
getSelectorContext in interface SwitchSelector
Specified by:
getSelectorContext in class AbstractSwitchSelector
Parameters:
objectModel - the objectModel of the pipeline processing
parameters - unused here
Returns:
Object which is an object of class DataSelectorContext

select

public boolean select(String expression,
                      Object selectorContext)
Evaluate select for a given expression

Specified by:
select in interface SwitchSelector
Specified by:
select in class AbstractSwitchSelector
Parameters:
expression - the expression to test against, as now expression should be a name defined as NAME_ATTR in the configuration section of this selector
selectorContext - is the SelectorContext set up by the getSelectorContext() method
Returns:
true if expression defining a name which yields true comparing the current date set in getSelectorContext, and the configured comparison, referenced by the expression name value.


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.