in app/src/main/java/org/apache/roller/weblogger/ui/core/tags/calendar/CalendarTag.java [112:263]
public int doStartTag( PrintWriter pw ) throws JspException {
try {
// build week day names
this.buildDayNames();
// day to be displayed
Date day;
// set to day to be displayed
Calendar dayCal;
// for iterating through days of month
Calendar cal;
// for iterating through days of month
Calendar todayCal;
// the calendar model
CalendarModel model;
// ---------------------------------
// --- initialize date variables ---
// ---------------------------------
// check for parameter map and target url
StringTokenizer toker = new StringTokenizer(mModelName,".");
String tok1 = toker.nextToken();
if (toker.hasMoreTokens()) {
String tok2 = toker.nextToken();
Object bean = pageContext.findAttribute(tok1);
model = (CalendarModel)PropertyUtils.getProperty(bean, tok2);
} else {
model = (CalendarModel)pageContext.findAttribute( mModelName );
}
// no model specified, nothing to generate
if (model == null) {
return SKIP_BODY;
}
day = model.getDay();
// ceate object to represent today
todayCal = model.getCalendar();
todayCal.setTime( new Date() );
// get Resource Bundle
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources", mLocale);
// formatter Month-Year title of calendar
SimpleDateFormat formatTitle = new SimpleDateFormat(bundle.getString("calendar.dateFormat"), mLocale);
formatTitle.setTimeZone(todayCal.getTimeZone());
// go back to first day in month
cal = model.getCalendar();
day = DateUtil.getNoonOfDay(day, cal);
cal.set( Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DAY_OF_MONTH) );
// Go back to first day of week before that (Sunday in US, Monday in France, e.g.)
// in the calendar
while ( cal.get( Calendar.DAY_OF_WEEK ) != cal.getFirstDayOfWeek() ) {
cal.add( Calendar.DATE, -1 );
}
// create table of 5 weeks, 7 days per row
dayCal = model.getCalendar();
dayCal.setTime( day );
// -------------------------
// --- draw the calendar ---
// -------------------------
pw.print("<table cellspacing=\"0\" border=\"0\" ");
pw.print(" summary=\""
+bundle.getString("calendar.summary")
+"\" class=\"hCalendarTable"
+mClassSuffix+"\">");
pw.print("<tr>");
pw.print("<td colspan=\"7\" align=\"center\" "+
"class=\"hCalendarMonthYearRow"+mClassSuffix+"\">");
if (model.getPrevMonth() != null) {
pw.print("<a href=\"" + model.computePrevMonthUrl()
+ "\" title=\"" + bundle.getString("calendar.prev")
+ "\" class=\"hCalendarNavBar\">«</a> ");
}
pw.print( formatTitle.format(day) );
if (model.getNextMonth() != null) {
pw.print(" <a href=\"" + model.computeNextMonthUrl()
+ "\" title=\"" + bundle.getString("calendar.next")
+ "\" class=\"hCalendarNavBar\">»</a>");
}
pw.print("</td></tr>");
// emit the HTML calendar
for ( int w=-1; w<6; w++ ) {
pw.print("<tr>");
for ( int d=0; d<7; d++ ) {
if ( w == -1 ) {
pw.print(
"<th class=\"hCalendarDayNameRow"
+mClassSuffix+"\" align=\"center\">");
pw.print( mDayNames[d] );
pw.print("</th>");
continue;
}
// determine URL for this calendar day
Date tddate = cal.getTime();
String url = model.computeUrl(tddate, false, false);
String content = model.getContent( tddate );
// day is in calendar month
if ((cal.get(Calendar.MONTH) == dayCal.get(Calendar.MONTH))
&& (cal.get(Calendar.YEAR) == dayCal.get(Calendar.YEAR))) {
// day is today then use today style
if (( cal.get(Calendar.DAY_OF_MONTH)
== todayCal.get(Calendar.DAY_OF_MONTH))
&& ( cal.get(Calendar.MONTH)
== todayCal.get(Calendar.MONTH))
&& ( cal.get(Calendar.YEAR)
== todayCal.get(Calendar.YEAR))) {
printToday(pw, cal, url, content);
} else {
printDayInThisMonth(pw, cal, url, content);
}
} else {
// apply day-not-in-month style ;-)
printDayNotInMonth(pw, cal);
}
// increment calendar by one day
cal.add( Calendar.DATE, 1 );
}
pw.print("</tr>");
}
pw.print("<tr class=\"hCalendarNextPrev"
+mClassSuffix+"\">");
pw.print("<td colspan=\"7\" align=\"center\">");
pw.print("<a href=\""+model.computeTodayMonthUrl()
+"\" class=\"hCalendarNavBar\">"
+bundle.getString("calendar.today")
+"</a>");
pw.print("</td>");
pw.print("</tr>");
pw.print("</table>");
} catch (Exception e) {
pw.print("<span class=\"error\">");
pw.print("<p><b>An ERROR has occured CalendarTag</b></p>");
pw.print("</span>");
mLogger.error("Calendar tag exception",e);
}
return Tag.SKIP_BODY;
}