You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ga...@apache.org on 2006/12/02 21:45:59 UTC

svn commit: r481624 - in /incubator/roller/trunk/src/org/apache/roller/ui: core/tags/calendar/ rendering/pagers/

Author: gangolli
Date: Sat Dec  2 12:45:54 2006
New Revision: 481624

URL: http://svn.apache.org/viewvc?view=rev&rev=481624
Log:
Fixes for ROL-1145.  Don't link back in time beyond creation date of weblog (website).  Relies on creation date of weblog being set (non-null).  If it is null, at least limits stepping back beyond beginning of Java epoch (Jan 1, 1970 UTC).

Modified:
    incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
    incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
    incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
    incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
    incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java

Modified: incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java?view=diff&rev=481624&r1=481623&r2=481624
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java Sat Dec  2 12:45:54 2006
@@ -32,12 +32,20 @@
     public Date getDay();
     
     public Date getNextMonth();
+
+    public Date getPrevMonth();
     
     public String computePrevMonthUrl();
     
     public String computeTodayMonthUrl();
     
     public String computeNextMonthUrl();
+
+    /**
+     * Get the earliest month in which there could possibly be data.  For a weblog this
+     * is the beginning of the month containing the creation date.
+     */
+    public Date getInitialMonth();
     
     /**
      * Create URL for use on edit-weblog page, preserves the request

Modified: incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java?view=diff&rev=481624&r1=481623&r2=481624
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java Sat Dec  2 12:45:54 2006
@@ -183,9 +183,11 @@
             pw.print("<tr>");
             pw.print("<td colspan=\"7\" align=\"center\" "+
                     "class=\"hCalendarMonthYearRow"+mClassSuffix+"\">");
-            pw.print("<a href=\"" + model.computePrevMonthUrl()
-            + "\" title=\"" + resources.getMessage(mLocale, "calendar.prev")
-            + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
+            if (model.getPrevMonth().compareTo(model.getInitialMonth()) >= 0) {
+                pw.print("<a href=\"" + model.computePrevMonthUrl()
+                        + "\" title=\"" + resources.getMessage(mLocale, "calendar.prev")
+                        + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
+            }
             pw.print( formatTitle.format(day) );
             if (todayCal.getTime().compareTo(model.getNextMonth()) >= 0) {
                 pw.print(" <a href=\"" + model.computeNextMonthUrl()

Modified: incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java?view=diff&rev=481624&r1=481623&r2=481624
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java Sat Dec  2 12:45:54 2006
@@ -87,7 +87,6 @@
     
     
     protected void initDay(Date month) {
-        this.day = day;
         calendar = Calendar.getInstance(
                 weblog.getTimeZoneInstance(),
                 weblog.getLocaleInstance());
@@ -192,6 +191,13 @@
         nextCal.add( Calendar.MONTH, 1 );
         return getFirstDayOfMonth(nextCal).getTime();
     }
+
+    public Date getPrevMonth() {
+        Calendar prevCal = getCalendar();
+        prevCal.setTime( day );
+        prevCal.add( Calendar.MONTH, -1 );
+        return getFirstDayOfMonth(prevCal).getTime();
+    }
     
     protected Calendar getFirstDayOfMonth(Calendar cal) {
         int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
@@ -215,7 +221,14 @@
         // and strip off last two digits to get a month URL
         return nextMonth;
     }
-    
+
+    public Date getInitialMonth() {
+        Calendar cal = getCalendar();
+        // if there is no dateCreated value, default to beginning of epoch.
+        cal.setTime(weblog.getDateCreated() != null ? weblog.getDateCreated() : new Date(0));
+        return getFirstDayOfMonth(cal).getTime();
+    }
+
     public String computePrevMonthUrl() {
         // Create yyyyMMdd dates for prev month, prev month and today
         Calendar prevCal = getCalendar();

Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java?view=diff&rev=481624&r1=481623&r2=481624
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java Sat Dec  2 12:45:54 2006
@@ -94,6 +94,10 @@
         cal.set(Calendar.MINUTE, 59);
         cal.set(Calendar.SECOND, 59);
         prevDay = cal.getTime();
+        Date weblogInitialDate = weblog.getDateCreated() != null ? weblog.getDateCreated() : new Date(0);
+        if (DateUtil.getEndOfDay(prevDay,cal).before(weblogInitialDate)) {
+            prevDay = null;
+        }
     }
     
     

Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java?view=diff&rev=481624&r1=481623&r2=481624
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java Sat Dec  2 12:45:54 2006
@@ -29,9 +29,7 @@
 import org.apache.commons.collections.comparators.ReverseComparator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.roller.business.Roller;
 import org.apache.roller.business.RollerFactory;
-import org.apache.roller.business.WeblogManager;
 import org.apache.roller.pojos.WeblogEntryData;
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
@@ -88,6 +86,11 @@
         cal.setTime(month);
         cal.add(Calendar.MONTH, -1);
         prevMonth = cal.getTime();
+        Date endOfPrevMonth = DateUtil.getEndOfMonth(prevMonth,cal) ;
+        Date weblogInitialDate = weblog.getDateCreated() != null ? weblog.getDateCreated() : new Date(0);
+        if (endOfPrevMonth.before(weblogInitialDate)) {
+            prevMonth = null;
+        }
     }
     
     
@@ -97,14 +100,12 @@
         cal.setTime(date);
         cal.add(Calendar.DATE, 1);
         date = cal.getTime();
-        Date startDate = DateUtil.getStartOfMonth(date, cal);;
-        Date endDate = DateUtil.getEndOfMonth(date, cal);;
+        Date startDate = DateUtil.getStartOfMonth(date, cal);
+        Date endDate = DateUtil.getEndOfMonth(date, cal);
         
         if (entries == null) {
             entries = new TreeMap(new ReverseComparator());
             try {
-                Roller roller = RollerFactory.getRoller();
-                WeblogManager wmgr = roller.getWeblogManager();
                 Map mmap = RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
                         weblog,
                         startDate,



Re: svn commit: r481624 - in /incubator/roller/trunk/src/org/apache/roller/ui: core/tags/calendar/ rendering/pagers/

Posted by Allen Gilliland <al...@sun.com>.

Anil Gangolli wrote:
> 
> Good points.
> 
> It doesn't seem feasible to keep querying for the earliest blog publish 
> date, but an alternative might be to try to keep track of the earliest 
> entry publish date in a field in the website, and then use that for the 
> limit on going back.

I agree.  I don't like the idea of continually querying for the pubtime 
of the oldest entry, so keeping that stashed somewhere would be the best 
option.


> 
> An upgrade script would be needed to populate this, and we'd have to 
> update this field (depending on whether it has gotten earlier) each time 
> an entry is stored.  If we want to avoid issues where the entry that has 
> the earliest pub time is edited and moved forward (but the date recorded 
> at the website level then precedes this), we would need to store the id 
> of the (an) entry that has the earliest pub time as well and use this in 
> the update logic.

I agree about the upgrade script, but I am uncertain about how best to 
maintain the date to the oldest entry.  I agree that there is definitely 
a problem if someone publishes an entry that is somehow older than their 
previous oldest entry, then goes back and changes the date to something 
current.  In fact, I am pretty sure this happens from time to time when 
user fidget with the pubtime on the entry form and mess it up on accident.

As I think about it more, I am wondering if the case where someone post 
dates an entry to before their previous oldest post is even likely 
enough that we should try and deal with it.  I would imagine that in the 
very unlikely event that happens that it will almost certainly have been 
a mistake anyways, so may it's not worth trying to worry about.

I think the cleanest, fastest, easiest way may be to just 1) use an 
upgrade script to set the first entry date to whatever their current 
oldest entry is and then 2) for each new weblog just set it to whatever 
the date is for their first entry and leave it.  It seems like a waste 
to invest time trying to solve for a scenario which is never likely to 
happen on purpose.

-- Allen


> 
> Should we take this approach?
> 
> --a.
> 
> 
> 
> 
> ----- Original Message ----- From: "Allen Gilliland" 
> <al...@sun.com>
> To: <ro...@incubator.apache.org>
> Sent: Saturday, December 02, 2006 1:55 PM
> Subject: Re: svn commit: r481624 - in 
> /incubator/roller/trunk/src/org/apache/roller/ui: core/tags/calendar/ 
> rendering/pagers/
> 
> 
>> Anil,
>>
>> This looks like a good fix which is long overdue, but I am wondering 
>> if using the weblog.dateCreated attribute is the best option.  I may 
>> be wrong, but for some reason I remember us having a problem in the 
>> past with the dateCreated field being updated at some point(s) in the 
>> various upgrade processes from the early Roller days.  If that's the 
>> case then it may be unreliable to use that column for upgrading 
>> users.  We could probably work around that with a bit of upgrade logic 
>> which sets the weblog.dateCreated to the date of the oldest entry if 
>> the oldest entry is older than creation date.
>>
>> Also, if for some reason someone post dates an entry to before the 
>> date they created a weblog then that would be a problem as well.  It's 
>> pretty unlikely that would happen, but it's technically possible.
>>
>> Those issues may not be likely enough to happen to be worth worrying 
>> about, but I wanted to mention it.
>>
>> -- Allen
>>
>>
>> gangolli@apache.org wrote:
>>> Author: gangolli
>>> Date: Sat Dec  2 12:45:54 2006
>>> New Revision: 481624
>>>
>>> URL: http://svn.apache.org/viewvc?view=rev&rev=481624
>>> Log:
>>> Fixes for ROL-1145.  Don't link back in time beyond creation date of 
>>> weblog (website).  Relies on creation date of weblog being set 
>>> (non-null).  If it is null, at least limits stepping back beyond 
>>> beginning of Java epoch (Jan 1, 1970 UTC).
>>>
>>> Modified:
>>>
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java 
>>>
>>>
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java 
>>>
>>>
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java 
>>>
>>>
>>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java 
>>>
>>>
>>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java 
>>>
>>>
>>> Modified: 
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java 
>>>
>>> URL: 
>>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java?view=diff&rev=481624&r1=481623&r2=481624 
>>>
>>> ============================================================================== 
>>>
>>> ---  
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java 
>>> (original)
>>> +++ 
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java 
>>> Sat Dec  2 12:45:54 2006
>>> @@ -32,12 +32,20 @@
>>>      public Date getDay();
>>>      public Date getNextMonth();
>>> +
>>> +    public Date getPrevMonth();
>>>      public String computePrevMonthUrl();
>>>      public String computeTodayMonthUrl();
>>>      public String computeNextMonthUrl();
>>> +
>>> +    /**
>>> +     * Get the earliest month in which there could possibly be data. 
>>> For a weblog this
>>> +     * is the beginning of the month containing the creation date.
>>> +     */
>>> +    public Date getInitialMonth();
>>>      /**
>>>       * Create URL for use on edit-weblog page, preserves the request
>>>
>>> Modified: 
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java 
>>>
>>> URL: 
>>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java?view=diff&rev=481624&r1=481623&r2=481624 
>>>
>>> ============================================================================== 
>>>
>>> ---  
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java 
>>> (original)
>>> +++ 
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java 
>>> Sat Dec  2 12:45:54 2006
>>> @@ -183,9 +183,11 @@
>>>              pw.print("<tr>");
>>>              pw.print("<td colspan=\"7\" align=\"center\" "+
>>>                      
>>> "class=\"hCalendarMonthYearRow"+mClassSuffix+"\">");
>>> -            pw.print("<a href=\"" + model.computePrevMonthUrl()
>>> -            + "\" title=\"" + resources.getMessage(mLocale, 
>>> "calendar.prev")
>>> -            + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
>>> +            if 
>>> (model.getPrevMonth().compareTo(model.getInitialMonth())  >= 0) {
>>> +                pw.print("<a href=\"" + model.computePrevMonthUrl()
>>> +                        + "\" title=\"" + 
>>> resources.getMessage(mLocale, "calendar.prev")
>>> +                        + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
>>> +            }
>>>              pw.print( formatTitle.format(day) );
>>>              if (todayCal.getTime().compareTo(model.getNextMonth()) 
>>> >= 0) {
>>>                  pw.print(" <a href=\"" + model.computeNextMonthUrl()
>>>
>>> Modified: 
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java 
>>>
>>> URL: 
>>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java?view=diff&rev=481624&r1=481623&r2=481624 
>>>
>>> ============================================================================== 
>>>
>>> ---  
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java 
>>> (original)
>>> +++ 
>>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java 
>>> Sat Dec  2 12:45:54 2006
>>> @@ -87,7 +87,6 @@
>>>      protected void initDay(Date month) {
>>> -        this.day = day;
>>>          calendar = Calendar.getInstance(
>>>                  weblog.getTimeZoneInstance(),
>>>                  weblog.getLocaleInstance());
>>> @@ -192,6 +191,13 @@
>>>          nextCal.add( Calendar.MONTH, 1 );
>>>          return getFirstDayOfMonth(nextCal).getTime();
>>>      }
>>> +
>>> +    public Date getPrevMonth() {
>>> +        Calendar prevCal = getCalendar();
>>> +        prevCal.setTime( day );
>>> +        prevCal.add( Calendar.MONTH, -1 );
>>> +        return getFirstDayOfMonth(prevCal).getTime();
>>> +    }
>>>      protected Calendar getFirstDayOfMonth(Calendar cal) {
>>>          int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
>>> @@ -215,7 +221,14 @@
>>>          // and strip off last two digits to get a month URL
>>>          return nextMonth;
>>>      }
>>> -    +
>>> +    public Date getInitialMonth() {
>>> +        Calendar cal = getCalendar();
>>> +        // if there is no dateCreated value, default to beginning of 
>>> epoch.
>>> +        cal.setTime(weblog.getDateCreated() != null ? 
>>> weblog.getDateCreated() : new Date(0));
>>> +        return getFirstDayOfMonth(cal).getTime();
>>> +    }
>>> +
>>>      public String computePrevMonthUrl() {
>>>          // Create yyyyMMdd dates for prev month, prev month and today
>>>          Calendar prevCal = getCalendar();
>>>
>>> Modified: 
>>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java 
>>>
>>> URL: 
>>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java?view=diff&rev=481624&r1=481623&r2=481624 
>>>
>>> ============================================================================== 
>>>
>>> ---  
>>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java 
>>> (original)
>>> +++ 
>>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java 
>>> Sat Dec  2 12:45:54 2006
>>> @@ -94,6 +94,10 @@
>>>          cal.set(Calendar.MINUTE, 59);
>>>          cal.set(Calendar.SECOND, 59);
>>>          prevDay = cal.getTime();
>>> +        Date weblogInitialDate = weblog.getDateCreated() != null ? 
>>> weblog.getDateCreated() : new Date(0);
>>> +        if 
>>> (DateUtil.getEndOfDay(prevDay,cal).before(weblogInitialDate)) {
>>> +            prevDay = null;
>>> +        }
>>>      }
>>>      Modified: 
>>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java 
>>>
>>> URL: 
>>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java?view=diff&rev=481624&r1=481623&r2=481624 
>>>
>>> ============================================================================== 
>>>
>>> ---  
>>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java 
>>> (original)
>>> +++ 
>>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java 
>>> Sat Dec  2 12:45:54 2006
>>> @@ -29,9 +29,7 @@
>>>  import org.apache.commons.collections.comparators.ReverseComparator;
>>>  import org.apache.commons.logging.Log;
>>>  import org.apache.commons.logging.LogFactory;
>>> -import org.apache.roller.business.Roller;
>>>  import org.apache.roller.business.RollerFactory;
>>> -import org.apache.roller.business.WeblogManager;
>>>  import org.apache.roller.pojos.WeblogEntryData;
>>>  import org.apache.roller.pojos.WebsiteData;
>>>  import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
>>> @@ -88,6 +86,11 @@
>>>          cal.setTime(month);
>>>          cal.add(Calendar.MONTH, -1);
>>>          prevMonth = cal.getTime();
>>> +        Date endOfPrevMonth = DateUtil.getEndOfMonth(prevMonth,cal) ;
>>> +        Date weblogInitialDate = weblog.getDateCreated() != null ? 
>>> weblog.getDateCreated() : new Date(0);
>>> +        if (endOfPrevMonth.before(weblogInitialDate)) {
>>> +            prevMonth = null;
>>> +        }
>>>      }
>>>      @@ -97,14 +100,12 @@
>>>          cal.setTime(date);
>>>          cal.add(Calendar.DATE, 1);
>>>          date = cal.getTime();
>>> -        Date startDate = DateUtil.getStartOfMonth(date, cal);;
>>> -        Date endDate = DateUtil.getEndOfMonth(date, cal);;
>>> +        Date startDate = DateUtil.getStartOfMonth(date, cal);
>>> +        Date endDate = DateUtil.getEndOfMonth(date, cal);
>>>          if (entries == null) {
>>>              entries = new TreeMap(new ReverseComparator());
>>>              try {
>>> -                Roller roller = RollerFactory.getRoller();
>>> -                WeblogManager wmgr = roller.getWeblogManager();
>>>                  Map mmap = 
>>> RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
>>>                          weblog,
>>>                          startDate,
>>>
>>>
>>
> 

Re: svn commit: r481624 - in /incubator/roller/trunk/src/org/apache/roller/ui: core/tags/calendar/ rendering/pagers/

Posted by Anil Gangolli <an...@busybuddha.org>.
Good points.

It doesn't seem feasible to keep querying for the earliest blog publish 
date, but an alternative might be to try to keep track of the earliest entry 
publish date in a field in the website, and then use that for the limit on 
going back.

An upgrade script would be needed to populate this, and we'd have to update 
this field (depending on whether it has gotten earlier) each time an entry 
is stored.  If we want to avoid issues where the entry that has the earliest 
pub time is edited and moved forward (but the date recorded at the website 
level then precedes this), we would need to store the id of the (an) entry 
that has the earliest pub time as well and use this in the update logic.

Should we take this approach?

--a.




----- Original Message ----- 
From: "Allen Gilliland" <al...@sun.com>
To: <ro...@incubator.apache.org>
Sent: Saturday, December 02, 2006 1:55 PM
Subject: Re: svn commit: r481624 - in 
/incubator/roller/trunk/src/org/apache/roller/ui: core/tags/calendar/ 
rendering/pagers/


> Anil,
>
> This looks like a good fix which is long overdue, but I am wondering if 
> using the weblog.dateCreated attribute is the best option.  I may be 
> wrong, but for some reason I remember us having a problem in the past with 
> the dateCreated field being updated at some point(s) in the various 
> upgrade processes from the early Roller days.  If that's the case then it 
> may be unreliable to use that column for upgrading users.  We could 
> probably work around that with a bit of upgrade logic which sets the 
> weblog.dateCreated to the date of the oldest entry if the oldest entry is 
> older than creation date.
>
> Also, if for some reason someone post dates an entry to before the date 
> they created a weblog then that would be a problem as well.  It's pretty 
> unlikely that would happen, but it's technically possible.
>
> Those issues may not be likely enough to happen to be worth worrying 
> about, but I wanted to mention it.
>
> -- Allen
>
>
> gangolli@apache.org wrote:
>> Author: gangolli
>> Date: Sat Dec  2 12:45:54 2006
>> New Revision: 481624
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=481624
>> Log:
>> Fixes for ROL-1145.  Don't link back in time beyond creation date of 
>> weblog (website).  Relies on creation date of weblog being set 
>> (non-null).  If it is null, at least limits stepping back beyond 
>> beginning of Java epoch (Jan 1, 1970 UTC).
>>
>> Modified:
>> 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
>> 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
>> 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
>> 
>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
>> 
>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
>>
>> Modified: 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
>> URL: 
>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java?view=diff&rev=481624&r1=481623&r2=481624
>> ==============================================================================
>> ---  
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java 
>> (original)
>> +++ 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java 
>> Sat Dec  2 12:45:54 2006
>> @@ -32,12 +32,20 @@
>>      public Date getDay();
>>      public Date getNextMonth();
>> +
>> +    public Date getPrevMonth();
>>      public String computePrevMonthUrl();
>>      public String computeTodayMonthUrl();
>>      public String computeNextMonthUrl();
>> +
>> +    /**
>> +     * Get the earliest month in which there could possibly be data. 
>> For a weblog this
>> +     * is the beginning of the month containing the creation date.
>> +     */
>> +    public Date getInitialMonth();
>>      /**
>>       * Create URL for use on edit-weblog page, preserves the request
>>
>> Modified: 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
>> URL: 
>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java?view=diff&rev=481624&r1=481623&r2=481624
>> ==============================================================================
>> ---  
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java 
>> (original)
>> +++ 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java 
>> Sat Dec  2 12:45:54 2006
>> @@ -183,9 +183,11 @@
>>              pw.print("<tr>");
>>              pw.print("<td colspan=\"7\" align=\"center\" "+
>>                      "class=\"hCalendarMonthYearRow"+mClassSuffix+"\">");
>> -            pw.print("<a href=\"" + model.computePrevMonthUrl()
>> -            + "\" title=\"" + resources.getMessage(mLocale, 
>> "calendar.prev")
>> -            + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
>> +            if (model.getPrevMonth().compareTo(model.getInitialMonth()) 
>>  >= 0) {
>> +                pw.print("<a href=\"" + model.computePrevMonthUrl()
>> +                        + "\" title=\"" + resources.getMessage(mLocale, 
>> "calendar.prev")
>> +                        + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
>> +            }
>>              pw.print( formatTitle.format(day) );
>>              if (todayCal.getTime().compareTo(model.getNextMonth()) >= 0) 
>> {
>>                  pw.print(" <a href=\"" + model.computeNextMonthUrl()
>>
>> Modified: 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
>> URL: 
>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java?view=diff&rev=481624&r1=481623&r2=481624
>> ==============================================================================
>> ---  
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java 
>> (original)
>> +++ 
>> incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java 
>> Sat Dec  2 12:45:54 2006
>> @@ -87,7 +87,6 @@
>>      protected void initDay(Date month) {
>> -        this.day = day;
>>          calendar = Calendar.getInstance(
>>                  weblog.getTimeZoneInstance(),
>>                  weblog.getLocaleInstance());
>> @@ -192,6 +191,13 @@
>>          nextCal.add( Calendar.MONTH, 1 );
>>          return getFirstDayOfMonth(nextCal).getTime();
>>      }
>> +
>> +    public Date getPrevMonth() {
>> +        Calendar prevCal = getCalendar();
>> +        prevCal.setTime( day );
>> +        prevCal.add( Calendar.MONTH, -1 );
>> +        return getFirstDayOfMonth(prevCal).getTime();
>> +    }
>>      protected Calendar getFirstDayOfMonth(Calendar cal) {
>>          int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
>> @@ -215,7 +221,14 @@
>>          // and strip off last two digits to get a month URL
>>          return nextMonth;
>>      }
>> -    +
>> +    public Date getInitialMonth() {
>> +        Calendar cal = getCalendar();
>> +        // if there is no dateCreated value, default to beginning of 
>> epoch.
>> +        cal.setTime(weblog.getDateCreated() != null ? 
>> weblog.getDateCreated() : new Date(0));
>> +        return getFirstDayOfMonth(cal).getTime();
>> +    }
>> +
>>      public String computePrevMonthUrl() {
>>          // Create yyyyMMdd dates for prev month, prev month and today
>>          Calendar prevCal = getCalendar();
>>
>> Modified: 
>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
>> URL: 
>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java?view=diff&rev=481624&r1=481623&r2=481624
>> ==============================================================================
>> ---  
>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java 
>> (original)
>> +++ 
>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java 
>> Sat Dec  2 12:45:54 2006
>> @@ -94,6 +94,10 @@
>>          cal.set(Calendar.MINUTE, 59);
>>          cal.set(Calendar.SECOND, 59);
>>          prevDay = cal.getTime();
>> +        Date weblogInitialDate = weblog.getDateCreated() != null ? 
>> weblog.getDateCreated() : new Date(0);
>> +        if (DateUtil.getEndOfDay(prevDay,cal).before(weblogInitialDate)) 
>> {
>> +            prevDay = null;
>> +        }
>>      }
>>      Modified: 
>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
>> URL: 
>> http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java?view=diff&rev=481624&r1=481623&r2=481624
>> ==============================================================================
>> ---  
>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java 
>> (original)
>> +++ 
>> incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java 
>> Sat Dec  2 12:45:54 2006
>> @@ -29,9 +29,7 @@
>>  import org.apache.commons.collections.comparators.ReverseComparator;
>>  import org.apache.commons.logging.Log;
>>  import org.apache.commons.logging.LogFactory;
>> -import org.apache.roller.business.Roller;
>>  import org.apache.roller.business.RollerFactory;
>> -import org.apache.roller.business.WeblogManager;
>>  import org.apache.roller.pojos.WeblogEntryData;
>>  import org.apache.roller.pojos.WebsiteData;
>>  import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
>> @@ -88,6 +86,11 @@
>>          cal.setTime(month);
>>          cal.add(Calendar.MONTH, -1);
>>          prevMonth = cal.getTime();
>> +        Date endOfPrevMonth = DateUtil.getEndOfMonth(prevMonth,cal) ;
>> +        Date weblogInitialDate = weblog.getDateCreated() != null ? 
>> weblog.getDateCreated() : new Date(0);
>> +        if (endOfPrevMonth.before(weblogInitialDate)) {
>> +            prevMonth = null;
>> +        }
>>      }
>>      @@ -97,14 +100,12 @@
>>          cal.setTime(date);
>>          cal.add(Calendar.DATE, 1);
>>          date = cal.getTime();
>> -        Date startDate = DateUtil.getStartOfMonth(date, cal);;
>> -        Date endDate = DateUtil.getEndOfMonth(date, cal);;
>> +        Date startDate = DateUtil.getStartOfMonth(date, cal);
>> +        Date endDate = DateUtil.getEndOfMonth(date, cal);
>>          if (entries == null) {
>>              entries = new TreeMap(new ReverseComparator());
>>              try {
>> -                Roller roller = RollerFactory.getRoller();
>> -                WeblogManager wmgr = roller.getWeblogManager();
>>                  Map mmap = 
>> RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
>>                          weblog,
>>                          startDate,
>>
>>
> 


Re: svn commit: r481624 - in /incubator/roller/trunk/src/org/apache/roller/ui: core/tags/calendar/ rendering/pagers/

Posted by Allen Gilliland <al...@sun.com>.
Anil,

This looks like a good fix which is long overdue, but I am wondering if 
using the weblog.dateCreated attribute is the best option.  I may be 
wrong, but for some reason I remember us having a problem in the past 
with the dateCreated field being updated at some point(s) in the various 
upgrade processes from the early Roller days.  If that's the case then 
it may be unreliable to use that column for upgrading users.  We could 
probably work around that with a bit of upgrade logic which sets the 
weblog.dateCreated to the date of the oldest entry if the oldest entry 
is older than creation date.

Also, if for some reason someone post dates an entry to before the date 
they created a weblog then that would be a problem as well.  It's pretty 
unlikely that would happen, but it's technically possible.

Those issues may not be likely enough to happen to be worth worrying 
about, but I wanted to mention it.

-- Allen


gangolli@apache.org wrote:
> Author: gangolli
> Date: Sat Dec  2 12:45:54 2006
> New Revision: 481624
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=481624
> Log:
> Fixes for ROL-1145.  Don't link back in time beyond creation date of weblog (website).  Relies on creation date of weblog being set (non-null).  If it is null, at least limits stepping back beyond beginning of Java epoch (Jan 1, 1970 UTC).
> 
> Modified:
>     incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
>     incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
>     incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
>     incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
>     incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
> 
> Modified: incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
> URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java?view=diff&rev=481624&r1=481623&r2=481624
> ==============================================================================
> --- incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java (original)
> +++ incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java Sat Dec  2 12:45:54 2006
> @@ -32,12 +32,20 @@
>      public Date getDay();
>      
>      public Date getNextMonth();
> +
> +    public Date getPrevMonth();
>      
>      public String computePrevMonthUrl();
>      
>      public String computeTodayMonthUrl();
>      
>      public String computeNextMonthUrl();
> +
> +    /**
> +     * Get the earliest month in which there could possibly be data.  For a weblog this
> +     * is the beginning of the month containing the creation date.
> +     */
> +    public Date getInitialMonth();
>      
>      /**
>       * Create URL for use on edit-weblog page, preserves the request
> 
> Modified: incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
> URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java?view=diff&rev=481624&r1=481623&r2=481624
> ==============================================================================
> --- incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java (original)
> +++ incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java Sat Dec  2 12:45:54 2006
> @@ -183,9 +183,11 @@
>              pw.print("<tr>");
>              pw.print("<td colspan=\"7\" align=\"center\" "+
>                      "class=\"hCalendarMonthYearRow"+mClassSuffix+"\">");
> -            pw.print("<a href=\"" + model.computePrevMonthUrl()
> -            + "\" title=\"" + resources.getMessage(mLocale, "calendar.prev")
> -            + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
> +            if (model.getPrevMonth().compareTo(model.getInitialMonth()) >= 0) {
> +                pw.print("<a href=\"" + model.computePrevMonthUrl()
> +                        + "\" title=\"" + resources.getMessage(mLocale, "calendar.prev")
> +                        + "\" class=\"hCalendarNavBar\">&laquo;</a> ");
> +            }
>              pw.print( formatTitle.format(day) );
>              if (todayCal.getTime().compareTo(model.getNextMonth()) >= 0) {
>                  pw.print(" <a href=\"" + model.computeNextMonthUrl()
> 
> Modified: incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
> URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java?view=diff&rev=481624&r1=481623&r2=481624
> ==============================================================================
> --- incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java (original)
> +++ incubator/roller/trunk/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java Sat Dec  2 12:45:54 2006
> @@ -87,7 +87,6 @@
>      
>      
>      protected void initDay(Date month) {
> -        this.day = day;
>          calendar = Calendar.getInstance(
>                  weblog.getTimeZoneInstance(),
>                  weblog.getLocaleInstance());
> @@ -192,6 +191,13 @@
>          nextCal.add( Calendar.MONTH, 1 );
>          return getFirstDayOfMonth(nextCal).getTime();
>      }
> +
> +    public Date getPrevMonth() {
> +        Calendar prevCal = getCalendar();
> +        prevCal.setTime( day );
> +        prevCal.add( Calendar.MONTH, -1 );
> +        return getFirstDayOfMonth(prevCal).getTime();
> +    }
>      
>      protected Calendar getFirstDayOfMonth(Calendar cal) {
>          int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
> @@ -215,7 +221,14 @@
>          // and strip off last two digits to get a month URL
>          return nextMonth;
>      }
> -    
> +
> +    public Date getInitialMonth() {
> +        Calendar cal = getCalendar();
> +        // if there is no dateCreated value, default to beginning of epoch.
> +        cal.setTime(weblog.getDateCreated() != null ? weblog.getDateCreated() : new Date(0));
> +        return getFirstDayOfMonth(cal).getTime();
> +    }
> +
>      public String computePrevMonthUrl() {
>          // Create yyyyMMdd dates for prev month, prev month and today
>          Calendar prevCal = getCalendar();
> 
> Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
> URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java?view=diff&rev=481624&r1=481623&r2=481624
> ==============================================================================
> --- incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java (original)
> +++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java Sat Dec  2 12:45:54 2006
> @@ -94,6 +94,10 @@
>          cal.set(Calendar.MINUTE, 59);
>          cal.set(Calendar.SECOND, 59);
>          prevDay = cal.getTime();
> +        Date weblogInitialDate = weblog.getDateCreated() != null ? weblog.getDateCreated() : new Date(0);
> +        if (DateUtil.getEndOfDay(prevDay,cal).before(weblogInitialDate)) {
> +            prevDay = null;
> +        }
>      }
>      
>      
> 
> Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
> URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java?view=diff&rev=481624&r1=481623&r2=481624
> ==============================================================================
> --- incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java (original)
> +++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java Sat Dec  2 12:45:54 2006
> @@ -29,9 +29,7 @@
>  import org.apache.commons.collections.comparators.ReverseComparator;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
> -import org.apache.roller.business.Roller;
>  import org.apache.roller.business.RollerFactory;
> -import org.apache.roller.business.WeblogManager;
>  import org.apache.roller.pojos.WeblogEntryData;
>  import org.apache.roller.pojos.WebsiteData;
>  import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
> @@ -88,6 +86,11 @@
>          cal.setTime(month);
>          cal.add(Calendar.MONTH, -1);
>          prevMonth = cal.getTime();
> +        Date endOfPrevMonth = DateUtil.getEndOfMonth(prevMonth,cal) ;
> +        Date weblogInitialDate = weblog.getDateCreated() != null ? weblog.getDateCreated() : new Date(0);
> +        if (endOfPrevMonth.before(weblogInitialDate)) {
> +            prevMonth = null;
> +        }
>      }
>      
>      
> @@ -97,14 +100,12 @@
>          cal.setTime(date);
>          cal.add(Calendar.DATE, 1);
>          date = cal.getTime();
> -        Date startDate = DateUtil.getStartOfMonth(date, cal);;
> -        Date endDate = DateUtil.getEndOfMonth(date, cal);;
> +        Date startDate = DateUtil.getStartOfMonth(date, cal);
> +        Date endDate = DateUtil.getEndOfMonth(date, cal);
>          
>          if (entries == null) {
>              entries = new TreeMap(new ReverseComparator());
>              try {
> -                Roller roller = RollerFactory.getRoller();
> -                WeblogManager wmgr = roller.getWeblogManager();
>                  Map mmap = RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
>                          weblog,
>                          startDate,
> 
>