The CalendarTag-PrevNextPatch patch enables simple previousMonth nextMonth navigation on the CalendarTag. It uses the calendar.data parameter already present in JSPWiki-2.0.32-beta.
Only two files are patched src/com/ecyrd/jspwiki/tags/CalendarTag.java and src/com/ecyrd/jspwiki/WikiEngine.java.
- This patch is now integrated in 2.1.3, with slight changes. I have still a couple of minor complaints about it, so there will be some more cleaning. But it's a good patch. Thanks! --JanneJalkanen
Patch for src/com/ecyrd/jspwiki/tags/CalendarTag.java
--- JSPWiki-2.0.32-beta-src/src/com/ecyrd/jspwiki/tags/CalendarTag.java 2003-03-07 23:47:07.000000000 +0000
+++ JSPWiki-calendarTagPatch/src/com/ecyrd/jspwiki/tags/CalendarTag.java 2003-03-08 10:34:07.000000000 +0000
@@ -28,6 +28,7 @@
import java.text.ParseException;
import javax.servlet.jsp.JspWriter;
+import javax.servlet.http.HttpServletRequest;
import com.ecyrd.jspwiki.WikiEngine;
import com.ecyrd.jspwiki.WikiPage;
@@ -127,6 +128,50 @@
return result;
}
+ private String getMonthLink( Calendar day, String txt, String queryString )
+ {
+ String result = "";
+ Calendar nextMonth = Calendar.getInstance();
+ nextMonth.set( Calendar.DATE, 1 );
+ nextMonth.add( Calendar.DATE, -1);
+ nextMonth.add( Calendar.MONTH, 1 ); // Now move to 1st day of next month
+
+ if ( day.before(nextMonth) )
+ {
+ WikiEngine engine = m_wikiContext.getEngine();
+ WikiPage thePage = m_wikiContext.getPage();
+ String pageName = thePage.getName();
+
+ String calendarDate = m_dateFormat.format(day.getTime());
+ String url = engine.getViewURL(pageName) + "&calendar.date="+calendarDate;
+
+ if ( (queryString != null) && (queryString.length() > 0) )
+ {
+ // Ensure that the 'calendar.date=ddMMyy' has been removed from the queryString
+ int pos1 = queryString.indexOf("calendar.date=");
+ if (pos1 >= 0)
+ {
+ String tmp = queryString.substring(0,pos1);
+ int pos2 = queryString.indexOf("&",pos1) + 1;
+ if ( (pos2 > 0) && (pos2 < queryString.length()) )
+ {
+ tmp = tmp + queryString.substring(pos2);
+ }
+ queryString = tmp;
+ }
+
+ url = url + "&"+queryString;
+ }
+ result = "<td><a href=\""+url+"\">"+txt+"</a></td>";
+ }
+ else
+ {
+ result="<td> </td>";
+ }
+
+ return result;
+ }
+
public final int doWikiStartTag()
throws IOException,
ProviderException
@@ -135,6 +180,8 @@
SimpleDateFormat monthfmt = new SimpleDateFormat( "MMMM yyyy" );
JspWriter out = pageContext.getOut();
Calendar cal = Calendar.getInstance();
+ Calendar prevCal = Calendar.getInstance();
+ Calendar nextCal = Calendar.getInstance();
//
// Check if there is a parameter in the request to set the date.
@@ -153,6 +200,8 @@
{
Date d = m_dateFormat.parse( calendarDate );
cal.setTime( d );
+ prevCal.setTime( d );
+ nextCal.setTime( d );
}
catch( ParseException e )
{
@@ -160,14 +209,26 @@
}
}
- cal.set( Calendar.DATE, 1 ); // First, set to first day of month
+ cal.set( Calendar.DATE, 1 ); // First, set to first day of month
+ prevCal.set( Calendar.DATE, 1 );
+ nextCal.set( Calendar.DATE, 1 );
+
+ prevCal.add(Calendar.MONTH, -1); // Now move to first day of previous month
+ nextCal.add(Calendar.MONTH, 1); // Now move to first day of next month
out.write( "<table class=\"calendar\">\n" );
- out.write( "<tr><td colspan=7 class=\"month\">"+
+ HttpServletRequest httpServletRequest = m_wikiContext.getHttpRequest();
+ String queryString = engine.safeGetQueryString( httpServletRequest );
+ out.write( "<tr>"+
+ getMonthLink(prevCal,"<<", queryString)+
+ "<td colspan=5 class=\"month\">"+
monthfmt.format( cal.getTime() )+
- "</td>\n" );
+ "</td>"+
+ getMonthLink(nextCal,">>", queryString)+
+ "</tr>\n"
+ );
int month = cal.get( Calendar.MONTH );
cal.set( Calendar.DAY_OF_WEEK, Calendar.MONDAY ); // Then, find the first day of the week.
Patch for src/com/ecyrd/jspwiki/WikiEngine.java
--- JSPWiki-2.0.32-beta-src/src/com/ecyrd/jspwiki/WikiEngine.java 2003-03-07 23:47:07.000000000 +0000
+++ JSPWiki-calendarTagPatch/src/com/ecyrd/jspwiki/WikiEngine.java 2003-03-08 10:29:56.000000000 +0000
@@ -551,7 +551,44 @@
}
}
+
+ public String safeGetQueryString( HttpServletRequest request )
+ {
+ if (request == null)
+ {
+ return "";
+ }
+
+ try
+ {
+ String res = request.getQueryString();
+ if( res != null )
+ {
+ res = new String(res.getBytes("ISO-8859-1"),
+ getContentEncoding() );
+ // Ensure that the 'page=xyz' attribute is removed
+ int pos1 = res.indexOf("page=");
+ if (pos1 >= 0)
+ {
+ String tmpRes = res.substring(0, pos1);
+ int pos2 = res.indexOf("&",pos1) + 1;
+ if ( (pos2 > 0) && (pos2 < res.length()) )
+ {
+ tmpRes = tmpRes + res.substring(pos2);
+ }
+ res = tmpRes;
+ }
+ }
+
+ return res;
+ }
+ catch( UnsupportedEncodingException e )
+ {
+ log.fatal( "Unsupported encoding", e );
+ return "";
+ }
+ }
/**
* Returns an URL to some other Wiki that we know.
--RoyW