org.apache.cocoon.generation
Class CalendarGenerator

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.generation.AbstractGenerator
              extended byorg.apache.cocoon.generation.ServiceableGenerator
                  extended byorg.apache.cocoon.generation.CalendarGenerator
All Implemented Interfaces:
org.apache.cocoon.caching.CacheableProcessingComponent, Disposable, org.apache.cocoon.generation.Generator, Poolable, Recyclable, Serviceable, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.xml.XMLProducer

public class CalendarGenerator
extends org.apache.cocoon.generation.ServiceableGenerator
implements org.apache.cocoon.caching.CacheableProcessingComponent

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

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.

Version:
$Id: CalendarGenerator.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  AttributesImpl attributes
          Convenience object, so we don't need to create an AttributesImpl for every element.
protected  List 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
           
 
Fields inherited from class org.apache.cocoon.generation.ServiceableGenerator
manager
 
Fields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, source
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.generation.Generator
ROLE
 
Constructor Summary
CalendarGenerator()
           
 
Method Summary
protected  void addContent(Calendar date, Locale locale)
          Add content to a <day> element.
 void generate()
          Generate XML data.
 Serializable getKey()
           
 SourceValidity getValidity()
           
 void recycle()
          Recycle resources
 void setup(org.apache.cocoon.environment.SourceResolver resolver, Map objectModel, String src, Parameters par)
          Set the request parameters.
 
Methods inherited from class org.apache.cocoon.generation.ServiceableGenerator
dispose, service
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
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.xml.XMLProducer
setConsumer
 

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 AttributesImpl attributes
Convenience object, so we don't need to create an AttributesImpl for every element.


cacheKeyParList

protected List 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

setup

public void setup(org.apache.cocoon.environment.SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws org.apache.cocoon.ProcessingException,
                  SAXException,
                  IOException
Set the request parameters. Must be called before the generate method.

Specified by:
setup in interface org.apache.cocoon.sitemap.SitemapModelComponent
Parameters:
resolver - the SourceResolver object
objectModel - a Map containing model object
src - the source URI (ignored)
par - configuration parameters
Throws:
org.apache.cocoon.ProcessingException
SAXException
IOException

generate

public void generate()
              throws SAXException,
                     org.apache.cocoon.ProcessingException
Generate XML data.

Specified by:
generate in interface org.apache.cocoon.generation.Generator
Throws:
SAXException - if an error occurs while outputting the document
org.apache.cocoon.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

getKey

public Serializable getKey()
Specified by:
getKey in interface org.apache.cocoon.caching.CacheableProcessingComponent
See Also:
CacheableProcessingComponent.getKey()

getValidity

public SourceValidity getValidity()
Specified by:
getValidity in interface org.apache.cocoon.caching.CacheableProcessingComponent
See Also:
CacheableProcessingComponent.getValidity()

recycle

public void recycle()
Recycle resources

Specified by:
recycle in interface Recyclable
See Also:
Recyclable.recycle()


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.