public final int doWikiStartTag()
throws IOException,
ProviderException
{
WikiEngine engine = m_wikiContext.getEngine();
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.
//
String calendarDate = pageContext.getRequest().getParameter( "calendar.date" );
if( calendarDate == null )
{
calendarDate = pageContext.getRequest().getParameter( "weblog.startDate" );
}
if( calendarDate != null )
{
try
{
Date d = m_dateFormat.parse( calendarDate );
cal.setTime( d );
prevCal.setTime( d );
nextCal.setTime( d );
}
catch( ParseException e )
{
log.warn( "date format wrong: "+calendarDate );
}
}
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" );
HttpServletRequest httpServletRequest = m_wikiContext.getHttpRequest();
String queryString = engine.safeGetQueryString( httpServletRequest );
out.write( "<tr>"+
getMonthNaviLink(prevCal,"<<", queryString)+
"<td colspan=5 class=\"month\">"+
getMonthLink( cal )+
"</td>"+
getMonthNaviLink(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.
out.write( "<tr><td class=\"weekdays\">Mon</td>"+
"<td class=\"weekdays\">Tue</td>"+
"<td class=\"weekdays\">Wed</td>"+
"<td class=\"weekdays\">Thu</td>"+
"<td class=\"weekdays\">Fri</td>"+
"<td class=\"weekdays\">Sat</td>"+
"<td class=\"weekdays\">Sun</td></tr>\n" );
boolean noMoreDates = false;
while( !noMoreDates )
{
out.write( "<tr>" );
for( int i = 0; i < 7; i++ )
{
int mth = cal.get( Calendar.MONTH );
if( mth != month )
{
out.write("<td class=\"othermonth\">"+cal.get(Calendar.DATE)+"</td>");
}
else
{
out.write( getDayLink(cal) );
}
cal.add( Calendar.DATE, 1 );
}
if( cal.get( Calendar.MONTH ) != month )
{
noMoreDates = true;
}
out.write( "</tr>\n" );
}
out.write( "</table>\n" );
return EVAL_BODY_INCLUDE;
}