org.apache.cocoon.optional.pipeline.components.sax.calendar
Class CalendarGenerator

java.lang.Object
  extended by org.apache.cocoon.pipeline.component.AbstractPipelineComponent
      extended by org.apache.cocoon.sax.AbstractSAXPipelineComponent
          extended by org.apache.cocoon.sax.AbstractSAXProducer
              extended by org.apache.cocoon.sax.AbstractSAXGenerator
                  extended by org.apache.cocoon.optional.pipeline.components.sax.calendar.CalendarGenerator
All Implemented Interfaces:
CachingPipelineComponent, PipelineComponent, Producer, Starter, SAXPipelineComponent, SAXProducer

public class CalendarGenerator
extends AbstractSAXGenerator
implements CachingPipelineComponent

Generates an XML document representing a calendar for a given month and year.

Note for c3: Since this is a migration code the source is ATM only really usable if you call setConfiguration(final Map configuration) with your custom settings since it assumes to be invoked from within a sitemap.

Here is a sample output:

 <calendar:calendar xmlns:calendar="http://apache.org/cocoon/calendar/1.0"
     year="2004" month="January" prevMonth="12" prevYear="2003"
     nextMonth="02" nextYear="2004">
   <calendar:week number="1">
     <calendar:day number="1" weekday="THURSDAY" date="January 1, 2004"/>
     <calendar:day number="2" weekday="FRIDAY" date="January 2, 2004"/>
     <calendar:day number="3" weekday="SATURDAY" date="January 3, 2004"/>
     <calendar:day number="4" weekday="SUNDAY" date="January 4, 2004"/>
   </calendar:week>
   ...
 </calendar:calendar>
 

The src parameter is ignored.

Configuration options:

month (optional)
Sets the month for the calendar (January is 1). Default is the current month.
year (optional)
Sets the year for the calendar. Default is the current year.
dateFormat (optional)
Sets the format for the date attribute of each node, as described in java.text.SimpleDateFormat. If unset, the default format for the current locale will be used.
lang (optional)
Sets the ISO language code for determining the locale.
country (optional)
Sets the ISO country code for determining the locale.
padWeeks (optional)
If set to true, full weeks will be generated by adding days from the end of the previous month and the beginning of the following month.


Field Summary
protected  org.xml.sax.helpers.AttributesImpl attributes
          Convenience object, so we don't need to create an AttributesImpl for every element.
protected  Parameters cacheKeyParList
          The cache key needs to be generated for the configuration of this generator, so storing the parameters for generateKey().
protected static String CALENDAR_NODE_NAME
          Node and attribute names
protected static String DATE_ATTR_NAME
           
protected  DateFormat dateFormatter
          The format for dates
protected static String DAY_NODE_NAME
           
protected  Locale locale
          The current locale
protected  int month
          The month to generate the calendar for
protected static String MONTH_ATTR_NAME
           
protected  DateFormat monthFormatter
          The format for month names
protected static DecimalFormat monthNumberFormatter
          Formatter for month number
protected static String NEXT_MONTH_ATTR_NAME
           
protected static String NEXT_YEAR_ATTR_NAME
           
protected static String NUMBER_ATTR_NAME
           
protected  boolean padWeeks
          Do we need to pad out the first and last weeks?
protected static String PREFIX
          The namespace prefix for this namespace.
protected static String PREV_MONTH_ATTR_NAME
           
protected static String PREV_YEAR_ATTR_NAME
           
protected static String URI
          The URI of the namespace of this generator.
protected static String WEEK_NODE_NAME
           
protected static String WEEKDAY_ATTR_NAME
           
protected  String[] weekdays
           
protected  int year
          The year to generate the calendar for
protected static String YEAR_ATTR_NAME
           
 
Constructor Summary
CalendarGenerator()
           
 
Method Summary
protected  void addContent(Calendar date, Locale locale)
          Add content to a <day> element.
 CacheKey constructCacheKey()
           
 void execute()
          Generate XML data.
 void recycle()
          Recycle resources
 void setConfiguration(Map<String,? extends Object> configuration)
          Set the request parameters.
 
