You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by he...@apache.org on 2005/09/18 23:00:20 UTC

svn commit: r289973 - /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CalendarGenerator.java

Author: hepabolu
Date: Sun Sep 18 14:00:13 2005
New Revision: 289973

URL: http://svn.apache.org/viewcvs?rev=289973&view=rev
Log:
Updated CalendardGenerator to include day_of_week info

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CalendarGenerator.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CalendarGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CalendarGenerator.java?rev=289973&r1=289972&r2=289973&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CalendarGenerator.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CalendarGenerator.java Sun Sep 18 14:00:13 2005
@@ -55,10 +55,10 @@
  *     year="2004" month="January" prevMonth="12" prevYear="2003"
  *     nextMonth="02" nextYear="2004">
  *   <calendar:week number="1">
- *     <calendar:day number="1" date="January 1, 2004"/>
- *     <calendar:day number="2" date="January 2, 2004"/>
- *     <calendar:day number="3" date="January 3, 2004"/>
- *     <calendar:day number="4" date="January 4, 2004"/>
+ *     <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>
@@ -106,6 +106,7 @@
     protected static final String YEAR_ATTR_NAME       = "year";
     protected static final String DATE_ATTR_NAME       = "date";
     protected static final String NUMBER_ATTR_NAME     = "number";
+	protected static final String WEEKDAY_ATTR_NAME    = "weekday";
     protected static final String PREV_MONTH_ATTR_NAME = "prevMonth";
     protected static final String PREV_YEAR_ATTR_NAME  = "prevYear";
     protected static final String NEXT_MONTH_ATTR_NAME = "nextMonth";
@@ -141,6 +142,16 @@
     /** Do we need to pad out the first and last weeks? */
     protected boolean padWeeks;
     
+	/* Add the day of the week 
+	 * 
+	 * since SUNDAY=1, we start with a dummy
+	 * entry. 
+	 */
+	protected String weekdays[] = { "",
+			"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", 
+			"Friday", "Saturday"
+	};
+	
     /**
      * Set the request parameters. Must be called before the generate method.
      *
@@ -241,6 +252,8 @@
                     attributes.clear();
                     attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, "CDATA",
                             String.valueOf(previous.get(Calendar.DAY_OF_MONTH)));
+					attributes.addAttribute("", WEEKDAY_ATTR_NAME, WEEKDAY_ATTR_NAME, "CDATA",
+							weekdays[previous.get(Calendar.DAY_OF_WEEK)]);
                     attributes.addAttribute("", DATE_ATTR_NAME, DATE_ATTR_NAME, "CDATA",
                             dateFormatter.format(previous.getTime()));
                     this.contentHandler.startElement(URI, DAY_NODE_NAME,
@@ -263,6 +276,8 @@
             attributes.clear();
             attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, "CDATA",
                     String.valueOf(start.get(Calendar.DAY_OF_MONTH)));
+			attributes.addAttribute("", WEEKDAY_ATTR_NAME, WEEKDAY_ATTR_NAME, "CDATA",
+					weekdays[start.get(Calendar.DAY_OF_WEEK)]);
             attributes.addAttribute("", DATE_ATTR_NAME, DATE_ATTR_NAME, "CDATA",
                     dateFormatter.format(start.getTime()));
             this.contentHandler.startElement(URI, DAY_NODE_NAME,
@@ -283,6 +298,8 @@
                 attributes.clear();
                 attributes.addAttribute("", NUMBER_ATTR_NAME, NUMBER_ATTR_NAME, "CDATA",
                         String.valueOf(end.get(Calendar.DAY_OF_MONTH)));
+				attributes.addAttribute("", WEEKDAY_ATTR_NAME, WEEKDAY_ATTR_NAME, "CDATA",
+						weekdays[end.get(Calendar.DAY_OF_WEEK)]);
                 attributes.addAttribute("", DATE_ATTR_NAME, DATE_ATTR_NAME, "CDATA",
                         dateFormatter.format(end.getTime()));
                 this.contentHandler.startElement(URI, DAY_NODE_NAME,



Re: svn commit: r289973 - /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CalendarGenerator.java

Posted by hepabolu <he...@gmail.com>.
Ugo Cei wrote:
> Il giorno 18/set/05, alle 23:00, hepabolu@apache.org ha scritto:
> 
>> +    protected String weekdays[] = { "",
>> +            "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
>> +            "Friday", "Saturday"
>> +    };
> 
> 
> Since the CalendarGenerator strives to be localizable as far as 
> possible, wouldn't it be better to use Java I18N features for outputting 
> localized weekday names instead of this?
> 
>     Ugo
> 
True, I've thought about this, but I intended the weekday attribute to 
be used for comparisons like "is this a weekday or a weekend day". In 
that case you don't want to depend on the current locale. You cannot 
depend on the order in the list either, since the first day in the week 
list is the first day of the week for that particular locale.

I could of course put in the ordinal (i.e. Sunday = 1), but that means 
you always need extra info to figure out what is what, i.e. context that 
you don't have once the calendar is generated.

I18n localizations can still be done using the i18n transformer with 
these names as keys.

WDYT?

Bye, Helma


Re: svn commit: r289973 - /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/CalendarGenerator.java

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 18/set/05, alle 23:00, hepabolu@apache.org ha scritto:

> +	protected String weekdays[] = { "",
> +			"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
> +			"Friday", "Saturday"
> +	};

Since the CalendarGenerator strives to be localizable as far as 
possible, wouldn't it be better to use Java I18N features for 
outputting localized weekday names instead of this?

	Ugo

-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/