ugo         2004/04/10 09:06:02

  Modified:    src/java/org/apache/cocoon/generation CalendarGenerator.java
  Log:
  Added addContent method to allow subclasses to add content to day nodes.
Fixed small bug.
  
  Revision  Changes    Path
  1.5       +34 -9     
cocoon-2.1/src/java/org/apache/cocoon/generation/CalendarGenerator.java
  
  Index: CalendarGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/CalendarGenerator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CalendarGenerator.java    9 Apr 2004 07:45:43 -0000       1.4
  +++ CalendarGenerator.java    10 Apr 2004 16:06:02 -0000      1.5
  @@ -52,21 +52,21 @@
    * </calendar:calendar>
    * </pre>
    * <p>
  - * The <i>src</i> parameter must be in the form "yyyy/mm" where "2004/01" 
stands
  - * for January, 2004.
  + * The <i>src</i> parameter is ignored.
    * </p>
    * <p>
    *  <b>Configuration options:</b>
    *  <dl>
  + *   <dt> <i>month</i> (optional)
  + *   <dd> Sets the month for the calendar (January is 1). Default is the 
current month.
  + *   <dt> <i>year</i> (optional)
  + *   <dd> Sets the year for the calendar. Default is the current year.
    *   <dt> <i>dateFormat</i> (optional)
    *   <dd> 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.
  - *  </dl>
    *   <dt> <i>lang</i> (optional)
    *   <dd> Sets the ISO language code for determining the locale.
  - *  </dl>
  - *  </dl>
    *   <dt> <i>country</i> (optional)
    *   <dd> Sets the ISO country code for determining the locale.
    *  </dl>
  @@ -120,7 +120,7 @@
        *
        * @param resolver     the SourceResolver object
        * @param objectModel  a <code>Map</code> containing model object
  -     * @param src          the year and month in the form "yyyy/mm"
  +     * @param src          the source URI (ignored)
        * @param par          configuration parameters
        */
       public void setup(SourceResolver resolver, Map objectModel, String src, 
Parameters par)
  @@ -169,7 +169,7 @@
        *
        * @throws  SAXException if an error occurs while outputting the document
        */
  -    public void generate() throws SAXException {
  +    public void generate() throws SAXException, ProcessingException {
           Calendar start = Calendar.getInstance(TimeZone.getTimeZone("UTC"), 
locale);
           start.clear();
           start.set(Calendar.YEAR, this.year);
  @@ -187,7 +187,7 @@
           this.contentHandler.startElement(URI, CALENDAR_NODE_NAME,
                   PREFIX + ':' + CALENDAR_NODE_NAME, attributes);
           int weekNo = start.get(Calendar.WEEK_OF_MONTH);
  -        if (start.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
  +        if (start.get(Calendar.DAY_OF_WEEK) != start.getFirstDayOfWeek()) {
               attributes.clear();
               attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, 
"CDATA", String.valueOf(weekNo));
               this.contentHandler.startElement(URI, WEEK_NODE_NAME,
  @@ -208,6 +208,7 @@
                       dateFormatter.format(start.getTime()));
               this.contentHandler.startElement(URI, DAY_NODE_NAME,
                       PREFIX + ':' + DAY_NODE_NAME, attributes);
  +            addContent(start, locale);
               this.contentHandler.endElement(URI, DAY_NODE_NAME,
                       PREFIX + ':' + DAY_NODE_NAME);
               start.add(Calendar.DAY_OF_MONTH, 1);
  @@ -224,6 +225,16 @@
           this.contentHandler.endDocument();
       }
       
  +    /**
  +     * Add content to a &lt;day&gt; element. This method is intended to be 
overridden
  +     * by subclasses that want to add content to one or more days of the 
calendar.
  +     * 
  +     * @param date   The date corresponding to the current element.
  +     * @param locale The current locale.
  +     * @throws SAXException if an error occurs while outputting the document
  +     */
  +    protected void addContent(Calendar date, Locale locale) throws 
SAXException {}
  +
       /* (non-Javadoc)
        * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
        */
  @@ -242,4 +253,18 @@
       public SourceValidity getValidity() {
           return NOPValidity.SHARED_INSTANCE;
       }
  +    
  +    /**
  +     * Recycle resources
  +     * @see org.apache.avalon.excalibur.pool.Recyclable.recycle()
  +     */
  +    public void recycle() {
  +        this.cacheKeyParList = null;
  +        this.attributes = null;
  +        this.dateFormatter = null;
  +        this.monthFormatter = null;
  +        this.locale = null;
  +        super.recycle();
  +    }
  +
   }
  
  
  

Reply via email to