ugo         2004/04/09 00:45:43

  Modified:    src/java/org/apache/cocoon/generation CalendarGenerator.java
               src/webapp/stylesheets/system calendar2html.xslt
  Log:
  Determine first day of week from locale, don't assume it's always Monday.
  
  Revision  Changes    Path
  1.4       +20 -14    
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CalendarGenerator.java    8 Apr 2004 20:15:20 -0000       1.3
  +++ CalendarGenerator.java    9 Apr 2004 07:45:43 -0000       1.4
  @@ -112,6 +112,9 @@
       /** The format for month names */
       DateFormat monthFormatter;
       
  +    /** The current locale */
  +    Locale locale;
  +    
       /**
        * Set the request parameters. Must be called before the generate method.
        *
  @@ -126,17 +129,10 @@
           
           this.cacheKeyParList = new ArrayList();
           this.cacheKeyParList.add(src);
  -        
  -        Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
  -        this.year = par.getParameterAsInteger("year", 
now.get(Calendar.YEAR));
  -        this.cacheKeyParList.add(String.valueOf(this.year));
  -        this.month = par.getParameterAsInteger("month", 
now.get(Calendar.MONTH) + 1) - 1;
  -        this.cacheKeyParList.add(String.valueOf(this.month));
  -        
  -        String dateFormatString = par.getParameter("dateFormat", null);
  -        this.cacheKeyParList.add(dateFormatString);
  +
  +        // Determine the locale
           String langString = par.getParameter("lang", null);
  -        Locale locale = Locale.getDefault();
  +        locale = Locale.getDefault();
           if (langString != null) {
               this.cacheKeyParList.add(langString);
               String countryString = par.getParameter("country", null);
  @@ -148,6 +144,16 @@
               }
               
           }
  +        
  +        // Determine year and month. Default is current year and month.
  +        Calendar now = Calendar.getInstance(locale);
  +        this.year = par.getParameterAsInteger("year", 
now.get(Calendar.YEAR));
  +        this.cacheKeyParList.add(String.valueOf(this.year));
  +        this.month = par.getParameterAsInteger("month", 
now.get(Calendar.MONTH) + 1) - 1;
  +        this.cacheKeyParList.add(String.valueOf(this.month));
  +        
  +        String dateFormatString = par.getParameter("dateFormat", null);
  +        this.cacheKeyParList.add(dateFormatString);
           if (dateFormatString != null) {
               this.dateFormatter = new SimpleDateFormat(dateFormatString, 
locale);
           } else {
  @@ -164,7 +170,7 @@
        * @throws  SAXException if an error occurs while outputting the document
        */
       public void generate() throws SAXException {
  -        Calendar start = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
  +        Calendar start = Calendar.getInstance(TimeZone.getTimeZone("UTC"), 
locale);
           start.clear();
           start.set(Calendar.YEAR, this.year);
           start.set(Calendar.MONTH, this.month);
  @@ -188,7 +194,7 @@
                       PREFIX + ':' + WEEK_NODE_NAME, attributes);
           }
           while (start.before(end)) {
  -            if (start.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
  +            if (start.get(Calendar.DAY_OF_WEEK) == 
start.getFirstDayOfWeek()) {
                   weekNo = start.get(Calendar.WEEK_OF_MONTH);
                   attributes.clear();
                   attributes.addAttribute("", NUMBER_ATTR_NAME, 
NUMBER_ATTR_NAME, "CDATA", String.valueOf(weekNo));
  @@ -205,7 +211,7 @@
               this.contentHandler.endElement(URI, DAY_NODE_NAME,
                       PREFIX + ':' + DAY_NODE_NAME);
               start.add(Calendar.DAY_OF_MONTH, 1);
  -            if (start.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
  +            if (start.get(Calendar.DAY_OF_WEEK) == start.getFirstDayOfWeek()
                       || ! start.before(end)) {
                   this.contentHandler.endElement(URI, WEEK_NODE_NAME,
                           PREFIX + ':' + WEEK_NODE_NAME);
  
  
  
  1.2       +8 -8      
cocoon-2.1/src/webapp/stylesheets/system/calendar2html.xslt
  
  Index: calendar2html.xslt
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/webapp/stylesheets/system/calendar2html.xslt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- calendar2html.xslt        9 Apr 2004 07:23:45 -0000       1.1
  +++ calendar2html.xslt        9 Apr 2004 07:45:43 -0000       1.2
  @@ -136,13 +136,13 @@
           </caption>
           <thead>
             <tr>
  -            <th class="mon">Monday</th>
  -            <th class="tue">Tuesday</th>
  -            <th class="wed">Wednesday</th>
  -            <th class="thu">Thursday</th>
  -            <th class="fri">Friday</th>
  -            <th class="sat">Saturday</th>
  -            <th class="sun">Sunday</th>
  +            <th>Sunday</th>
  +            <th>Monday</th>
  +            <th>Tuesday</th>
  +            <th>Wednesday</th>
  +            <th>Thursday</th>
  +            <th>Friday</th>
  +            <th>Saturday</th>
             </tr>
           </thead>
           <tbody>
  
  
  

Reply via email to