Methods inherited from class org.apache.cocoon.sax.AbstractSAXProducer
getSAXConsumer, setConsumer, setSAXConsumer, toString
 
Methods inherited from class org.apache.cocoon.pipeline.component.AbstractPipelineComponent
finish, setup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.pipeline.component.PipelineComponent
finish, setup
 

Field Detail

URI

protected static final String URI
The URI of the namespace of this generator.

See Also:
Constant Field Values

PREFIX

protected static final String PREFIX
The namespace prefix for this namespace.

See Also:
Constant Field Values

CALENDAR_NODE_NAME

protected static final String CALENDAR_NODE_NAME
Node and attribute names

See Also:
Constant Field Values

WEEK_NODE_NAME

protected static final String WEEK_NODE_NAME
See Also:
Constant Field Values

DAY_NODE_NAME

protected static final String DAY_NODE_NAME
See Also:
Constant Field Values

MONTH_ATTR_NAME

protected static final String MONTH_ATTR_NAME
See Also:
Constant Field Values

YEAR_ATTR_NAME

protected static final String YEAR_ATTR_NAME
See Also:
Constant Field Values

DATE_ATTR_NAME

protected static final String DATE_ATTR_NAME
See Also:
Constant Field Values

NUMBER_ATTR_NAME

protected static final String NUMBER_ATTR_NAME
See Also:
Constant Field Values

WEEKDAY_ATTR_NAME

protected static final String WEEKDAY_ATTR_NAME
See Also:
Constant Field Values

PREV_MONTH_ATTR_NAME

protected static final String PREV_MONTH_ATTR_NAME
See Also:
Constant Field Values

PREV_YEAR_ATTR_NAME

protected static final String PREV_YEAR_ATTR_NAME
See Also:
Constant Field Values

NEXT_MONTH_ATTR_NAME

protected static final String NEXT_MONTH_ATTR_NAME
See Also:
Constant Field Values

NEXT_YEAR_ATTR_NAME

protected static final String NEXT_YEAR_ATTR_NAME
See Also:
Constant Field Values

monthNumberFormatter

protected static final DecimalFormat monthNumberFormatter
Formatter for month number


attributes

protected org.xml.sax.helpers.AttributesImpl attributes
Convenience object, so we don't need to create an AttributesImpl for every element.


cacheKeyParList

protected Parameters cacheKeyParList
The cache key needs to be generated for the configuration of this generator, so storing the parameters for generateKey().


year

protected int year
The year to generate the calendar for


month

protected int month
The month to generate the calendar for


dateFormatter

protected DateFormat dateFormatter
The format for dates


monthFormatter

protected DateFormat monthFormatter
The format for month names


locale

protected Locale locale
The current locale


padWeeks

protected boolean padWeeks
Do we need to pad out the first and last weeks?


weekdays

protected String[] weekdays
Constructor Detail

CalendarGenerator

public CalendarGenerator()
Method Detail

setConfiguration

public void setConfiguration(Map<String,? extends Object> configuration)
Set the request parameters. Must be called before the generate method.

Specified by:
setConfiguration in interface PipelineComponent
Overrides:
setConfiguration in class AbstractPipelineComponent
Parameters:
resolver - the SourceResolver object
objectModel - a Map containing model object
src - the source URI (ignored)
par - configuration parameters

constructCacheKey

public CacheKey constructCacheKey()
Specified by:
constructCacheKey in interface CachingPipelineComponent

execute

public void execute()
             throws ProcessingException
Generate XML data.

Specified by:
execute in interface Starter
Throws:
SAXException - if an error occurs while outputting the document
ProcessingException

addContent

protected void addContent(Calendar date,
                          Locale locale)
                   throws SAXException
Add content to a <day> element. This method is intended to be overridden by subclasses that want to add content to one or more days of the calendar.

Parameters:
date - The date corresponding to the current element.
locale - The current locale.
Throws:
SAXException - if an error occurs while outputting the document

recycle

public void recycle()
Recycle resources

See Also:
for traditional background history. Keeping it for handyniess


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.