A common problem with applications which allow paging with a calendar
is not having anyway to terminate the paging. I have seen this with
my own roller installation with bot's indexing page after page going
back to the dawn of history.
Attached is a patch for calendar paging which will remove the previous
month link if there are no more weblog entries going back in time.
This patch was generated against the roller 3.1 RC7 source.
Regards,
Glenn
diff -ur
apache-roller-src-3.1.orig/src/org/apache/roller/business/WeblogManager.java
apache-roller-src-3.1/src/org/apache/roller/business/WeblogManager.java
---
apache-roller-src-3.1.orig/src/org/apache/roller/business/WeblogManager.java
2007-03-22 22:04:51.000000000 -0500
+++ apache-roller-src-3.1/src/org/apache/roller/business/WeblogManager.java
2007-04-17 20:31:09.000000000 -0500
@@ -210,11 +210,23 @@
*/
public List getWeblogEntriesPinnedToMain(Integer max) throws
RollerException;
+ /** Get time of first update for a weblog specified by username */
+ public Date getWeblogFirstPublishTime(WebsiteData website) throws
RollerException;
+
/** Get time of last update for a weblog specified by username */
public Date getWeblogLastPublishTime(WebsiteData website) throws
RollerException;
-
+
+ /**
+ * Returns first pubTime, optionally restricted by category.
+ * @param handle Handle of website or null for all users
+ * @param catName Category name of posts or null for all categories
+ * @return Date Of last publish time
+ */
+ public Date getWeblogFirstPublishTime(WebsiteData website, String catName )
+ throws RollerException;
+
/**
- * Gets returns most recent pubTime, optionally restricted by category.
+ * Returns most recent pubTime, optionally restricted by category.
* @param handle Handle of website or null for all users
* @param catName Category name of posts or null for all categories
* @return Date Of last publish time
diff -ur
apache-roller-src-3.1.orig/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
apache-roller-src-3.1/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
---
apache-roller-src-3.1.orig/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
2007-03-22 22:05:01.000000000 -0500
+++
apache-roller-src-3.1/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
2007-04-17 19:48:25.000000000 -0500
@@ -584,7 +584,46 @@
throw new RollerException(e);
}
}
-
+
+ public Date getWeblogFirstPublishTime(WebsiteData website, String catName)
+ throws RollerException {
+ WeblogCategoryData cat = null;
+
+ if (catName != null && website != null) {
+ cat = getWeblogCategoryByPath(website, null, catName);
+ if (cat == null) catName = null;
+ }
+ if (catName != null && catName.trim().equals("/")) {
+ catName = null;
+ }
+
+ try {
+ Session session =
((HibernatePersistenceStrategy)this.strategy).getSession();
+ Criteria criteria = session.createCriteria(WeblogEntryData.class);
+ criteria.add(Expression.eq("status", WeblogEntryData.PUBLISHED));
+ criteria.add(Expression.le("pubTime", new Date()));
+
+ if (website != null) {
+ criteria.add(Expression.eq("website", website));
+ }
+
+ if ( cat != null ) {
+ criteria.add(Expression.eq("category", cat));
+ }
+
+ criteria.addOrder(Order.asc("pubTime"));
+ criteria.setMaxResults(1);
+ List list = criteria.list();
+ if (list.size() > 0) {
+ return ((WeblogEntryData)list.get(0)).getPubTime();
+ } else {
+ return null;
+ }
+ } catch (HibernateException e) {
+ throw new RollerException(e);
+ }
+ }
+
public List getWeblogEntries(WeblogCategoryData cat, boolean subcats)
throws RollerException {
try {
@@ -1060,7 +1099,16 @@
throws RollerException {
return getWeblogLastPublishTime(website, null);
}
-
+
+ /**
+ * Gets the Date of the first Entry publish time
+ * for all WeblogEntries
+ */
+ public Date getWeblogFirstPublishTime(WebsiteData website)
+ throws RollerException {
+ return getWeblogFirstPublishTime(website, null);
+ }
+
public Map getWeblogEntryObjectMap(
WebsiteData website,
Date startDate,
diff -ur
apache-roller-src-3.1.orig/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
apache-roller-src-3.1/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
---
apache-roller-src-3.1.orig/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
2007-03-22 22:04:53.000000000 -0500
+++
apache-roller-src-3.1/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
2007-04-17 20:40:38.000000000 -0500
@@ -30,7 +30,9 @@
public void setDay( String month ) throws Exception;
public Date getDay();
-
+
+ public Date getLastMonth() throws Exception;
+
public Date getNextMonth();
public String computePrevMonthUrl();
diff -ur
apache-roller-src-3.1.orig/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
apache-roller-src-3.1/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
---
apache-roller-src-3.1.orig/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
2007-03-22 22:04:53.000000000 -0500
+++
apache-roller-src-3.1/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
2007-04-17 21:30:27.000000000 -0500
@@ -184,9 +184,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\">«</a> ");
+ if (day.compareTo(model.getLastMonth()) >= 0) {
+ pw.print("<a href=\"" + model.computePrevMonthUrl()
+ + "\" title=\"" + resources.getMessage(mLocale,
"calendar.prev")
+ + "\" class=\"hCalendarNavBar\">«</a> ");
+ }
pw.print( formatTitle.format(day) );
if (todayCal.getTime().compareTo(model.getNextMonth()) >= 0) {
pw.print(" <a href=\"" + model.computeNextMonthUrl()
diff -ur
apache-roller-src-3.1.orig/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
apache-roller-src-3.1/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
---
apache-roller-src-3.1.orig/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
2007-03-22 22:04:57.000000000 -0500
+++
apache-roller-src-3.1/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
2007-04-17 20:40:51.000000000 -0500
@@ -49,6 +49,7 @@
protected String pageLink = null;
protected String locale = null;
protected Calendar calendar = null;
+ protected Calendar lastCalendar = null;
protected WebsiteData weblog = null;
protected WeblogPageRequest pageRequest = null;
@@ -181,7 +182,16 @@
public Calendar getCalendar() {
return (Calendar)calendar.clone();
}
-
+
+ public Date getLastMonth() throws Exception {
+ if (lastCalendar == null) {
+ WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
+ lastCalendar = getCalendar();
+ lastCalendar.setTime( mgr.getWeblogFirstPublishTime(weblog) );
+ }
+ return getFirstDayOfMonth(lastCalendar).getTime();
+ }
+
public Date getNextMonth() {
Calendar nextCal = getCalendar();
nextCal.setTime( day );